Links

Trading & Orders

Documentation on interacting with a variety of OKX trading and order API functions through the PENDAX SDK.
All Trading & Order API endpoints require authentication. Please create OKX API keys to interact with these functions successfully. Accounts must be funded or collateralized for any trades to successfully post. Please note that some endpoints for Algo & Block trading are currently under development.

Placing and Manipulating Orders

Place Order

Please refer to the official OKX API Docs for the required parameters. You can place an order only if you have sufficient funds.

Function Name:

placeOrder()

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 placeOrder(exchange, options) {
try {
let result = await exchange.placeOrder(options);
return result
console.log(result);
} catch (error) {
console.log(error.message);
}
}
const result = await placeOrder(myOkxAccount, {
instId: "BTC-USDT",
tdMode: "cash",
side: "buy",
ordType: "limit",
px: "10000",
sz: ".01", // for SWAPS sz is number of contracts which is .01 BTC
})

Place Multiple Orders

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

Function Name:

placeMultiOrder()

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 placeMultiOrder(exchange, options) {
try {
let result = await exchange.placeMultiOrder(options);
console.log(result);
} catch (error) {
console.log(error.message);
}
}
const result = await placeMultiOrder(myOkxAccount, [
{
instId:"BTC-USDT",
tdMode:"cash",
clOrdId:"b15",
side:"buy",
ordType:"limit",
px:"2.15",
sz:"2"
},
{
instId:"BTC-USDT",
tdMode:"cash",
clOrdId:"b15",
side:"buy",
ordType:"limit",
px:"2.15",
sz:"2"
}
])

Cancel Order

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

Function Name:

cancelOrder()

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 cancelOrder(exchange, options) {
try {
let result = await exchange.cancelOrder(options);
console.log(result);
} catch (error) {
console.log(error.message);
}
}
const result = await cancelOrder(myOkxAccount, {
ordId:"2510789768709120",
instId:"BTC-USD-190927"
})

Cancel Multiple Orders

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

Function Name:

cancelMultiOrder()

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 cancelMultiOrder(exchange, options) {
try {
let result = await exchange.cancelMultiOrder(options);
console.log(result);
} catch (error) {
console.log(error.message);
}
}
const result = await cancelOrder(myOkxAccount, [
{
ordId:"2510789768709120",
instId:"BTC-USD-190927"
},
{
ordId:"12312",
instId:"BTC-USDT"
}
])

Amend Order

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

Function Name:

modifyOrder()

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 modifyOrder(exchange, options) {
try {
let result = await exchange.modifyOrder(options);
console.log(result);
} catch (error) {
console.log(error.message);
}
}
const result = await modifyOrder(myOkxAccount, {
ordId:"2510789768709120",
newSz:"2",
instId:"BTC-USDT"
})

Amend Multiple Orders

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

Function Name:

modifyMultiOrder()

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 modifyMultiOrder(exchange, options) {
try {
let result = await exchange.modifyMultiOrder(options);
console.log(result);
} catch (error) {
console.log(error.message);
}
}
const result = await modifyMultiOrder(myOkxAccount, [
{
ordId:"2510789768709120",
newSz:"2",
instId:"BTC-USDT"
},
{
ordId:"2510789768709121",
newSz:"2",
instId:"BTC-USDT"
}
])

Close Positions

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

Function Name:

closePositions()

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 closePositions(exchange, options) {
try {
let result = await exchange.closePositions(options);
console.log(result);
} catch (error) {
console.log(error.message);
}
}
const result = await closePositions(myOkxAccount, {
instId:"BTC-USDT-SWAP",
mgnMode:"cross"
})

Order Details And Transaction History

Get Order Details

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

Function Name:

getOrderDetails()

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 getOrderDetails(exchange, options) {
try {
let result = await exchange.getOrderDetails(options);
console.log(result);
} catch (error) {
console.log(error.message);
}
}
const result = await getOrderDetails(myOkxAccount, {
instId: "BTC-USDT"
})

Get Order List

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

Function Name:

getOrderList()

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 getOrderList(exchange, options) {
try {
let result = await exchange.getOrderList(options);
console.log(result);
} catch (error) {
console.log(error.message);
}
}
const result = await getOrderList(myOkxAccount)

Get Order History (last 7 days)

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

Function Name:

getOrderHistoryWeek()

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 getOrderHistoryWeek(exchange, options) {
try {
let result = await exchange.getOrderHistoryWeek(options);
console.log(result);
} catch (error) {
console.log(error.message);
}
}
const result = await getOrderHistoryWeek(myOkxAccount, {
instType: "SPOT"
})

Get Order History (last 3 months)

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

Function Name:

getOrderHistoryArchive()

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 getOrderHistoryArchive(exchange, options) {
try {
let result = await exchange.getOrderHistoryArchive(options);
console.log(result);
} catch (error) {
console.log(error.message);
}
}
const result = await getOrderHistoryArchive(myOkxAccount, {
instType: "SPOT"
})

Get Transaction Details (last 3 days)

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

Function Name:

getRecentTransactionDetailsShort()

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 getRecentTransactionDetailsShort(exchange, options) {
try {
let result = await exchange.getRecentTransactionDetailsShort(options);
console.log(result);
} catch (error) {
console.log(error.message);
}
}
const result = await getRecentTransactionDetailsShort(myOkxAccount)

Get Transaction Details (last 3 months)

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

Function Name:

getRecentTransactionDetailsLong()

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 getRecentTransactionDetailsLong(exchange, options) {
try {
let result = await exchange.getRecentTransactionDetailsLong(options);
console.log(result);
} catch (error) {
console.log(error.message);
}
}
const result = await getRecentTransactionDetailsLong(myOkxAccount)

Placing & Editing Algo Orders

Place Algo Order

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

Function Name:

placeAlgoOrder()

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 placeAlgoOrder(exchange, options) {
try {
let result = await exchange.placeAlgoOrder(options);
console.log(result);
} catch (error) {
console.log(error.message);
}
}
const result = await placeAlgoOrder(myOkxAccount, {
instId:"BTC-USDT",
tdMode:"cross",
side:"buy",
ordType:"conditional",
sz:"2",
tpTriggerPx:"15",
tpOrdPx:"18")
})

Cancel Algo Order

This endpoint is currently under development
Please refer to the official OKX API Docs for required parameters.

Function Name:

cancelAlgoOrder()

Usage:

//

Cancel Advance Algo Order

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

Function Name:

cancelAdvAlgoOrder()

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 cancelAdvAlgoOrder(exchange, options) {
try {
let result = await exchange.cancelAdvAlgoOrder(options);
console.log(result);
} catch (error) {
console.log(error.message);
}
}
const result = await cancelAdvAlgoOrder(myOkxAccount,
[
{
algoId:"198273485",
instId:"BTC-USDT"
},
{
algoId:"198273485",
instId:"BTC-USDT"
}
])

Get Algo Order List

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

Function Name:

getAlgoOrderList()

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 getAlgoOrderList(exchange, options) {
try {
let result = await exchange.getAlgoOrderList(options);
console.log(result);
} catch (error) {
console.log(error.message);
}
}
const result = await getAlgoOrderList(myOkxAccount, {
ordType: "conditional"
})

Get Algo Order History

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

Function Name:

getAlgoOrderHistory()

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 getAlgoOrderHistory(exchange, options) {
try {
let result = await exchange.getAlgoOrderHistory(options);
console.log(result);
} catch (error) {
console.log(error.message);
}
}
const result = await getAlgoOrderHistory(myOkxAccount, {
state: "effective",
ordType: "conditional"
})

One-Click & Easy Convert

Get Easy Convert Currency List

This endpoint is currently under development.

Place Easy Convert

This endpoint is currently under development.

Get Easy Convert History

This endpoint is currently under development.

Get One-Click Repay Currency List

This endpoint is currently under development.

Trade One-Click Repay

This endpoint is currently under development.

Get One-Click Repay History

This endpoint is currently under development.

Block Trading

Get Counterparties

This endpoint is under development
Please refer to the official OKX API Docs for required parameters.

Function Name:

getCounterparties()

Usage: