Account & Subaccount

Documentation on interacting with a variety of OKX account and subaccount API endpoint functions through the PENDAX Javascript SDK.

All Account and Subaccount API endpoints require authentication. Please create OKX API keys to interact with these functions successfully.

Account

Get Balance

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

https://www.okx.com/docs-v5/en/#trading-account-rest-api-get-balance

Function Name:

getBalances()

Usage:

import { createExchange } from "./exchanges/exchange.js";

  let myOkxAccount = createExchange({
      exchange: "okx",
      authenticate: true,
      key: "myKeys",
      secret: "mySecret",
      passphrase: "myPassphrase",
      label: "okx",
      marginType: "usdt"
});

async function getBalances(exchange, options) {
    try {
        let result = await exchange.getBalances(options);
        console.log(result);
    } catch (error) {
        console.log(error.message);
    }
}

const result = await getBalances(myOkxAccount)

Get Positions

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

https://www.okx.com/docs-v5/en/#rest-api-account-get-positions

Function Name:

getPositions()

Usage:

import { createExchange } from "./exchanges/exchange.js";

  let myOkxAccount = createExchange({
      exchange: "okx",
      authenticate: true,
      key: "myKeys",
      secret: "mySecret",
      passphrase: "myPassphrase",
      label: "okx",
      marginType: "usdt"
});

async function getPositions(exchange, options) {
    try {
        let result = await exchange.getPositions(options);
        console.log(result);
    } catch (error) {
        console.log(error.message);
    }
}

const result = await getPositions(myOkxAccount)

Get Positions History

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

https://www.okx.com/docs-v5/en/#rest-api-account-get-positions-history

Function Name:

getPositionsHistory()

Usage:

import { createExchange } from "./exchanges/exchange.js";

  let myOkxAccount = createExchange({
      exchange: "okx",
      authenticate: true,
      key: "myKeys",
      secret: "mySecret",
      passphrase: "myPassphrase",
      label: "okx",
      marginType: "usdt"
});

async function getPositionsHistory(exchange, options) {
    try {
        let result = await exchange.getPositionsHistory(options);
        console.log(result);
    } catch (error) {
        console.log(error.message);
    }
}

const result = await getPositionsHistory(myOkxAccount)

Get Account and Position Risk

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

https://www.okx.com/docs-v5/en/#rest-api-account-get-account-and-position-risk

Function Name:

getAccountPosAndRisk()

Usage:

import { createExchange } from "./exchanges/exchange.js";

  let myOkxAccount = createExchange({
      exchange: "okx",
      authenticate: true,
      key: "myKeys",
      secret: "mySecret",
      passphrase: "myPassphrase",
      label: "okx",
      marginType: "usdt"
});

async function getAccountPosAndRisk(exchange, options) {
    try {
        let result = await exchange.getAccountPosAndRisk(options);
        console.log(result);
    } catch (error) {
        console.log(error.message);
    }
}

const result = await getAccountPosAndRisk(myOkxAccount)

Get Bills Details (last 7 days)

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

https://www.okx.com/docs-v5/en/#rest-api-account-get-bills-details-last-7-days

Function Name:

getBills()

Usage:

import { createExchange } from "./exchanges/exchange.js";

  let myOkxAccount = createExchange({
      exchange: "okx",
      authenticate: true,
      key: "myKeys",
      secret: "mySecret",
      passphrase: "myPassphrase",
      label: "okx",
      marginType: "usdt"
});

async function getBills(exchange, options) {
    try {
        let result = await exchange.getBills(options);
        console.log(result);
    } catch (error) {
        console.log(error.message);
    }
}

const result = await getBills(myOkxAccount)

Get Bills Details (last 3 months)

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

https://www.okx.com/docs-v5/en/#rest-api-account-get-bills-details-last-3-months

Function Name:

getBillsArchive()

Usage:

import { createExchange } from "./exchanges/exchange.js";

  let myOkxAccount = createExchange({
      exchange: "okx",
      authenticate: true,
      key: "myKeys",
      secret: "mySecret",
      passphrase: "myPassphrase",
      label: "okx",
      marginType: "usdt"
});

async function getBillsArchive(exchange, options) {
    try {
        let result = await exchange.getBillsArchive(options);
        console.log(result);
    } catch (error) {
        console.log(error.message);
    }
}

const result = await getBillsArchive(myOkxAccount)

