Skip to navigation

Place algo order

The algo order includes trigger order, oco order, chase order, conditional order, twap order and trailing order.

Authentication

OK-ACCESS-KEYstring
Your API key.
OK-ACCESS-SIGNstring

Base64-encoded HMAC-SHA256 signature of the prehash string.

OK-ACCESS-TIMESTAMPstring

ISO 8601 UTC timestamp, e.g. 2020-12-08T09:08:57.715Z.

OK-ACCESS-PASSPHRASEstring
The passphrase you set when creating the API key.

Request

This endpoint expects an object.
instIdstringRequired

Instrument ID, e.g. BTC-USDT

tdModeenumRequired

Trade mode Margin mode cross isolated Non-Margin mode cash spot_isolated (only applicable to SPOT lead trading) Note: isolated is not available in multi-currency margin mode and portfolio margin mode.

Allowed values:
sideenumRequired

Order side, buy sell

Allowed values:
ordTypeenumRequired

Order type conditional: One-way stop order oco: One-cancels-the-other order chase: chase order, only applicable to FUTURES and SWAP trigger: Trigger order move_order_stop: Trailing order twap: TWAP order smart_iceberg: Iceberg order

szstringRequired

Quantity to buy or sell Either sz or closeFraction is required.

ccystringOptional

Margin currency Applicable to all isolated MARGIN orders and cross MARGIN orders in Futures mode.

posSideenumOptional

Position side Required in long/short mode and only be long or short

Allowed values:
algoClOrdIdstringOptional

Client-supplied Algo ID A combination of case-sensitive alphanumerics, all numbers, or all letters of up to 32 characters.

tagstringOptional

Order tag A combination of case-sensitive alphanumerics, all numbers, or all letters of up to 16 characters.

reduceOnlybooleanOptional

Whether the order can only reduce the position size. Valid options: true or false. The default value is false. This parameter is only valid in the FUTRUES/SWAP net mode, and is ignored in the long/short mode.

tgtCcystringOptional

Order quantity unit setting for sz base_ccy: Base currency ,quote_ccy: Quote currency Only applicable to SPOT traded with Market buy conditional order Default is quote_ccy for buy, base_ccy for sell

tpTriggerPxstringOptional

Take-profit trigger price If you fill in this parameter, you should fill in the take-profit order price as well.

tpTriggerPxTypeenumOptional

Take-profit trigger price type last: last price index: index price mark: mark price The default is last

Allowed values:
tpOrdPxstringOptional

Take-profit order price For condition TP order, if you fill in this parameter, you should fill in the take-profit trigger price as well. For limit TP order, you need to fill in this parameter, but the take-profit trigger price doesn’t need to be filled. If the price is -1, take-profit will be executed at the market price.

slTriggerPxstringOptional

Stop-loss trigger price If you fill in this parameter, you should fill in the stop-loss order price.

slTriggerPxTypeenumOptional

Stop-loss trigger price type last: last price index: index price mark: mark price The default is last

Allowed values:
slOrdPxstringOptional

Stop-loss order price If you fill in this parameter, you should fill in the stop-loss trigger price. If the price is -1, stop-loss will be executed at the market price.

triggerPxstringOptional

The price level that activates this algo order. Unit: same as px for the instrument. Which price feed is compared depends on triggerPxType (default: last trade price). Direction: for a sell stop-loss, trigger must be below orderPx; for a buy stop, above orderPx. Error codes 51046–51049 are returned for direction violations.

triggerPxTypeenumOptional

Trigger price type: last: triggers when any trade occurs at or beyond triggerPx — most responsive but vulnerable to brief price wicks in thin markets. index: triggers on the underlying multi-exchange composite index — stable, not affected by OKX-specific wicks. mark: triggers on OKX mark price — smoothed and wick-resistant; recommended for derivatives. last is the only option available for SPOT instruments. The default is last.

Allowed values:
orderPxstringOptional

Price of the order submitted when triggerPx is reached. This is separate from triggerPx (which determines when the algo activates). Set to -1 to submit a market order when triggered; set to a specific price to submit a limit order. Not applicable when advanceOrdType is chase (a chase has no fixed price).

callbackRatiostringOptional

Callback price ratio, e.g. 0.01 represents 1% Either callbackRatio or callbackSpread is allowed to be passed.

callbackSpreadstringOptional
Callback price variance
activePxstringOptional

Active price The system will only start tracking the market and calculating your trigger price after the activation price is reached. If you don’t set a price, your order will be activated as soon as it’s placed.

pxVarstringOptional

Price variance by percentage, range between [0.0001 ~ 0.01], e.g. 0.01 represents 1% Take buy orders as an example. When the market price is lower than the limit price, small buy orders will be placed above the best bid price within a certain range. This parameter determines the range by percentage. Either pxVar or pxSpread is allowed to be passed.

pxSpreadstringOptional

Price variance by constant, should be no less then 0 (no upper limit) Take buy orders as an example. When the market price is lower than the limit price, small buy orders will be placed above the best bid price within a certain range. This parameter determines the range by constant.

szLimitstringOptional

Minimum order size per execution. Only applicable to smart_iceberg

pxLimitstringOptional

Price limit. Only applicable to smart_iceberg

timeIntervalstringOptional

Time interval in unit of second ake buy orders as an example. When the market price is lower than the limit price, small buy orders will be placed above the best bid price within a certain range based on the time cycle. This parameter represents the time cycle.

Response

Successful response
codestringOptional

Result code. 0 means success; any other value is an error code.

msgstringOptional
Error message. Empty on success.
datalist of objectsOptional