Compendium Trading Tools Documentation
CompendiumPENDAXCompendexOfficial Links
  • ⭐Platform Overview
  • ⚫PENDAX
    • 🌐What is PENDAX?
    • 🖱️PENDAX Capabilities
    • 💾Installing PENDAX modules
    • 💡Using PENDAX SDK
      • 💻Common Functions
      • 💻OKX Functions
        • Trading & Orders
        • Funding
        • Convert
        • Account & Subaccount
        • Grid Trading
        • Market Data
        • Public Data
        • Trading Data
      • 💻Bitget Functions
        • Public (Spot)
        • Market (Spot)
        • Wallet (Spot)
        • Account (Spot)
        • Trade (Spot)
        • Market (Futures)
        • Account (Futures)
        • Trade (Futures)
        • CopyTrade (Futures)
        • Sub Account Interface (Broker)
        • Sub API Interface (Broker)
      • 💻ByBit Functions
        • Market
        • Trading
        • Position
        • Account
        • Asset
        • User
        • Spot Leverage Token
        • Spot Margin Trade (UTA)
        • Spot Margin Trade (Normal)
        • Institutional Lending
      • 💻Mexc Functions
        • Market
        • Sub-Account
        • Spot Account/Trade
        • Wallet
        • ETF
        • Rebate
        • Futures Market
        • Futures Account and Trading
      • 💻Phemex Functions
        • Contract
        • Hedged Contract
        • Spot
        • Margin Trading
        • Transfer
        • Convert
        • Deposit And Withdraw
      • 💻BloFin Functions
        • Websocket
        • Account
        • Affiliate
        • Public Data
        • Trading
        • User
      • 💻BingX Functions
        • Fund Account
        • Wallet Deposits and Withdrawals
        • Sub-Account Managenent
        • Market Data (USDT-M)
        • Account (USDT-M)
        • Trades (USDT-M)
        • Market Data (Coin-M)
        • Trades (Coin-M)
        • Market Data (Spot)
        • Fund Account (Spot)
        • Trades (Spot)
        • CopyTrader
      • ⚠️FTX Functions
    • 📜License Agreement
  • 🟣Compendium App
    • 📈Compendium Trading Tools
    • 🔗Connect An Exchange Account
      • 🗝️OKX.com API Keys
    • 🤖Verified Trading Bots
      • Explore The Marketplace
      • For Algo & Strategy Authors
        • Get Listed & Verified
        • Strategy Monetization
        • Sending Trading Signals
        • Simplified Signal Program
      • For Users & Subscribers
        • Subscribing To Bots
        • Managing A Subscription
    • 💫Copy Trading Groups
      • For Copy Group Leaders
        • Creating A Copy Group
        • Linking Leader Account
        • Important Trading Notes
        • Manage A Copy Group
        • Discord Webhooks Setup
      • For Users & Subscribers
        • Subscribe To Copy Group
        • Link Account To Group
    • 📶Signal Provider Groups
      • For Group Leaders
        • Creating A Signal Group
        • Managing A Signal Group
        • Sending Trading Signals
      • For Users & Subscribers
        • Subscribing To Signal Groups
        • Manage Signal Group Subscription
  • 🔵Compendex Suite
    • 🔮DeFi With Compendex
    • ☀️Solana Integrations
      • Supported Solana Wallets
      • Overview And News
      • Openbook Spot Markets
      • Smart Swap Aggregator
      • NFT Metaverse Markets
      • Solana DeFi Analytics Portal
      • Community Tools List
  • 🪙The CMFI Token Ecosystem
    • 📊Tokenomics Breakdown
    • 🍎Trade Incentive Program
    • 🌊Staking And Liquidity Pools
      • ✨Raydium Liquidity Pools
      • 🐳Orca Liquidity Whirlpools
      • 🐋Orca Liquidity Pools
    • 🐷Compendi-Pigs NFT
  • 👥Community Info
    • ✅Links And Social Pages
    • 🎨Branding Guidelines
Powered by GitBook
On this page
  • Get Position Info
  • Set Leverage
  • Switch Cross/Isolated Margin
  • Set TP/SL Mode
  • Switch Position Mode
  • Set Risk Limit
  • Set Trading Stop
  • Set Auto Add Margin
  • Get Execution
  • Get Closed PnL
  1. PENDAX
  2. Using PENDAX SDK
  3. ByBit Functions

Position

Documentation on interacting with ByBit's Position API functions through the PENDAX Javascript SDK.

PreviousTradingNextAccount

Last updated 8 months ago

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'
     });

⚫
💡
💻
https://bybit-exchange.github.io/docs/v5/position
https://bybit-exchange.github.io/docs/v5/position/leverage
https://bybit-exchange.github.io/docs/v5/position/cross-isolate
https://bybit-exchange.github.io/docs/v5/position/tpsl-mode
https://bybit-exchange.github.io/docs/v5/position/position-mode
https://bybit-exchange.github.io/docs/v5/position/set-risk-limit
https://bybit-exchange.github.io/docs/v5/position/trading-stop
https://bybit-exchange.github.io/docs/v5/position/add-margin
https://bybit-exchange.github.io/docs/v5/position/execution
https://bybit-exchange.github.io/docs/v5/position/close-pnl