Get Account Configuration

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

https://www.okx.com/docs-v5/en/#rest-api-account-get-account-configuration

Function Name:

getAccountConfig()

Usage:

import { createExchange } from "./exchanges/exchange.js";

  let myOkxAccount = createExchange({
      exchange: "okx",
      authenticate: true,
      key: "myKeys",
      secret: "mySecret",
      passphrase: "myPassphrase",
      label: "okx",
      marginType: "usdt"
});

async function getAccountConfig(exchange, options) {
    try {
        let result = await exchange.getAccountConfig(options);
        console.log(result);
    } catch (error) {
        console.log(error.message);
    }
}

const result = await getAccountConfig(myOkxAccount)

Set Position Mode

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

https://www.okx.com/docs-v5/en/#rest-api-account-set-position-mode

Function Name:

setPosMode()

Usage:

import { createExchange } from "./exchanges/exchange.js";

  let myOkxAccount = createExchange({
      exchange: "okx",
      authenticate: true,
      key: "myKeys",
      secret: "mySecret",
      passphrase: "myPassphrase",
      label: "okx",
      marginType: "usdt"
});

async function setPosMode(exchange, options) {
    try {
        let result = await exchange.setPosMode(options);
        console.log(result);
    } catch (error) {
        console.log(error.message);
    }
}

const result = await setPosMode(myOkxAccount,
{
    posMode:"long_short_mode"
}
)

Set Leverage

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

https://www.okx.com/docs-v5/en/#rest-api-account-set-leverage

Function Name:

setLeverage()

Usage:

import { createExchange } from "./exchanges/exchange.js";

  let myOkxAccount = createExchange({
      exchange: "okx",
      authenticate: true,
      key: "myKeys",
      secret: "mySecret",
      passphrase: "myPassphrase",
      label: "okx",
      marginType: "usdt"
});

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(myOkxAccount,
{
    instId:"BTC-USDT",
    lever:"5",
    mgnMode:"isolated"
}
)

Get Maximum Buy/Sell Amount or Open Amount

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

https://www.okx.com/docs-v5/en/#rest-api-account-get-maximum-buy-sell-amount-or-open-amount

Function Name:

getMaxSize()

Usage:

import { createExchange } from "./exchanges/exchange.js";

  let myOkxAccount = createExchange({
      exchange: "okx",
      authenticate: true,
      key: "myKeys",
      secret: "mySecret",
      passphrase: "myPassphrase",
      label: "okx",
      marginType: "usdt"
});

async function getMaxSize(exchange, options) {
    try {
        let result = await exchange.getMaxSize(options);
        console.log(result);
    } catch (error) {
        console.log(error.message);
    }
}

const result = await getMaxSize(myOkxAccount,
{
    instId:"BTC-USDT",
    tdMode:"isolated"
}
)

Get Maximum Available Tradable Amount

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

https://www.okx.com/docs-v5/en/#rest-api-account-get-maximum-available-tradable-amount

Function Name:

getMaxAvailSize()

Usage:

import { createExchange } from "./exchanges/exchange.js";

  let myOkxAccount = createExchange({
      exchange: "okx",
      authenticate: true,
      key: "myKeys",
      secret: "mySecret",
      passphrase: "myPassphrase",
      label: "okx",
      marginType: "usdt"
});

async function getMaxAvailSize(exchange, options) {
    try {
        let result = await exchange.getMaxAvailSize(options);
        console.log(result);
    } catch (error) {
        console.log(error.message);
    }
}

const result = await getMaxAvailSize(myOkxAccount,
{
    instId:"BTC-USDT",
    tdMode:"isolated"
}
)

Increase/Decrease Margin

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

https://www.okx.com/docs-v5/en/#rest-api-account-increase-decrease-margin

Function Name:

adjustMargin()

Usage:

import { createExchange } from "./exchanges/exchange.js";

  let myOkxAccount = createExchange({
      exchange: "okx",
      authenticate: true,
      key: "myKeys",
      secret: "mySecret",
      passphrase: "myPassphrase",
      label: "okx",
      marginType: "usdt"
});

async function adjustMargin(exchange, options) {
    try {
        let result = await exchange.adjustMargin(options);
        console.log(result);
    } catch (error) {
        console.log(error.message);
    }
}

const result = await adjustMargin(myOkxAccount,
{
    instId:"BTC-USDT-200626",
    posSide:"short",
    type:"add",
    amt:"1"
}
)

