💻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.

Account Data

Get Balances

getBalances(options)

Available Exchanges:

  • FTX ( ⚠️ Exchange Unavailable - For Documentation Purposes ONLY)

  • FTX US ( ⚠️ Exchange Unavailable - For Documentation Purposes ONLY)

OKX

Please refer to the official OKX API documentation for all available and/or required parameters to send.

OKX Example:

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);
    }  
⚠️ FTX

Please refer to the official FTX API documentation for all available and/or required parameters to send.

FTX Example:

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

⚠️ FTX US

Please refer to the official FTX US API documentation for all available and/or required parameters to send.

FTX US Example:

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

Trading

Place Order

placeOrder(options)

Available Exchanges:

  • FTX ( ⚠️ Exchange Unavailable - For Documentation Purposes ONLY)

  • FTX US ( ⚠️ Exchange Unavailable - For Documentation Purposes ONLY)

OKX

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

OKX Example

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

⚠️ FTX

Please refer to the official FTX API documentation for all available and/or required parameters to send. https://docs.ftx.com/#place-order

FTX Example

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

⚠️ FTX US

Please refer to the official FTX US API documentation for all available and/or required parameters to send. https://docs.ftx.us/#place-order

FTX US Example

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

Cancel Order

cancelOrder(options)

Available Exchanges:

  • FTX ( ⚠️ Exchange Unavailable - For Documentation Purposes ONLY)

  • FTX US ( ⚠️ Exchange Unavailable - For Documentation Purposes ONLY)

OKX

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

OKX Example:

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);
    }
⚠️ FTX

Please refer to the official FTX API documentation for all available and/or required parameters to send. https://docs.ftx.com/#cancel-order

FTX Example:

// 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);
    }
⚠️ FTX US

Please refer to the official FTX API documentation for all available and/or required parameters to send. https://docs.ftx.us/#cancel-order

FTX US Example:

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

Cancel All Orders

cancellAllOrders(options)

Available Exchanges:

  • 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

⚠️ FTX

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.

FTX Example:

// 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);
    }
⚠️ FTX US

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.

FTX US Example:

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

Get Open Positions

getPositions(options)

Available Exchanges:

  • FTX ( ⚠️ Exchange Unavailable - For Documentation Purposes ONLY)

  • FTX US ( ⚠️ Exchange Unavailable - For Documentation Purposes ONLY)

OKX

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

OKX Example

// 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);
   }
⚠️ FTX

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

FTX Example:

// 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);
   }
⚠️ FTX US

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.

FTX US Example:

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

Get Open Orders

getLiveOrders(options)

Available Exchanges:

  • FTX ( ⚠️ Exchange Unavailable - For Documentation Purposes ONLY)

  • FTX US ( ⚠️ Exchange Unavailable - For Documentation Purposes ONLY)

OKX

Please refer to the official OKX API documentation for all available and/or required parameters to send.

OKX Example:

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);
   }
⚠️ FTX

Please refer to the official FTX API documentation for all available and/or required parameters to send.

FTX Example:

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);
   }
⚠️ FTX US

Please refer to the official FTX US API documentation for all available and/or required parameters to send.

FTX US Example:

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

Market Info

Get Markets

getMarkets()

Available Exchanges:

  • FTX ( ⚠️ Exchange Unavailable - For Documentation Purposes ONLY)

  • FTX US ( ⚠️ Exchange Unavailable - For Documentation Purposes ONLY)

OKX

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

OKX Example:

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 Example with filtering:

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);
   }
⚠️ FTX

Please refer to the official FTX API documentation for all available and/or required parameters to send. https://docs.ftx.com/#get-markets

FTX Example:

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);
   }
⚠️ FTX US

Please refer to the official FTX US API documentation for all available and/or required parameters to send. https://docs.ftx.us/#get-markets

FTX US Example:

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

Get Market

getMarket()

Available Exchanges:

  • FTX ( ⚠️ Exchange Unavailable - For Documentation Purposes ONLY)

  • FTX US ( ⚠️ Exchange Unavailable - For Documentation Purposes ONLY)

OKX

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

OKX Example:

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);
   }
⚠️ FTX

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

FTX Example:

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);
   }
⚠️ FTX US

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

Get Open Interest

getOpenInterest(options)

Available Exchanges:

  • FTX ( ⚠️ Exchange Unavailable - For Documentation Purposes ONLY)

OKX

Fetches the Open Interest on a Futures Market for a given symbol

OKX Example:

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.getOpenInterest({
          instType: 'SWAP', 
          instId: 'BTC-USDT-SWAP'
          });
      console.log(result);
   } catch (error) {
      console.log(error.message);
   }
⚠️ FTX

Fetches the Open Interest on a Futures Market for a given symbol

FTX Example:

const exchange = createExchange({
  exchange: "ftx",
  authenticate: true,
  key: "123455676890",
  secret: "abcdefghijk",
  subaccount: "subaccountname",
  label: "ftx",   // any value
});
const result = 
    try {
      let result = await exchange.getOpenInterest(
          {
           market:'BTC-PERP'
          });
      console.log(result);
   } catch (error) {
      console.log(error.message);
   }

Get Current Funding Rate

getCurrentFundingRate(options)

Available Exchanges:

  • FTX ( ⚠️ Exchange Unavailable - For Documentation Purposes ONLY)

OKX

Fetches the current funding rate on a futures instrument

OKX Example:

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.getCurrentFundingRate({ future_name: 'BTC-USDT-SWAP'});
     console.log(result);
   } catch (error) {
      console.log(error.message);
   }
⚠️ FTX

Fetches the current funding rate on a futures instrument.

FTX Example:

const exchange = createExchange({
  exchange: "ftxus",
  authenticate: true,
  key: "123455676890",
  secret: "abcdefghijk",
  subaccount: "subaccountname",
  label: "ftxus",   // any value
});
const result = 
    try {
      let result = await exchange.getCurrentFundingRate(
         {
           future_name: future_name: 'BTC-PERP'
         });
     console.log(result);
   } catch (error) {
      console.log(error.message);
   }

Get Next Funding Rate

getNextFundingRate(options)

Available Exchanges:

  • FTX ( ⚠️ Exchange Unavailable - For Documentation Purposes ONLY)

OKX

Fetches the next funding rate on a futures market

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.getNextFundingRate({ future_name: 'BTC-USDT-SWAP'});
     console.log(result);
   } catch (error) {
      console.log(error.message);
   }
⚠️ FTX

Fetches the next funding rate on a futures market

FTX Example:

const exchange = createExchange({
  exchange: "ftxus",
  authenticate: true,
  key: "123455676890",
  secret: "abcdefghijk",
  subaccount: "subaccountname",
  label: "ftxus",   // any value
});
const result = 
    try {
      let result = await exchange.getNextFundingRate(
         {
           future_name: future_name: 'BTC-PERP'
         });
     console.log(result);
   } catch (error) {
      console.log(error.message);
   }

Last updated