๐Ÿ’ปOKX Functions

Documentation for interacting with OKX functions and API endpoints through the PENDAX Javascript SDK.

Create an Exchange Object

Before you can interact with PENDAX functions, you must first create an Exchange object. This exchange object will allow you to interact with PENDAX. You can create one or multiple, and reference them together or individually throughout your code.

Example Exchange Object Creation:

import { createExchange } from "./exchanges/exchange.js";

let myOkxAccount = createExchange({
  exchange: "okx",
  authenticate: true,
  key: "myKeys",
  secret: "mySecret",
  passphrase: "myPassphrase",
  label: "okx",
  marginType: "usdt" // coin or usdt
});

Unauthenticated Exchange Objects

If you are just calling public API endpoints on the exchange and you don't need any authentication to protected endpoints, simply create your exchange object with authenticate set to false and omit the key, secret, passphrase.

Authenticated Exchange objects can call private and public endpoints, however, unauthenticated exchange objects may only call public endpoints.

Example Unauthenticated Exchange Object:

import { createExchange } from "./exchanges/exchange.js";

let myOkxAccount = createExchange({
  exchange: "okx",
  authenticate: false,
  label: "okx",
  marginType: "usdt" // coin or usdt
});

Once an Exchange object has been created you may use any of the available functions allowed by that exchange by referencing the name of the Exchange object you created.

Example using multiple Exchange Objects for executing PENDAX functions:

import { createExchange } from "./exchanges/exchange.js";

let myOkxAccount = createExchange({
  exchange: "okx",
  authenticate: true,
  key: "myKeys",
  secret: "mySecret",
  passphrase: "myPassphrase",
  label: "okx",
  marginType: "usdt"
});

let myOtherOkxAccount = createExchange({
  exchange: "okx",
  authenticate: true,
  key: "myOtherKeys",
  secret: "myOtherSecret",
  passphrase: "myOtherPassphrase",
  label: "okx2",
  marginType: "usdt"
});

 async function placeOrder(options){
    try {
      let result = await myOkxAccount.placeOrder (options);
      console.log(result);
    } catch (error) {
      console.log(error.message);
    }
  }  
  async function placeOrder(options){
    try {
      let result = await myOtherOkxAccount.placeOrder (options);
      console.log(result);
    } catch (error) {
      console.log(error.message);
    }
  }

All Available OKX Functions

Documentation for each category of functions is broken down into its own subpage in order to make navigating pages simpler and faster. Please use the side navigation to access these sub-pages or click on one of the links below.

Trading & OrdersFundingConvertAccount & SubaccountGrid TradingMarket DataPublic DataTrading Data

Exchange API Availability Status

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

https://www.okx.com/docs-v5/en/#rest-api-status

Function name:

getStatus() 

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

const result = await getStatus(myOkxAccount)

WebSocket Example Code

Please refer to the attached repository to utilize OKX WebSocket connections for trading and data deployments through the PENDAX SDK

Last updated