> 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/copy-trading/get-leading-position-history/llms.txt. > For AI client integration (Claude Code, Cursor, etc.), connect to the MCP server at https://okx-demo.ferndocs.com/_mcp/server. # Leading position history GET https://www.okx.com/api/v5/copytrading/subpositions-history Retrieve the completed lead position of the last 3 months. Returns reverse chronological order with `subPosId`. Reference: https://okx-demo.ferndocs.com/api/api-reference/copy-trading/get-leading-position-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 - `instType` (enum, optional) — Instrument type `SPOT` `SWAP` It returns all types by default. - Allowed values: `SPOT`, `SWAP` - `instId` (string, optional) — Instrument ID, e.g. BTC-USDT-SWAP - `subPosType` (enum, optional) — Sub position type. lead: lead trade; copy: copy trade. Default is lead. - Allowed values: `lead`, `copy` - `after` (string, optional) — Pagination of data to return records earlier than the requested `subPosId`. - `before` (string, optional) — Pagination of data to return records newer than the requested `subPosId`. - `limit` (string, optional) — Number of results per request. Maximum is 100. 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 ApiV5CopytradingSubpositionsHistoryGetResponsesContentApplicationJsonSchemaDataItems, optional) ## Types ### ApiV5CopytradingSubpositionsHistoryGetResponsesContentApplicationJsonSchemaDataItems - `subPosId` (string, optional) — Lead position ID - `uniqueCode` (string, optional) — Lead trader unique code - `instType` (string, optional) — Instrument type - `instId` (string, optional) — Instrument ID, e.g. BTC-USDT-SWAP - `ccy` (string, optional) — Currency - `posSide` (string, optional) — Position side `long` `short` `net` (long position has positive subPos; short position has negative subPos) - `mgnMode` (string, optional) — Margin mode. `cross` `isolated` - `lever` (string, optional) — Leverage - `margin` (string, optional) — Margin - `markPx` (string, optional) — Latest mark price, only applicable to contract - `openAvgPx` (string, optional) — Average open price - `openTime` (string, optional) — Time of opening - `openOrdId` (string, optional) — Order ID for opening position, only applicable to lead position - `closeAvgPx` (string, optional) — Average price of closing position - `closeTime` (string, optional) — Time of closing position - `subPos` (string, optional) — Quantity of positions - `closeSubPos` (string, optional) — Quantity of positions that is already closed - `pnl` (string, optional) — Profit and loss - `pnlRatio` (string, optional) — P&L ratio - `profitSharingAmt` (string, optional) — Profit sharing amount, only applicable to copy trading. Note: this parameter is already deprecated. - `type` (string, optional) — The type of closing position `1`:Close position partially; `2`:Close all ## Examples **Response** ```json { "code": "0", "msg": "", "data": [ { "subPosId": "649750700213698561", "uniqueCode": "25CD5A80241D6FE6", "instType": "SWAP", "instId": "BTC-USDT-SWAP", "ccy": "USDT", "posSide": "net", "mgnMode": "isolated", "lever": "3", "margin": "37.41", "markPx": "38203.4", "openAvgPx": "37410", "openTime": "1701184638702", "openOrdId": "", "closeAvgPx": "37617.5", "closeTime": "1701188587950", "subPos": "3", "closeSubPos": "2", "pnl": "0.6225", "pnlRatio": "0.0166399358460306", "profitSharingAmt": "0.0407967", "type": "1" }, { "subPosId": "649750686292803585", "uniqueCode": "25CD5A80241D6FE6", "instType": "SWAP", "instId": "BTC-USDT-SWAP", "ccy": "USDT", "posSide": "net", "mgnMode": "isolated", "lever": "3", "margin": "24.94", "markPx": "38203.4", "openAvgPx": "37410", "openTime": "1701184635381", "openOrdId": "", "closeAvgPx": "37617.5", "closeTime": "1701188587950", "subPos": "2", "closeSubPos": "2", "pnl": "0.415", "pnlRatio": "0.0166399358460306", "profitSharingAmt": "0.0271978", "type": "2" } ] } ``` **SDK Code** ```python copyTrading_getLeadingPositionHistory_example import requests url = "https://www.okx.com/api/v5/copytrading/subpositions-history" headers = {"OK-ACCESS-KEY": ""} response = requests.get(url, headers=headers) print(response.json()) ``` ```javascript copyTrading_getLeadingPositionHistory_example const url = 'https://www.okx.com/api/v5/copytrading/subpositions-history'; 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 copyTrading_getLeadingPositionHistory_example package main import ( "fmt" "net/http" "io" ) func main() { url := "https://www.okx.com/api/v5/copytrading/subpositions-history" 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 copyTrading_getLeadingPositionHistory_example require 'uri' require 'net/http' url = URI("https://www.okx.com/api/v5/copytrading/subpositions-history") 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 copyTrading_getLeadingPositionHistory_example import com.mashape.unirest.http.HttpResponse; import com.mashape.unirest.http.Unirest; HttpResponse response = Unirest.get("https://www.okx.com/api/v5/copytrading/subpositions-history") .header("OK-ACCESS-KEY", "") .asString(); ``` ```php copyTrading_getLeadingPositionHistory_example request('GET', 'https://www.okx.com/api/v5/copytrading/subpositions-history', [ 'headers' => [ 'OK-ACCESS-KEY' => '', ], ]); echo $response->getBody(); ``` ```csharp copyTrading_getLeadingPositionHistory_example using RestSharp; var client = new RestClient("https://www.okx.com/api/v5/copytrading/subpositions-history"); var request = new RestRequest(Method.GET); request.AddHeader("OK-ACCESS-KEY", ""); IRestResponse response = client.Execute(request); ``` ```swift copyTrading_getLeadingPositionHistory_example import Foundation let headers = ["OK-ACCESS-KEY": ""] let request = NSMutableURLRequest(url: NSURL(string: "https://www.okx.com/api/v5/copytrading/subpositions-history")! 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() ```