> 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-positions/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 positions GET https://www.okx.com/api/v5/tradingBot/grid/positions Retrieve the open positions held by a contract grid algo order. Reference: https://okx-demo.ferndocs.com/api/api-reference/grid-trading/get-grid-positions ## 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 `contract_grid`: Contract grid - Allowed values: `contract_grid` - `algoId` (string, required) — Algo ID ## 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 ApiV5TradingBotGridPositionsGetResponsesContentApplicationJsonSchemaDataItems, optional) ## Types ### ApiV5TradingBotGridPositionsGetResponsesContentApplicationJsonSchemaDataItems - `algoId` (string, optional) — Algo ID - `instType` (string, optional) — Instrument type - `instId` (string, optional) — Instrument ID, e.g. `BTC-USDT-SWAP` - `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` - `posSide` (string, optional) — Position side `net` - `pos` (string, optional) — Quantity of positions - `mgnMode` (string, optional) — Margin mode `cross` `isolated` - `avgPx` (string, optional) — Average open price - `liqPx` (string, optional) — Estimated liquidation price - `markPx` (string, optional) — Mark price - `imr` (string, optional) — Initial margin requirement - `mmr` (string, optional) — Maintenance margin requirement - `upl` (string, optional) — Unrealized profit and loss - `uplRatio` (string, optional) — Unrealized profit and loss ratio - `lever` (string, optional) — Leverage - `notionalUsd` (string, optional) — Notional value of positions in `USD` - `adl` (string, optional) — Automatic-Deleveraging, signal area Divided into 5 levels, from 1 to 5, the smaller the number, the weaker the adl intensity. - `last` (string, optional) — Latest traded price ## Examples **Response** ```json { "code": "0", "msg": "", "data": [ { "algoId": "449327675342323712", "instType": "SWAP", "instId": "BTC-USDT-SWAP", "cTime": "1653400065917", "uTime": "1653400066938", "posSide": "net", "pos": "35", "mgnMode": "cross", "avgPx": "29215.0142857142857149", "liqPx": "661.1684795867162", "markPx": "29213.9", "imr": "2045.386", "mmr": "40.907720000000005", "upl": "1.674999999999818", "uplRatio": "0.0008190504784478", "lever": "5", "notionalUsd": "10216.70307", "adl": "1", "last": "29206.7", "algoClOrdId": "", "ccy": "USDT", "mgnRatio": "217.19370606167573" } ] } ``` **SDK Code** ```python gridTrading_getGridPositions_example import requests url = "https://www.okx.com/api/v5/tradingBot/grid/positions" querystring = {"algoId":"448965992920907776","algoOrdType":"contract_grid"} headers = {"OK-ACCESS-KEY": ""} response = requests.get(url, headers=headers, params=querystring) print(response.json()) ``` ```javascript gridTrading_getGridPositions_example const url = 'https://www.okx.com/api/v5/tradingBot/grid/positions?algoId=448965992920907776&algoOrdType=contract_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_getGridPositions_example package main import ( "fmt" "net/http" "io" ) func main() { url := "https://www.okx.com/api/v5/tradingBot/grid/positions?algoId=448965992920907776&algoOrdType=contract_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_getGridPositions_example require 'uri' require 'net/http' url = URI("https://www.okx.com/api/v5/tradingBot/grid/positions?algoId=448965992920907776&algoOrdType=contract_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_getGridPositions_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/positions?algoId=448965992920907776&algoOrdType=contract_grid") .header("OK-ACCESS-KEY", "") .asString(); ``` ```php gridTrading_getGridPositions_example request('GET', 'https://www.okx.com/api/v5/tradingBot/grid/positions?algoId=448965992920907776&algoOrdType=contract_grid', [ 'headers' => [ 'OK-ACCESS-KEY' => '', ], ]); echo $response->getBody(); ``` ```csharp gridTrading_getGridPositions_example using RestSharp; var client = new RestClient("https://www.okx.com/api/v5/tradingBot/grid/positions?algoId=448965992920907776&algoOrdType=contract_grid"); var request = new RestRequest(Method.GET); request.AddHeader("OK-ACCESS-KEY", ""); IRestResponse response = client.Execute(request); ``` ```swift gridTrading_getGridPositions_example import Foundation let headers = ["OK-ACCESS-KEY": ""] let request = NSMutableURLRequest(url: NSURL(string: "https://www.okx.com/api/v5/tradingBot/grid/positions?algoId=448965992920907776&algoOrdType=contract_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() ```