> 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/grid-trading/get-grid-orders-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 grid orders history GET https://www.okx.com/api/v5/tradingBot/grid/orders-algo-history Retrieve a list of stopped grid algo orders from the last three months. Reference: https://okx-demo.ferndocs.com/api/api-reference/grid-trading/get-grid-orders-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 - `algoOrdType` (enum, required) — Algo order type `grid`: Spot grid `contract_grid`: Contract grid - Allowed values: `grid`, `contract_grid`, `moon_grid` - `algoId` (string, optional) — Algo ID - `instId` (string, optional) — Instrument ID, e.g. `BTC-USDT` - `instType` (enum, optional) — Instrument type `SPOT` `MARGIN` `FUTURES` `SWAP` - Allowed values: `SPOT`, `MARGIN`, `SWAP`, `FUTURES` - `instFamily` (string, optional) — Instrument family, applicable to contract grid. - `after` (string, optional) — Pagination of data to return records earlier than the requested `algoId`. - `before` (string, optional) — Pagination of data to return records newer 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 ApiV5TradingBotGridOrdersAlgoHistoryGetResponsesContentApplicationJsonSchemaDataItems, optional) ## Types ### ApiV5TradingBotGridOrdersAlgoHistoryGetResponsesContentApplicationJsonSchemaDataItems - `algoId` (string, optional) — Algo ID - `algoClOrdId` (string, optional) — Client-supplied Algo ID - `instType` (string, optional) — Instrument type - `instId` (string, optional) — Instrument ID - `cTime` (string, optional) — Algo order created time, Unix timestamp format in milliseconds, e.g. `1597026383085` - `uTime` (string, optional) — Algo order updated time, Unix timestamp format in milliseconds, e.g. `1597026383085` - `algoOrdType` (string, optional) — Algo order type `grid`: Spot grid `contract_grid`: Contract grid - `state` (string, optional) — Algo order state `stopped` - `maxPx` (string, optional) — Upper price of price range - `minPx` (string, optional) — Lower price of price range - `gridNum` (string, optional) — Grid quantity - `runType` (string, optional) — Grid type `1`: Arithmetic, `2`: Geometric - `investment` (string, optional) — Accumulated investment amount Spot grid investment amount calculated on quote currency - `totalPnl` (string, optional) — Total P&L - `pnlRatio` (string, optional) — P&L ratio - `gridProfit` (string, optional) — Grid profit ## Examples **Response** ```json { "code": "0", "msg": "", "data": [ { "algoId": "565849588675117056", "algoClOrdId": "", "instType": "SPOT", "instId": "BTC-USDT", "cTime": "1681181054927", "uTime": "1681181186496", "algoOrdType": "grid", "state": "stopped", "maxPx": "5000", "minPx": "400", "gridNum": "10", "runType": "1", "investment": "25", "totalPnl": "0", "pnlRatio": "0", "gridProfit": "0", "actualLever": "", "arbitrageNum": "0", "availEq": "", "basePos": false, "baseSz": "0", "cancelType": "1", "copyType": "0", "direction": "", "fee": "", "feeCcy": "", "floatProfit": "0", "fundingFee": "", "instFamily": "", "lever": "0", "liqPx": "", "ordFrozen": "", "profitSharingRatio": "", "quoteSz": "25", "rebateTrans": [ { "rebate": "0", "rebateCcy": "BTC" }, { "rebate": "0", "rebateCcy": "USDT" } ], "slTriggerPx": "0", "stopResult": "0", "stopType": "1", "sz": "", "tag": "", "tpTriggerPx": "0", "tradeQuoteCcy": "USDT", "triggerParams": [ { "delaySeconds": "0", "triggerAction": "start", "triggerStrategy": "instant", "triggerTime": "", "triggerType": "auto" }, { "delaySeconds": "0", "stopType": "1", "triggerAction": "stop", "triggerPx": "1000", "triggerStrategy": "instant", "triggerTime": "1681181186484", "triggerType": "manual" } ], "uly": "BTC-USDT" } ] } ``` **SDK Code** ```python gridTrading_getGridOrdersHistory_example import requests url = "https://www.okx.com/api/v5/tradingBot/grid/orders-algo-history" querystring = {"algoOrdType":"grid"} headers = {"OK-ACCESS-KEY": ""} response = requests.get(url, headers=headers, params=querystring) print(response.json()) ``` ```javascript gridTrading_getGridOrdersHistory_example const url = 'https://www.okx.com/api/v5/tradingBot/grid/orders-algo-history?algoOrdType=grid'; 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 gridTrading_getGridOrdersHistory_example package main import ( "fmt" "net/http" "io" ) func main() { url := "https://www.okx.com/api/v5/tradingBot/grid/orders-algo-history?algoOrdType=grid" 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 gridTrading_getGridOrdersHistory_example require 'uri' require 'net/http' url = URI("https://www.okx.com/api/v5/tradingBot/grid/orders-algo-history?algoOrdType=grid") 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 gridTrading_getGridOrdersHistory_example import com.mashape.unirest.http.HttpResponse; import com.mashape.unirest.http.Unirest; HttpResponse response = Unirest.get("https://www.okx.com/api/v5/tradingBot/grid/orders-algo-history?algoOrdType=grid") .header("OK-ACCESS-KEY", "") .asString(); ``` ```php gridTrading_getGridOrdersHistory_example request('GET', 'https://www.okx.com/api/v5/tradingBot/grid/orders-algo-history?algoOrdType=grid', [ 'headers' => [ 'OK-ACCESS-KEY' => '', ], ]); echo $response->getBody(); ``` ```csharp gridTrading_getGridOrdersHistory_example using RestSharp; var client = new RestClient("https://www.okx.com/api/v5/tradingBot/grid/orders-algo-history?algoOrdType=grid"); var request = new RestRequest(Method.GET); request.AddHeader("OK-ACCESS-KEY", ""); IRestResponse response = client.Execute(request); ``` ```swift gridTrading_getGridOrdersHistory_example import Foundation let headers = ["OK-ACCESS-KEY": ""] let request = NSMutableURLRequest(url: NSURL(string: "https://www.okx.com/api/v5/tradingBot/grid/orders-algo-history?algoOrdType=grid")! 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() ```