Not all products mentioned are available in all jurisdictions.

OKX API FAQ

Published on Sep 20, 2024Updated on Nov 1, 20246 min read4

What does Passphrase refer to?

This is the password you filled in when applying for the APIKey. You need to remember it yourself. Once you forget it, you can't retrieve it and you'll need to create a new APIKey.

How to create a demo disk APIKey?

To trade on the demo disk API, you need to create an APIKey on the demo disk. Follow the steps below:

Log in to your OKX Account > Trading > Demo Trading > Personal Center > Create Demo Account APIKey > Start Demo Trading

Will the APIKey expire?

APIKeys that aren't bound to IP and have transaction or withdrawal permissions will be automatically deleted after 14 days of inactivity. APIKeys will not be considered inactive if they are used to call private or account-related interfaces that require identity verification, such as viewing account balance, billing data, or placing orders.

Only read-only APIKeys bound to an IP or specific permissions will not expire.

Can orders be placed in USDT or currency units when placing orders through the interface?

No; for contract orders, the interface defaults to orders in number of contracts. If you need to calculate the conversion between the number of contracts and coins, you can refer to the number of contracts-to-coin conversion interface here.

How to obtain the fluctuation rate of the interface?

The interface cannot directly obtain the price increase or decrease, but it can be calculated through a calculation formula.

The rise and fall value of the latest transaction price compared to the opening price of the K-line 24 hours ago/100% of the opening price of the K-line 24 hours ago.

The above formula data can be obtained through the market interface here (last-open24h)/open24h.

What's the reason for the error message "51000 Parameter posSide error" when placing an order?

You need to check the account mode first; buying and selling mode/opening and closing mode, which can be viewed here to obtain posMode.

Note:

  • In the case of opening and closing positions and placing orders using a contract, the posSide parameter is required, and long or short is filled in.

  • If it's a buying and selling mode, or a cryptocurrency or leveraged transaction is conducted under the opening and closing mode, posSide only supports net or no transmission.

Which interface can be used to obtain the contract face value and minimum order quantity?

You can use the interface to obtain basic information of trading products here.

contract face value: ctVal, minimum order quantity: minSz.

What's the format of instId?

You can directly use the interface to obtain the basic information of trading products here.

Example of instId format:

Coin/Coin leverage: BTC-USDT

Perpetual contract: Coin standard: BTC-USD-SWAP, U standard: BTC-USDT-SWAP All letters must be capitalized

Settlement contract: currency standard: BTC-USD-210326, U standard: BTC-USDT-210326 last two digits of the year + current week or next week or current month or next month or current quarter or next quarter time

Options contracts: BTC-USD-210326-2000-C bullish options, BTC-USD-210326-2000-P put options

How to set stop loss and take profit?

If the order is attached to take profit stop loss, you can refer to the order interface here.: attachAlgoOrds array parameters.

However, if it's a separate order stop loss, you can refer to the strategy commission interface here.

Why is an error reported when setting the trigger price for take profit and stop loss: 51046, 51047, 51048, 51049?

Rules for setting stop-loss trigger price/take-profit trigger price – during selling, the take-profit trigger price is greater than the latest transaction price, and the stop-loss trigger price is less than the latest transaction price; while during buying, the take-profit trigger price is less than the latest transaction price, and the stop-loss trigger price is greater than the latest transaction price.

What's "Interface error: 50102 Timestamp request expired"?

This error occurs when the timestamp has expired. You need to call the system time interface here to synchronize your local time with our server's time. Keeping the time difference within 30 seconds can help avoid this issue.

Note: the time in the request header time is in UTC0. When calling the server time interface, the time is provided in UTC + 8.

What's "Interface error: 50101 APIKey does not match the current environment"?

This is due to the mismatch between the APIKey and the current environment. Real account calls require the use of the real account APIKey, and the value of the x-simulated-trading parameter in the request header needs to be 0. Simulated account calls require the use of the simulated account APIKey, and the value of the x-simulated-trading parameter in the request header needs to be 1.

What's "Interface error: 51010 Request unsupported under current account mode"?

This is related to your account mode. If you want to place a single currency leverage or contract, you need to adjust to the other three modes except for spot mode! You can set it through the interface settings here, or you can set it on the web or app.

Note: the first setting must be set on the page or app; settings option on the main menu of the trading page - Account mode.

What's "Interface error: 51121 Order quantity must be a multiple of the lot size"?

In the API, contract orders are in units of sheets and must be a multiple of the minimum order quantity of the currency pair. The minimum order quantity can be obtained through the minSz field of the product interface here.

"Withdrawal error: 58207 Withdrawal address is not whitelisted for verification exemption"; why does the allowlist verification still report an error when it is closed on the withdrawal page?

To withdraw coins using the API interface, it's necessary to add a withdrawal address on the page and check the non verified by visa button. Whether the allowlist verification is turned off on the page will not affect the interface function.

What's "Interface error: 50004 API endpoint request timeout" (doesn't mean that the request was successful or failed, please check the request result)?

50004 is usually caused by excessive server pressure. 8, 16, and 24 am are the time points for collecting capital fees every day. At this time, the server pressure is high. It's recommended to stagger transactions at these times. If an error of 50004 is reported at other times, it can be retried later. If an order is placed with an error of 50004, it doesn't represent the actual result of the interface request. The request may succeed or fail. Please refer to the actual result.

Note: if you have any other questions or other API-related inquiries, you can reach out to us by scanning the code below via the app.

okxapi-app-1