Get Leverage

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

https://www.okx.com/docs-v5/en/#rest-api-account-get-leverage

Function Name:

getLeverage()

Usage:

import { createExchange } from "./exchanges/exchange.js";

  let myOkxAccount = createExchange({
      exchange: "okx",
      authenticate: true,
      key: "myKeys",
      secret: "mySecret",
      passphrase: "myPassphrase",
      label: "okx",
      marginType: "usdt"
});

async function getLeverage(exchange, options) {
    try {
        let result = await exchange.getLeverage(options);
        console.log(result);
    } catch (error) {
        console.log(error.message);
    }
}

const result = await getLeverage(myOkxAccount,
{
    instId:"BTC-USDT-200626",
    mgnMode: "cross"
}
)

Get The Maximum Loan Of Instrument

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

https://www.okx.com/docs-v5/en/#rest-api-account-get-the-maximum-loan-of-instrument

Function Name:

getMaxLoan()

Usage:

import { createExchange } from "./exchanges/exchange.js";

  let myOkxAccount = createExchange({
      exchange: "okx",
      authenticate: true,
      key: "myKeys",
      secret: "mySecret",
      passphrase: "myPassphrase",
      label: "okx",
      marginType: "usdt"
});

async function getMaxLoan(exchange, options) {
    try {
        let result = await exchange.getMaxLoan(options);
        console.log(result);
    } catch (error) {
        console.log(error.message);
    }
}

const result = await getMaxLoan(myOkxAccount,
{
    instId:["BTC-USDT-200626"],
    mgnMode: "cross"
}
)

Get Fee Rates

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

https://www.okx.com/docs-v5/en/#rest-api-account-get-fee-rates

Function Name:

getFeeRates()

Usage:

import { createExchange } from "./exchanges/exchange.js";

  let myOkxAccount = createExchange({
      exchange: "okx",
      authenticate: true,
      key: "myKeys",
      secret: "mySecret",
      passphrase: "myPassphrase",
      label: "okx",
      marginType: "usdt"
});

async function getFeeRates(exchange, options) {
    try {
        let result = await exchange.getFeeRates(options);
        console.log(result);
    } catch (error) {
        console.log(error.message);
    }
}

const result = await getFeeRates(myOkxAccount,
{
    instType: "SPOT",
    instID: "BTC-USDT"
}
)

Get Interest Accrued Data

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

https://www.okx.com/docs-v5/en/#rest-api-account-get-interest-accrued-data

Function Name:

getFeeRates()

Usage:

import { createExchange } from "./exchanges/exchange.js";

  let myOkxAccount = createExchange({
      exchange: "okx",
      authenticate: true,
      key: "myKeys",
      secret: "mySecret",
      passphrase: "myPassphrase",
      label: "okx",
      marginType: "usdt"
});

async function getInterestAccrued(exchange, options) {
    try {
        let result = await exchange.getInterestAccrued(options);
        console.log(result);
    } catch (error) {
        console.log(error.message);
    }
}

const result = await getInterestAccrued(myOkxAccount)

Get Interest Rate

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

https://www.okx.com/docs-v5/en/#rest-api-account-get-interest-rate

Function Name:

getInterestRate()

Usage:

import { createExchange } from "./exchanges/exchange.js";

  let myOkxAccount = createExchange({
      exchange: "okx",
      authenticate: true,
      key: "myKeys",
      secret: "mySecret",
      passphrase: "myPassphrase",
      label: "okx",
      marginType: "usdt"
});

async function getInterestRate(exchange, options) {
    try {
        let result = await exchange.getInterestRate(options);
        console.log(result);
    } catch (error) {
        console.log(error.message);
    }
}

const result = await getInterestRate(myOkxAccount)

Set Greeks

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

https://www.okx.com/docs-v5/en/#rest-api-account-set-greeks-pa-bs

Function Name:

setGreeks()

Usage:

import { createExchange } from "./exchanges/exchange.js";

  let myOkxAccount = createExchange({
      exchange: "okx",
      authenticate: true,
      key: "myKeys",
      secret: "mySecret",
      passphrase: "myPassphrase",
      label: "okx",
      marginType: "usdt"
});

async function setGreeks(exchange, options) {
    try {
        let result = await exchange.setGreeks(options);
        console.log(result);
    } catch (error) {
        console.log(error.message);
    }
}

