All parameters of type INTEGER listed in the Bybit API docs need to be passed in as a string.
Get Position Info
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
Function name:
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
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
Function name:
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
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
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
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
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
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
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'
});