> For clean Markdown of any page, append .md to the page URL. > For a complete documentation index, see https://okx-demo.ferndocs.com/api/api-reference/trade/get-algo-history/llms.txt. > For AI client integration (Claude Code, Cursor, etc.), connect to the MCP server at https://okx-demo.ferndocs.com/_mcp/server. # Get algo order history GET https://www.okx.com/api/v5/trade/orders-algo-history Retrieve a list of all algo orders under the current account in the last 3 months. Reference: https://okx-demo.ferndocs.com/api/api-reference/trade/get-algo-history ## Authentication - `OK-ACCESS-KEY` header (required) — Your API key. - `OK-ACCESS-SIGN` header (required) — Base64-encoded HMAC-SHA256 signature of the prehash string. - `OK-ACCESS-TIMESTAMP` header (required) — ISO 8601 UTC timestamp, e.g. 2020-12-08T09:08:57.715Z. - `OK-ACCESS-PASSPHRASE` header (required) — The passphrase you set when creating the API key. ## Request ### Query parameters - `ordType` (enum, required) — 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 `iceberg`: Iceberg order `twap`: TWAP order `smart_iceberg`: Iceberg order For every request, unlike other ordType which only can use one type, `conditional` and `oco` both can be used and separated with comma. - Allowed values: `conditional`, `oco`, `trigger`, `move_order_stop`, `iceberg`, `twap`, `chase` - `state` (enum, optional) — State `effective` `canceled` `order_failed` Either `state` or `algoId` is required - Allowed values: `effective`, `canceled`, `order_failed` - `algoId` (string, optional) — Algo ID Either `state` or `algoId` is required. - `instType` (enum, optional) — Instrument type `SPOT` `SWAP` `FUTURES` `MARGIN` - Allowed values: `SPOT`, `MARGIN`, `SWAP`, `FUTURES` - `instId` (string, optional) — Instrument ID, e.g. `BTC-USDT` - `after` (string, optional) — Pagination of data to return records earlier than the requested `algoId` - `before` (string, optional) — Pagination of data to return records new than the requested `algoId` - `limit` (string, optional) — Number of results per request. The maximum is `100`. The default is `100` ## Response ### 200 Successful response - `code` (string, optional) — Result code. `0` means success; any other value is an error code. - `msg` (string, optional) — Error message. Empty on success. - `data` (list of ApiV5TradeOrdersAlgoHistoryGetResponsesContentApplicationJsonSchemaDataItems, optional) ## Types ### ApiV5TradeOrdersAlgoHistoryGetResponsesContentApplicationJsonSchemaDataItems - `algoId` (string, optional) — Algo ID - `algoClOrdId` (string, optional) — Client Algo Order ID as assigned by the client. - `instType` (string, optional) — Instrument type - `instId` (string, optional) — Instrument ID - `ordType` (string, optional) — Order type - `side` (string, optional) — Order side - `sz` (string, optional) — Quantity to buy or sell - `state` (string, optional) — State `effective` `canceled` `order_failed` `partially_failed` - `triggerPx` (string, optional) — trigger price. - `triggerTime` (string, optional) — Trigger time, Unix timestamp format in milliseconds, e.g. `1597026383085` - `ordId` (string, optional) — Latest order ID. It will be deprecated soon - `failCode` (string, optional) — It represents that the reason that algo order fails to trigger. It is "" when the state is `effective`/`canceled`. There will be value when the state is `order_failed`, e.g. 51008; Only applicable to Stop Order, Trailing Stop Order, Trigger order. - `cTime` (string, optional) — Creation time Unix timestamp format in milliseconds, e.g. `1597026383085` ## Examples **Response** ```json { "code": "0", "msg": "", "data": [ { "algoId": "1880721064716505088", "algoClOrdId": "", "instType": "SWAP", "instId": "BTC-USDT-SWAP", "ordType": "oco", "side": "sell", "sz": "100", "state": "effective", "triggerPx": "", "triggerTime": "1728673513447", "ordId": "1884789786215137280", "failCode": "1", "cTime": "1728552255493", "activePx": "", "actualPx": "", "actualSide": "tp", "actualSz": "100", "amendPxOnTriggerType": "0", "attachAlgoOrds": [], "callbackRatio": "", "callbackSpread": "", "ccy": "", "chaseType": "", "chaseVal": "", "clOrdId": "", "closeFraction": "1", "isTradeBorrowMode": "", "last": "60777.5", "lever": "10", "linkedOrd": { "ordId": "" }, "maxChaseType": "", "maxChaseVal": "", "moveTriggerPx": "", "ordIdList": [ "1884789786215137280" ], "ordPx": "", "posSide": "long", "pxLimit": "", "pxSpread": "", "pxVar": "", "quickMgnType": "", "reduceOnly": "true", "slOrdPx": "-1", "slTriggerPx": "57000", "slTriggerPxType": "mark", "szLimit": "", "tag": "", "tdMode": "isolated", "tgtCcy": "", "timeInterval": "", "tpOrdPx": "-1", "tpTriggerPx": "63000", "tpTriggerPxType": "last", "tradeQuoteCcy": "USDT", "triggerPxType": "", "uTime": "1728673513447" } ] } ``` **SDK Code** ```python trade_getAlgoHistory_example import requests url = "https://www.okx.com/api/v5/trade/orders-algo-history" querystring = {"ordType":"conditional"} headers = {"OK-ACCESS-KEY": ""} response = requests.get(url, headers=headers, params=querystring) print(response.json()) ``` ```javascript trade_getAlgoHistory_example const url = 'https://www.okx.com/api/v5/trade/orders-algo-history?ordType=conditional'; const options = {method: 'GET', headers: {'OK-ACCESS-KEY': ''}}; try { const response = await fetch(url, options); const data = await response.json(); console.log(data); } catch (error) { console.error(error); } ``` ```go trade_getAlgoHistory_example package main import ( "fmt" "net/http" "io" ) func main() { url := "https://www.okx.com/api/v5/trade/orders-algo-history?ordType=conditional" req, _ := http.NewRequest("GET", url, nil) req.Header.Add("OK-ACCESS-KEY", "") res, _ := http.DefaultClient.Do(req) defer res.Body.Close() body, _ := io.ReadAll(res.Body) fmt.Println(res) fmt.Println(string(body)) } ``` ```ruby trade_getAlgoHistory_example require 'uri' require 'net/http' url = URI("https://www.okx.com/api/v5/trade/orders-algo-history?ordType=conditional") http = Net::HTTP.new(url.host, url.port) http.use_ssl = true request = Net::HTTP::Get.new(url) request["OK-ACCESS-KEY"] = '' response = http.request(request) puts response.read_body ``` ```java trade_getAlgoHistory_example import com.mashape.unirest.http.HttpResponse; import com.mashape.unirest.http.Unirest; HttpResponse response = Unirest.get("https://www.okx.com/api/v5/trade/orders-algo-history?ordType=conditional") .header("OK-ACCESS-KEY", "") .asString(); ``` ```php trade_getAlgoHistory_example request('GET', 'https://www.okx.com/api/v5/trade/orders-algo-history?ordType=conditional', [ 'headers' => [ 'OK-ACCESS-KEY' => '', ], ]); echo $response->getBody(); ``` ```csharp trade_getAlgoHistory_example using RestSharp; var client = new RestClient("https://www.okx.com/api/v5/trade/orders-algo-history?ordType=conditional"); var request = new RestRequest(Method.GET); request.AddHeader("OK-ACCESS-KEY", ""); IRestResponse response = client.Execute(request); ``` ```swift trade_getAlgoHistory_example import Foundation let headers = ["OK-ACCESS-KEY": ""] let request = NSMutableURLRequest(url: NSURL(string: "https://www.okx.com/api/v5/trade/orders-algo-history?ordType=conditional")! as URL, cachePolicy: .useProtocolCachePolicy, timeoutInterval: 10.0) request.httpMethod = "GET" request.allHTTPHeaderFields = headers let session = URLSession.shared let dataTask = session.dataTask(with: request as URLRequest, completionHandler: { (data, response, error) -> Void in if (error != nil) { print(error as Any) } else { let httpResponse = response as? HTTPURLResponse print(httpResponse) } }) dataTask.resume() ```