const result = await setGreeks(myOkxAccount, {
    greeksType:"PA"
})

Isolated Margin Trading Settings

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

https://www.okx.com/docs-v5/en/#rest-api-account-isolated-margin-trading-settings

Function Name:

setIsolatedMode()

Usage:

import { createExchange } from "./exchanges/exchange.js";

  let myOkxAccount = createExchange({
      exchange: "okx",
      authenticate: true,
      key: "myKeys",
      secret: "mySecret",
      passphrase: "myPassphrase",
      label: "okx",
      marginType: "usdt"
});

async function setIsolatedMode(exchange, options) {
    try {
        let result = await exchange.setIsolatedMode(options);
        console.log(result);
    } catch (error) {
        console.log(error.message);
    }
}

const result = await setIsolatedMode(myOkxAccount, {
    isoMode:"automatic",
    type:"MARGIN"
})

Get Maximum Withdrawals

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

https://www.okx.com/docs-v5/en/#rest-api-account-get-maximum-withdrawals

Function Name:

getMaxWithdrawal()

Usage:

import { createExchange } from "./exchanges/exchange.js";

  let myOkxAccount = createExchange({
      exchange: "okx",
      authenticate: true,
      key: "myKeys",
      secret: "mySecret",
      passphrase: "myPassphrase",
      label: "okx",
      marginType: "usdt"
});

async function getMaxWithdrawal(exchange, options) {
    try {
        let result = await exchange.getMaxWithdrawal(options);
        console.log(result);
    } catch (error) {
        console.log(error.message);
    }
}

const result = await getMaxWithdrawal(myOkxAccount)

Get Account Risk State

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

https://www.okx.com/docs-v5/en/#rest-api-account-get-account-risk-state

Function Name:

getRiskState()

Usage:

import { createExchange } from "./exchanges/exchange.js";

  let myOkxAccount = createExchange({
      exchange: "okx",
      authenticate: true,
      key: "myKeys",
      secret: "mySecret",
      passphrase: "myPassphrase",
      label: "okx",
      marginType: "usdt"
});

async function getRiskState(exchange, options) {
    try {
        let result = await exchange.getRiskState(options);
        console.log(result);
    } catch (error) {
        console.log(error.message);
    }
}

const result = await getRiskState(myOkxAccount)

VIP Loans Borrow and Repay

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

https://www.okx.com/docs-v5/en/#rest-api-account-vip-loans-borrow-and-repay

Function Name:

vipLoanBorrowRepay()

Usage:

import { createExchange } from "./exchanges/exchange.js";

  let myOkxAccount = createExchange({
      exchange: "okx",
      authenticate: true,
      key: "myKeys",
      secret: "mySecret",
      passphrase: "myPassphrase",
      label: "okx",
      marginType: "usdt"
});

async function vipLoanBorrowRepay(exchange, options) {
    try {
        let result = await exchange.vipLoanBorrowRepay(options);
        console.log(result);
    } catch (error) {
        console.log(error.message);
    }
}

const result = await vipLoanBorrowRepay(myOkxAccount, {
    ccy:"USDT",
    side:"borrow",
    amt:"100"
})

Get Borrow and Repay History for VIP Loans

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

https://www.okx.com/docs-v5/en/#rest-api-account-get-borrow-and-repay-history-for-vip-loans

Function Name:

getVipLoanHistory()

Usage:

import { createExchange } from "./exchanges/exchange.js";

  let myOkxAccount = createExchange({
      exchange: "okx",
      authenticate: true,
      key: "myKeys",
      secret: "mySecret",
      passphrase: "myPassphrase",
      label: "okx",
      marginType: "usdt"
});

async function getVipLoanHistory(exchange, options) {
    try {
        let result = await exchange.getVipLoanHistory(options);
        console.log(result);
    } catch (error) {
        console.log(error.message);
    }
}

const result = await getVipLoanHistory(myOkxAccount)

Get Borrow Interest and Limit

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

https://www.okx.com/docs-v5/en/#rest-api-account-get-borrow-interest-and-limit

Function Name:

getBorrowInterestAndLimit()

Usage:

import { createExchange } from "./exchanges/exchange.js";

  let myOkxAccount = createExchange({
      exchange: "okx",
      authenticate: true,
      key: "myKeys",
      secret: "mySecret",
      passphrase: "myPassphrase",
      label: "okx",
      marginType: "usdt"
});

