Links

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.

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.

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.

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.

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.

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.

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.

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.

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.

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.

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.

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.

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.

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.

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.

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.

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.

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.

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.

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.

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