All Account and Subaccount API endpoints require authentication. Please create OKX API keys to interact with these functions successfully.
Account
Get Balance
Function Name:
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
Function Name:
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
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
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)
Function Name:
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)
Function Name:
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
Function Name:
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
Function Name:
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
Function Name:
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
Function Name:
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
Function Name:
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
Function Name:
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
Function Name:
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
Function Name:
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
Function Name:
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
Function Name:
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
Function Name:
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
Function Name:
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
Function Name:
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
Function Name:
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
Function Name:
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
Function Name:
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
Function Name:
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
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
Function Name:
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
Function Name:
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
Function Name:
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
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
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
Function Name:
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 getSubaccountBills(exchange, options) {
try {
let result = await exchange.getSubaccountBills(options);
console.log(result);
} catch (error) {
console.log(error.message);
}
}
const result = await getSubaccountBills(myOkxAccount)
Master Accounts Manage the Transfers Between Subaccounts
Function Name:
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 subaccountTransfer(exchange, options) {
try {
let result = await exchange.subaccountTransfer(options);
console.log(result);
} catch (error) {
console.log(error.message);
}
}
const result = await subaccountTransfer(myOkxAccount,
{
ccy:"USDT",
amt:"1.5",
from:"6",
to:"6",
fromSubAccount:"test-1",
toSubAccount:"test-2"
})
Set Permission of Transfer Out
Function Name:
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 canTransferOut(exchange, options) {
try {
let result = await exchange.canTransferOut(options);
console.log(result);
} catch (error) {
console.log(error.message);
}
}
const result = await canTransferOut(myOkxAccount,
{
subAcct:"test-1",
canTransOut:true
})
Get Custody Trading Subaccount List
Function Name:
getCustodyTradingAccountList()
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 getCustodyTradingAccountList(exchange, options) {
try {
let result = await exchange.getCustodyTradingAccountList(options);
console.log(result);
} catch (error) {
console.log(error.message);
}
}
const result = await getCustodyTradingAccountList(myOkxAccount)