async function getBorrowInterestAndLimit(exchange, options) {
    try {
        let result = await exchange.getBorrowInterestAndLimit(options);
        console.log(result);
    } catch (error) {
        console.log(error.message);
    }
}

const result = await getBorrowInterestAndLimit(myOkxAccount)

Position Builder

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

https://www.okx.com/docs-v5/en/#rest-api-account-position-builder

Function Name:

positionBuilder()

Usage:

import { createExchange } from "./exchanges/exchange.js";

  let myOkxAccount = createExchange({
      exchange: "okx",
      authenticate: true,
      key: "myKeys",
      secret: "mySecret",
      passphrase: "myPassphrase",
      label: "okx",
      marginType: "usdt"
});

async function positionBuilder(exchange, options) {
    try {
        let result = await exchange.positionBuilder(options);
        console.log(result);
    } catch (error) {
        console.log(error.message);
    }
}

const result = await positionBuilder(myOkxAccount,
{
   instType:"SWAP",
   inclRealPos:"true",
   simPos:[
     {
          pos:"10",
          instId:"BTC-USDT-SWAP"
     },
     {
          pos:"10",
          instId:"LTC-USDT-SWAP"
     }
   ]
})

Get Greeks

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

https://www.okx.com/docs-v5/en/#rest-api-account-get-greeks

Function Name:

getGreeks()

Usage:

import { createExchange } from "./exchanges/exchange.js";

  let myOkxAccount = createExchange({
      exchange: "okx",
      authenticate: true,
      key: "myKeys",
      secret: "mySecret",
      passphrase: "myPassphrase",
      label: "okx",
      marginType: "usdt"
});

async function getGreeks(exchange, options) {
    try {
        let result = await exchange.getGreeks(options);
        console.log(result);
    } catch (error) {
        console.log(error.message);
    }
}

const result = await getGreeks(myOkxAccount)

Subaccount

View Subaccount List

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

https://www.okx.com/docs-v5/en/#rest-api-subaccount-view-sub-account-list

Function Name:

getSubaccountList()

Usage:

import { createExchange } from "./exchanges/exchange.js";

  let myOkxAccount = createExchange({
      exchange: "okx",
      authenticate: true,
      key: "myKeys",
      secret: "mySecret",
      passphrase: "myPassphrase",
      label: "okx",
      marginType: "usdt"
});

async function getSubaccountList(exchange, options) {
    try {
        let result = await exchange.getSubaccountList(options);
        console.log(result);
    } catch (error) {
        console.log(error.message);
    }
}

const result = await getSubaccountList(myOkxAccount)

Get Subaccount Trading Balance

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

https://www.okx.com/docs-v5/en/#rest-api-subaccount-get-sub-account-trading-balance

Function Name:

getSubaccountTradingBalance()

Usage:

import { createExchange } from "./exchanges/exchange.js";

  let myOkxAccount = createExchange({
      exchange: "okx",
      authenticate: true,
      key: "myKeys",
      secret: "mySecret",
      passphrase: "myPassphrase",
      label: "okx",
      marginType: "usdt"
});

async function getSubaccountTradingBalance(exchange, options) {
    try {
        let result = await exchange.getSubaccountTradingBalance(options);
        console.log(result);
    } catch (error) {
        console.log(error.message);
    }
}

const result = await getSubaccountTradingBalance(myOkxAccount, {
    subAcct: "mySubaccount"
    })

Get Subaccount Funding Balance

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

https://www.okx.com/docs-v5/en/#rest-api-subaccount-get-sub-account-funding-balance

Function Name:

getSubaccountFundingBalance()

Usage:

import { createExchange } from "./exchanges/exchange.js";

  let myOkxAccount = createExchange({
      exchange: "okx",
      authenticate: true,
      key: "myKeys",
      secret: "mySecret",
      passphrase: "myPassphrase",
      label: "okx",
      marginType: "usdt"
});

async function getSubaccountFundingBalance(exchange, options) {
    try {
        let result = await exchange.getSubaccountFundingBalance(options);
        console.log(result);
    } catch (error) {
        console.log(error.message);
    }
}

const result = await getSubaccountFundingBalance(myOkxAccount, {
    subAcct: "mySubaccount"
    })

History of Subaccount Transfer

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