Links

Position

Documentation on interacting with ByBit's Position API functions through the PENDAX Javascript SDK.
All parameters of type INTEGER listed in the Bybit API docs need to be passed in as a string.

Get Position Info

Please refer to the official ByBit API Docs for the required parameters.

Function name:

getPositionInfo(options)

Usage:

import { createExchange } from "./exchanges/exchange.js";
let myByBitAccount = createExchange({
exchange: "bybit",
authenticate: "true",
key: "myKeys",
secret: "mySecret",
label: "bybit",
testnet: "false"
});
async function getPositionInfo(exchange, options) {
try {
let result = await exchange.getPositionInfo(options);
console.log(result);
} catch (error) {
console.log(error.message);
}
}
const result = await getPositionInfo(myByBitAccount,
{
category: 'linear',
symbol: 'BTCUSDT'
});

Set Leverage

Please refer to the official ByBit API Docs for the required parameters.

Function name:

setLeverage(options)

Usage:

import { createExchange } from "./exchanges/exchange.js";
let myByBitAccount = createExchange({
exchange: "bybit",
authenticate: "true",
key: "myKeys",
secret: "mySecret",
label: "bybit",
testnet: "false"
});
async function setLeverage(exchange, options) {
try {
let result = await exchange.setLeverage(options);
console.log(result);
} catch (error) {
console.log(error.message);
}
}
const result = await setLeverage(myByBitAccount,
{
category: 'linear',
symbol: 'BTCUSD',
buyLeverage: '6',
sellLeverage: '6'
});

Switch Cross/Isolated Margin

Please refer to the official ByBit API Docs for the required parameters.

Function name:

switchCrossIsolatedMargin(options)

Usage:

import { createExchange } from "./exchanges/exchange.js";
let myByBitAccount = createExchange({
exchange: "bybit",
authenticate: "true",
key: "myKeys",
secret: "mySecret",
label: "bybit",
testnet: "false"
});
async function switchCrossIsolatedMargin(exchange, options) {
try {
let result = await exchange.switchCrossIsolatedMargin(options);
console.log(result);
} catch (error) {
console.log(error.message);
}
}
const result = await switchCrossIsolatedMargin(myByBitAccount,
{
category: 'linear',
symbol: 'BTCUSD',
tradeMode: '0',
buyLeverage: '6',
sellLeverage: '6'
});

Set TP/SL Mode

Please refer to the official ByBit API Docs for the required parameters.

Function name:

setTpslMode(options)

Usage:

import { createExchange } from "./exchanges/exchange.js";
let myByBitAccount = createExchange({
exchange: "bybit",
authenticate: "true",
key: "myKeys",
secret: "mySecret",
label: "bybit",
testnet: "false"
});
async function setTpslMode(exchange, options) {
try {
let result = await exchange.setTpslMode(options);
console.log(result);
} catch (error) {
console.log(error.message);
}
}
const result = await setTpslMode(myByBitAccount,
{
category: 'linear',
symbol: 'BTCUSD',
tpSlMode: 'Full'
});

Switch Position Mode

Please refer to the official ByBit API Docs for the required parameters.

Function name:

switchPositionMode(options)

Usage:

import { createExchange } from "./exchanges/exchange.js";
let myByBitAccount = createExchange({
exchange: "bybit",
authenticate: "true",
key: "myKeys",
secret: "mySecret",
label: "bybit",
testnet: "false"
});
async function switchPositionMode(exchange, options) {
try {
let result = await exchange.switchPositionMode(options);
console.log(result);
} catch (error) {
console.log(error.message);
}
}
const result = await switchPositionMode(myByBitAccount,
{
category: 'linear',
mode: '0'
});

Set Risk Limit

Please refer to the official ByBit API Docs for the required parameters.

Function name:

setRiskLimit(options)

Usage:

import { createExchange } from "./exchanges/exchange.js";
let myByBitAccount = createExchange({
exchange: "bybit",
authenticate: "true",
key: "myKeys",
secret: "mySecret",
label: "bybit",
testnet: "false"
});
async function setRiskLimit(exchange, options) {
try {
let result = await exchange.setRiskLimit(options);
console.log(result);
} catch (error) {
console.log(error.message);
}
}
const result = await setRiskLimit(myByBitAccount,
{
category: 'linear',
symbol: 'BTCUSDT',
riskId: '4'
});

Set Trading Stop

Please refer to the official ByBit API Docs for the required parameters.

Function name:

setTradingStop(options)

Usage:

import { createExchange } from "./exchanges/exchange.js";
let myByBitAccount = createExchange({
exchange: "bybit",
authenticate: "true",
key: "myKeys",
secret: "mySecret",
label: "bybit",
testnet: "false"
});
async function setTradingStop(exchange, options) {
try {
let result = await exchange.setTradingStop(options);
console.log(result);
} catch (error) {
console.log(error.message);
}
}
const result = await setTradingStop(myByBitAccount,
{
category: 'linear',
symbol: 'BTCUSD',
positionIdx: '0',
takeProfit: '0'
});

Set Auto Add Margin

Please refer to the official ByBit API Docs for the required parameters.

Function name:

setAutoAddMargin(options)

Usage:

import { createExchange } from "./exchanges/exchange.js";
let myByBitAccount = createExchange({
exchange: "bybit",
authenticate: "true",
key: "myKeys",
secret: "mySecret",
label: "bybit",
testnet: "false"
});
async function setAutoAddMargin(exchange, options) {
try {
let result = await exchange.setAutoAddMargin(options);
console.log(result);
} catch (error) {
console.log(error.message);
}
}
const result = await setAutoAddMargin(myByBitAccount,
{
category: 'linear',
symbol: 'BTCUSD',
autoAddMargin: '0'
});

Get Execution

Please refer to the official ByBit API Docs for the required parameters.

Function name:

getExecution(options)

Usage:

import { createExchange } from "./exchanges/exchange.js";
let myByBitAccount = createExchange({
exchange: "bybit",
authenticate: "true",
key: "myKeys",
secret: "mySecret",
label: "bybit",
testnet: "false"
});
async function getExecution(exchange, options) {
try {
let result = await exchange.getExecution(options);
console.log(result);
} catch (error) {
console.log(error.message);
}
}
const result = await getExecution(myByBitAccount,
{
category: 'linear',
symbol: 'BTCUSD'
});

Get Closed PnL

Please refer to the official ByBit API Docs for the required parameters.

Function name:

getClosedPnl(options)

Usage:

import { createExchange } from "./exchanges/exchange.js";
let myByBitAccount = createExchange({
exchange: "bybit",
authenticate: "true",
key: "myKeys",
secret: "mySecret",
label: "bybit",
testnet: "false"
});
async function getClosedPnl(exchange, options) {
try {
let result = await exchange.getClosedPnl(options);
console.log(result);
} catch (error) {
console.log(error.message);
}
}
const result = await getClosedPnl(myByBitAccount,
{
category: 'linear',
symbol: 'BTCUSD'
});
Last modified 6mo ago