Comment on page
💻
Common Functions
This page documents common functions across exchanges within the PENDAX SDK that developers can utilize while integrating.
Common functions are widely used calls available on different platforms and will work by just changing the "exchange" parameter and making edits to API credential layouts (depending on the selected exchange).
Some exchanges may not be included in common functions due to unique API layouts native to that platform. If a common function is not found here for your selected exchange then please visit that exchange's functions page.
getBalances(options)
- FTX ( ⚠️ Exchange Unavailable - For Documentation Purposes ONLY)
- FTX US ( ⚠️ Exchange Unavailable - For Documentation Purposes ONLY)
Please refer to the official OKX API documentation for all available and/or required parameters to send.
const exchange = createExchange({
exchange: "okx",
key: "jdsklsakh-76sruuu2",
secret: "GASDF45II@kkkk",
label: "okx", // any value
passphrase: "hhsgr$!kkks",
margintype: "usdt" // coin, usdt
});
// If no param passed, returns balances of all coins/assets, etc.
// To filter to specific assets, pass an object with a property 'tokens',
// where tokens is an array of asset names (see example)
const result =
try {
return await exchange.getBalances(
{
tokens: ['BTC', 'USD']
}
)
}
catch (err) {
console.log(err);
}
Please refer to the official FTX API documentation for all available and/or required parameters to send.
const exchange = createExchange({
exchange: "ftx",
authenticate: true,
key: "123455676890",
secret: "abcdefghijk",
subaccount: "subaccountname",
label: "ftx", // any value
});
// If no param passed, returns balances of all coins/assets, etc.
// To filter to specific assets, pass an object with a property 'tokens',
// where tokens is an array of asset names (see example)
const result =
try {
return await exchange.getBalances(
{
tokens: ['BTC', 'USD']
}
)
}
catch (err) {
console.log(err);
}
Please refer to the official FTX US API documentation for all available and/or required parameters to send.
const exchange = createExchange({
exchange: "ftxus",
authenticate: true,
key: "123455676890",
secret: "abcdefghijk",
subaccount: "subaccountname",
label: "ftxus", // any value
});
// If no param passed, returns balances of all coins/assets, etc.
// To filter to specific assets, pass an object with a property 'tokens',
// where tokens is an array of asset names (see example)
const result =
try {
return await exchange.getBalances(
{
tokens: ['BTC', 'USD']
}
)
}
catch (err) {
console.log(err);
}
placeOrder(options)
- FTX ( ⚠️ Exchange Unavailable - For Documentation Purposes ONLY)
- FTX US ( ⚠️ Exchange Unavailable - For Documentation Purposes ONLY)
Please refer to the official OKX API documentation for all available and/or required parameters to send. https://www.okx.com/docs-v5/en/#rest-api-trade-place-order
const exchange = createExchange({
exchange: "okx",
key: "jdsklsakh-76sruuu2",
secret: "GASDF45II@kkkk",
label: "okx", // any value
passphrase: "hhsgr$!kkks",
margintype: "usdt" // coin, usdt
});
// Place order
// parameters are per the exchange's api requirements
const result =
try {
return await exchange.placeOrder(
{
market: "BTC/USD",
side: "buy",
price: null,
type: "market",
size: 0.0009009
}
}
catch (err) {
console.log(err);
}
Please refer to the official FTX API documentation for all available and/or required parameters to send. https://docs.ftx.com/#place-order
// Create exchange
const exchange = createExchange({
exchange: "ftx",
authenticate: true,
key: "123455676890",
secret: "abcdefghijk",
subaccount: "subaccountname",
label: "ftx", // any value
});
// Place order
// parameters are per the exchange's api requirements
const result =
try {
return await exchange.placeOrder(
{
market: "BTC/USD",
side: "buy",
price: null,
type: "market",
size: 0.0009009
}
}
catch (err) {
console.log(err);
}
Please refer to the official FTX US API documentation for all available and/or required parameters to send. https://docs.ftx.us/#place-order
// Create exchange
const exchange = createExchange({
exchange: "ftxus",
authenticate: true,
key: "123455676890",
secret: "abcdefghijk",
subaccount: "subaccountname",
label: "ftxus", // any Value
});
// Place order
// parameters are per the exchange's api requirements
const result =
try {
return await exchange.placeOrder(
{
market: "BTC/USD",
side: "buy",
price: null,
type: "market",
size: 0.0009009
}
}
catch (err) {
console.log(err);
}
cancelOrder(options)
- FTX ( ⚠️ Exchange Unavailable - For Documentation Purposes ONLY)
- FTX US ( ⚠️ Exchange Unavailable - For Documentation Purposes ONLY)
Please refer to the official OKX API documentation for all available and/or required parameters to send. https://www.okx.com/docs-v5/en/#rest-api-trade-cancel-order
const exchange = createExchange({
exchange: "okx",
key: "jdsklsakh-76sruuu2",
secret: "GASDF45II@kkkk",
label: "okx", // any value
passphrase: "hhsgr$!kkks",
margintype: "usdt" // coin, usdt
});
const result =
try {
return await exchange.cancelOrder(
{
instId: "BTC/USD", // required
ordId: "87757021604562009" // ordId OR clOrdId required
}
}
catch (err) {
console.log(err);
}
Please refer to the official FTX API documentation for all available and/or required parameters to send. https://docs.ftx.com/#cancel-order
// Create exchange
const exchange = createExchange({
exchange: "ftx",
authenticate: true,
key: "123455676890",
secret: "abcdefghijk",
subaccount: "subaccountname",
label: "ftx", // any value
});
const result =
try {
return await exchange.cancelOrder(
{
order_id: "265102861651009"
}
}
catch (err) {
console.log(err);
}
Please refer to the official FTX API documentation for all available and/or required parameters to send. https://docs.ftx.us/#cancel-order
// Create exchange
const exchange = createExchange({
exchange: "ftxus",
authenticate: true,
key: "123455676890",
secret: "abcdefghijk",
subaccount: "subaccountname",
label: "ftxus", // any value
});
const result =
try {
return await exchange.cancelOrder(
{
order_id: "265102861651009"
}
}
catch (err) {
console.log(err);
}
cancellAllOrders(options)
- FTX ( ⚠️ Exchange Unavailable - For Documentation Purposes ONLY)
- FTX US ( ⚠️ Exchange Unavailable - For Documentation Purposes ONLY)
Not supported on OKX (Use combination of getLiveOrders() or the native getOrderList() and cancelMultiOrder() ) - WARNING - Okx rate-limits cancelMultiOrder() - see documents for details: https://www.okx.com/docs-v5/en/#rest-api-trade-cancel-multiple-orders
Please refer to the official FTX API documentation for all available and/or required parameters to send. https://docs.ftx.com/#cancel-all-orders
If no options are passed in, then all orders on the account will be canceled without regard to any other considerations.
// options:
// {
// market: 'BTC-PERP', //optional; restrict to cancelling orders only on this market
// side: 'buy', //optional; restrict to cancelling orders only on this side
// conditionalOrdersOnly: false, // optional; restrict to cancelling conditional orders only
// limitOrdersOnly: false, //optional; restrict to cancelling existing limit orders (non-conditional orders) only
// }
// Create exchange
const exchange = createExchange({
exchange: "ftx",
authenticate: true,
key: "123455676890",
secret: "abcdefghijk",
subaccount: "subaccountname",
label: "ftx", // any value
});
const result =
try {
return await exchange.cancelAllOrders(
{
side: 'buy'
}
}
catch (err) {
console.log(err);
}
Please refer to the official FTX US API documentation for all available and/or required parameters to send. https://docs.ftx.us/#cancel-all-orders
If no options are passed in, then all orders on the account will be canceled without regard to any other considerations.
// options:
// {
// market: 'BTC-PERP', //optional; restrict to cancelling orders only on this market
// side: 'buy', //optional; restrict to cancelling orders only on this side
// conditionalOrdersOnly: false, // optional; restrict to cancelling conditional orders only
// limitOrdersOnly: false, //optional; restrict to cancelling existing limit orders (non-conditional orders) only
// }
// Create exchange
const exchange = createExchange({
exchange: "ftxus",
authenticate: true,
key: "123455676890",
secret: "abcdefghijk",
subaccount: "subaccountname",
label: "ftxus", // any value
});
const result =
try {
return await exchange.cancelAllOrders(
{
side: 'buy'
}
}
catch (err) {
console.log(err);
}
getPositions(options)
- FTX ( ⚠️ Exchange Unavailable - For Documentation Purposes ONLY)
- FTX US ( ⚠️ Exchange Unavailable - For Documentation Purposes ONLY)
Please refer to the official OKX API documentation for all available and/or required parameters to send. https://www.okx.com/docs-v5/en/#rest-api-account-get-positions
// positionType: <'SPOT', 'FUTURE'>, - optional - if omitted, all are fetched
// markets: ..., - optional array of markets - 10 max if type is FUTURE - 20 max if SPOT
// posIds: ..., - optional array of posId's - 20 max if type is FUTURE - ignored if SPOT
// openClosed: <open/closed>} - optional - defaults to open AND closed
const exchange = createExchange({
exchange: "okx",
key: "jdsklsakh-76sruuu2",
secret: "GASDF45II@kkkk",
label: "okx", // any value
passphrase: "hhsgr$!kkks",
margintype: "usdt" // coin, usdt
});
const result =
try {
let result = await exchange.getPositions ({
positionType: 'FUTURE',
markets: ['BTC-USDT-SWAP'],
posIds: ['307173036051017730', '33049853605101720'],
openClosed: 'open'
});
console.log(result);
} catch (error) {
console.log(error.message);
}
This is a hybrid function that calls api getBalances() and api getPositions(). It adds the ability to filter results by:
- open or closed (does not affect balances)
- markets (must contain an array of market names)
- market type (spot or future - spot returns account balances, future returns account positions)
- in addition, the boolean parameter 'showAvgPrice' is supported as shown in the FTX getPositions api document: https://docs.ftx.com/#get-positions
// positionType: <'SPOT', 'FUTURE'>, - optional - if omitted, all are fetched
// markets: ..., - optional array of markets - 10 max if type is FUTURE - 20 max if SPOT
// openClosed: <open/closed>} - optional - defaults to open AND closed
// showAvgPrice: <true/false> - pertains to positions only - balances not affected
const exchange = createExchange({
exchange: "ftx",
authenticate: true,
key: "123455676890",
secret: "abcdefghijk",
subaccount: "subaccountname",
label: "ftx", // any value
});
const result =
try {
let result = await exchange.getPositions ({
positionType: 'FUTURE',
markets: ['BTC-USDT-SWAP'],
openClosed: 'open'
});
console.log(result);
} catch (error) {
console.log(error.message);
}
This function when used in FTX US responds with the information from the getBalances() function, but adds the ability to filter by token as shown below.
// positionType: <'SPOT', 'FUTURE'>, - optional - if omitted, all are fetched
// markets: ..., - optional array of markets - 10 max if type is FUTURE - 20 max if SPOT
// openClosed: <open/closed>} - optional - defaults to open AND closed
const exchange = createExchange({
exchange: "ftxus",
authenticate: true,
key: "123455676890",
secret: "abcdefghijk",
subaccount: "subaccountname",
label: "ftxus", // any value
});
const result =
try {
let result = await exchange.getPositions ({
tokens: ['BTC', 'USDT'], //(optional)
});
console.log(result);
} catch (error) {
console.log(error.message);
}
getLiveOrders(options)
- FTX ( ⚠️ Exchange Unavailable - For Documentation Purposes ONLY)
- FTX US ( ⚠️ Exchange Unavailable - For Documentation Purposes ONLY)
Please refer to the official OKX API documentation for all available and/or required parameters to send.
const exchange = createExchange({
exchange: "okx",
key: "jdsklsakh-76sruuu2",
secret: "GASDF45II@kkkk",
label: "okx", // any value
passphrase: "hhsgr$!kkks",
margintype: "usdt" // coin, usdt
});
const result =
try {
let result = await exchange.getLiveOrders ({
instType: 'SPOT',
ordType: 'limit',
state: 'partially_filled'
});
console.log(result);
} catch (error) {
console.log(error.message);
}
Please refer to the official FTX API documentation for all available and/or required parameters to send.
const exchange = createExchange({
exchange: "ftx",
authenticate: true,
key: "123455676890",
secret: "abcdefghijk",
subaccount: "subaccountname",
label: "ftx", // any value
});
const result =
try {
let result = await exchange.getLiveOrders ('BTC-PERP');
console.log(result);
} catch (error) {
console.log(error.message);
}
Please refer to the official FTX US API documentation for all available and/or required parameters to send.
const exchange = createExchange({
exchange: "ftxus",
authenticate: true,
key: "123455676890",
secret: "abcdefghijk",
subaccount: "subaccountname",
label: "ftxus", // any value
});
const result =
try {
let result = await exchange.getLiveOrders ('BTC');
console.log(result);
} catch (error) {
console.log(error.message);
}
getMarkets()
- FTX ( ⚠️ Exchange Unavailable - For Documentation Purposes ONLY)
- FTX US ( ⚠️ Exchange Unavailable - For Documentation Purposes ONLY)
Okx does not actually offer a getMarkets api. So this function calls api getTickers() twice. Once using parameter "SPOT", and once using parameter "SWAP". This returns markets for each in a combined format. If you want more detailed information you can call getTickers() directly, using the parameters detailed in the OKX api document. Please refer to the official OKX API documentation for all available and/or required parameters to send. https://www.okx.com/docs-v5/en/#rest-api-market-data-get-tickers
const exchange = createExchange({
exchange: "okx",
key: "jdsklsakh-76sruuu2",
secret: "GASDF45II@kkkk",
label: "okx", // any value
passphrase: "hhsgr$!kkks",
margintype: "usdt" // coin, usdt
});
const result =
try {
let result = await exchange.getMarkets();
console.log(result);
} catch (error) {
console.log(error.message);
}
OKX returns coins whether they are 'enabled' or not. An example of how to filter the results to include only enabled coins is below.
const exchange = createExchange({
exchange: "okx",
key: "jdsklsakh-76sruuu2",
secret: "GASDF45II@kkkk",
label: "okx", // any value
passphrase: "hhsgr$!kkks",
margintype: "usdt" // coin, usdt
});
const result =
try {
let result = await exchange.getMarkets();
if (result.result) {
result = result.result;
markets = result
.filter((coin) => {
return coin.enabled == true;
})
.map((coin) => {
return coin.name;
});
}
console.log(result);
} catch (error) {
console.log(error.message);
}
Please refer to the official FTX API documentation for all available and/or required parameters to send. https://docs.ftx.com/#get-markets
const exchange = createExchange({
exchange: "ftx",
authenticate: true,
key: "123455676890",
secret: "abcdefghijk",
subaccount: "subaccountname",
label: "ftx", // any value
});
const result =
try {
let result = await exchange.getMarkets();
console.log(result);
} catch (error) {
console.log(error.message);
}
Please refer to the official FTX US API documentation for all available and/or required parameters to send. https://docs.ftx.us/#get-markets
const exchange = createExchange({
exchange: "ftxus",
authenticate: true,
key: "123455676890",
secret: "abcdefghijk",
subaccount: "subaccountname",
label: "ftxus", // any value
});
const result =
try {
let result = await exchange.getMarkets();
console.log(result);
} catch (error) {
console.log(error.message);
}
getMarket()
- FTX ( ⚠️ Exchange Unavailable - For Documentation Purposes ONLY)
- FTX US ( ⚠️ Exchange Unavailable - For Documentation Purposes ONLY)
Fetches details on a given market. Relays a call to endpoint getTicker(). Please refer to the official FTX API documentation for all available and/or required parameters to send. https://www.okx.com/docs-v5/en/#rest-api-market-data-get-ticker
const exchange = createExchange({
exchange: "okx",
key: "jdsklsakh-76sruuu2",
secret: "GASDF45II@kkkk",
label: "okx", // any value
passphrase: "hhsgr$!kkks",
margintype: "usdt" // coin, usdt
});
const result =
try {
let result = await exchange.getMarket({instId: 'BTC-USDT-SWAP'});
console.log(result);
} catch (error) {
console.log(error.message);
}
Fetches details on a given market. Please refer to the official FTX API documentation for all available and/or required parameters to send. https://docs.ftx.com/#get-single-market
const exchange = createExchange({
exchange: "ftx",
authenticate: true,
key: "123455676890",
secret: "abcdefghijk",
subaccount: "subaccountname",
label: "ftx", // any value
});
const result =
try {
let result = await exchange.getMarket('BTC/USD');
console.log(result);
} catch (error) {
console.log(error.message);
}
Fetches details on a given market. Please refer to the official FTX API documentation for all available and/or required parameters to send. https://docs.ftx.us/#get-single-market
const exchange = createExchange({
exchange: "ftxus",
authenticate: true,
key: "123455676890",
secret: "abcdefghijk",
subaccount: "subaccountname",
label: "ftxus", // any value
});
const result =
try {
let result = await exchange.getMarket('BTC/USD');
console.log(result);
} catch (error) {
console.log(error.message);
}
getOpenInterest(options)
- FTX ( ⚠️ Exchange Unavailable - For Documentation Purposes ONLY)
Fetches the Open Interest on a Futures Market for a given symbol
const exchange = createExchange({
exchange: "okx",
key: "jdsklsakh-76sruuu2",
secret: "GASDF45II@kkkk",
label: "okx", // any value
passphrase: "hhsgr$!kkks",
margintype: "usdt" // coin, usdt
});
const result =
try {
let result = await exchange.