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.

https://www.okx.com/docs-v5/en/#rest-api-trade-place-order

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.

https://www.okx.com/docs-v5/en/#rest-api-trade-place-multiple-orders

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.

https://www.okx.com/docs-v5/en/#rest-api-trade-cancel-order

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.

https://www.okx.com/docs-v5/en/#rest-api-trade-cancel-multiple-orders

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.

https://www.okx.com/docs-v5/en/#rest-api-trade-amend-order

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.

https://www.okx.com/docs-v5/en/#rest-api-trade-amend-multiple-orders

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.

https://www.okx.com/docs-v5/en/#rest-api-trade-close-positions

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.

https://www.okx.com/docs-v5/en/#rest-api-trade-get-order-details

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.

https://www.okx.com/docs-v5/en/#rest-api-trade-get-order-list

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.

https://www.okx.com/docs-v5/en/#rest-api-trade-get-order-history-last-7-days

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.

https://www.okx.com/docs-v5/en/#rest-api-trade-get-order-history-last-3-months

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.

https://www.okx.com/docs-v5/en/#rest-api-trade-get-transaction-details-last-3-days

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.

https://www.okx.com/docs-v5/en/#rest-api-trade-get-transaction-details-last-3-months

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.

https://www.okx.com/docs-v5/en/#rest-api-trade-place-algo-order

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

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

https://www.okx.com/docs-v5/en/#rest-api-trade-cancel-algo-order

Function Name:

cancelAlgoOrder()

Usage:

// 

Cancel Advance Algo Order

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

https://www.okx.com/docs-v5/en/#rest-api-trade-cancel-advance-algo-order

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.

https://www.okx.com/docs-v5/en/#rest-api-trade-get-algo-order-list

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.

https://www.okx.com/docs-v5/en/#rest-api-trade-get-algo-order-history

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

Place Easy Convert

Get Easy Convert History

Get One-Click Repay Currency List

Trade One-Click Repay

Get One-Click Repay History

Block Trading

Get Counterparties

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

https://www.okx.com/docs-v5/en/#rest-api-block-trading-get-counterparties

Function Name:

getCounterparties()

Usage:

// 

Create RFQ

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

https://www.okx.com/docs-v5/en/#rest-api-block-trading-create-rfq

Function Name:

createRfq()

Usage:

// 

Cancel RFQ

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

https://www.okx.com/docs-v5/en/#rest-api-block-trading-cancel-rfq

Function Name:

cancelRfq()

Usage:

//

Cancel Multiple RFQ's

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

https://www.okx.com/docs-v5/en/#rest-api-block-trading-cancel-multiple-rfqs

Function Name:

cancelBatchRfq()

Usage:

//

Cancel All RFQ's

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

https://www.okx.com/docs-v5/en/#rest-api-block-trading-cancel-all-rfqs

Function Name:

cancelAllRfqs()

Usage:

//

Execute Quote

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

https://www.okx.com/docs-v5/en/#rest-api-block-trading-execute-quote

Function Name:

executeQuote()

Usage:

//

Set Quote Products

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

https://www.okx.com/docs-v5/en/#rest-api-block-trading-set-quote-products

Function Name:

//

Usage:

//

Reset MMP Status

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

https://www.okx.com/docs-v5/en/#rest-api-block-trading-reset-mmp-status

Function Name:

//

Usage:

//

Create Quote

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

https://www.okx.com/docs-v5/en/#rest-api-block-trading-create-quote

Function Name:

createQuote()

Usage:

//

Cancel Quote

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

https://www.okx.com/docs-v5/en/#rest-api-block-trading-cancel-quote

Function Name:

cancelQuote()

Usage:

//

Cancel Multiple Quotes

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

https://www.okx.com/docs-v5/en/#rest-api-block-trading-cancel-multiple-quotes

Function Name:

cancelBatchQuotes()

Usage:

//

Cancel All Quotes

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

https://www.okx.com/docs-v5/en/#rest-api-block-trading-cancel-all-quotes

Function Name:

cancelAllQuotes()

Usage:

//

Get RFQ's

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

https://www.okx.com/docs-v5/en/#rest-api-block-trading-get-rfqs

Function Name:

getRfqs()

Usage:

//

Get Quotes

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

https://www.okx.com/docs-v5/en/#rest-api-block-trading-get-quotes

Function Name:

getQuotes()

Usage:

//

Get Trades

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

https://www.okx.com/docs-v5/en/#rest-api-block-trading-get-trades

Function Name:

getUserBlockTrades()

Usage:

//

Get Public Trades

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

https://www.okx.com/docs-v5/en/#rest-api-block-trading-get-public-trades

Function Name:

getPublicBlockTrades()

Usage:

//

Last updated