> This page is for API Reference.

> For clean Markdown of any page, append .md to the page URL.
> For a complete documentation index, see https://okx-demo.ferndocs.com/llms.txt.
> For AI client integration (Claude Code, Cursor, etc.), connect to the MCP server at https://okx-demo.ferndocs.com/_mcp/server.

# Existing leading positions

GET https://www.okx.com/api/v5/copytrading/current-subpositions

Retrieve lead positions that are not closed.

Returns reverse chronological order with `openTime`

Reference: https://okx-demo.ferndocs.com/api/api-reference/copy-trading/get-existing-leading-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

- `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
- `uniqueCode` (string, optional) — Lead trader unique code. If left blank, the current lead trader's positions are returned.
- `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 500. Default is 500.

## 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 ApiV5CopytradingCurrentSubpositionsGetResponsesContentApplicationJsonSchemaDataItems, optional)

## Types

### ApiV5CopytradingCurrentSubpositionsGetResponsesContentApplicationJsonSchemaDataItems

- `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) — Margin currency
- `posSide` (string, optional) — Position side `long` `short` `net` (Long positions have positive subPos; short positions have negative subPos)
- `mgnMode` (string, optional) — Margin mode. `cross` `isolated`
- `lever` (string, optional) — Leverage
- `openAvgPx` (string, optional) — Average open price
- `openTime` (string, optional) — Open time
- `openOrdId` (string, optional) — Order ID for opening position, only applicable to lead position
- `subPos` (string, optional) — Quantity of positions
- `availSubPos` (string, optional) — Quantity of positions that can be closed
- `margin` (string, optional) — Margin
- `markPx` (string, optional) — Latest mark price, only applicable to contract
- `upl` (string, optional) — Unrealized profit and loss
- `uplRatio` (string, optional) — Unrealized profit and loss ratio
- `algoId` (string, optional) — Stop order ID
- `tpTriggerPx` (string, optional) — Take-profit trigger price.
- `tpOrdPx` (string, optional) — Take-profit order price, it is -1 for market price
- `slTriggerPx` (string, optional) — Stop-loss trigger price.
- `slOrdPx` (string, optional) — Stop-loss order price, it is -1 for market price

## Examples

**Response**

```json
{
  "code": "0",
  "msg": "",
  "data": [
    {
      "subPosId": "649945658862370816",
      "uniqueCode": "25CD5A80241D6FE6",
      "instType": "SWAP",
      "instId": "BTC-USDT-SWAP",
      "ccy": "USDT",
      "posSide": "net",
      "mgnMode": "isolated",
      "lever": "3",
      "openAvgPx": "37925.1",
      "openTime": "1701231120479",
      "openOrdId": "",
      "subPos": "1",
      "availSubPos": "1",
      "margin": "12.6417",
      "markPx": "38205.8",
      "upl": "0.2807",
      "uplRatio": "0.0222042921442527",
      "algoId": "",
      "tpTriggerPx": "",
      "tpOrdPx": "",
      "slTriggerPx": "",
      "slOrdPx": ""
    },
    {
      "subPosId": "649920301388038144",
      "uniqueCode": "25CD5A80241D6FE6",
      "instType": "SWAP",
      "instId": "BTC-USDT-SWAP",
      "ccy": "USDT",
      "posSide": "net",
      "mgnMode": "isolated",
      "lever": "3",
      "openAvgPx": "37879",
      "openTime": "1701225074786",
      "openOrdId": "",
      "subPos": "1",
      "availSubPos": "1",
      "margin": "12.6263333333333333",
      "markPx": "38205.8",
      "upl": "0.3268",
      "uplRatio": "0.0258824150584758",
      "algoId": "",
      "tpTriggerPx": "",
      "tpOrdPx": "",
      "slTriggerPx": "",
      "slOrdPx": ""
    }
  ]
}
```

**SDK Code**

```python copyTrading_getExistingLeadingPositions_example
import requests

url = "https://www.okx.com/api/v5/copytrading/current-subpositions"

headers = {"OK-ACCESS-KEY": "<apiKey>"}

response = requests.get(url, headers=headers)

print(response.json())
```

```javascript copyTrading_getExistingLeadingPositions_example
const url = 'https://www.okx.com/api/v5/copytrading/current-subpositions';
const options = {method: 'GET', headers: {'OK-ACCESS-KEY': '<apiKey>'}};

try {
  const response = await fetch(url, options);
  const data = await response.json();
  console.log(data);
} catch (error) {
  console.error(error);
}
```

```go copyTrading_getExistingLeadingPositions_example
package main

import (
	"fmt"
	"net/http"
	"io"
)

func main() {

	url := "https://www.okx.com/api/v5/copytrading/current-subpositions"

	req, _ := http.NewRequest("GET", url, nil)

	req.Header.Add("OK-ACCESS-KEY", "<apiKey>")

	res, _ := http.DefaultClient.Do(req)

	defer res.Body.Close()
	body, _ := io.ReadAll(res.Body)

	fmt.Println(res)
	fmt.Println(string(body))

}
```

```ruby copyTrading_getExistingLeadingPositions_example
require 'uri'
require 'net/http'

url = URI("https://www.okx.com/api/v5/copytrading/current-subpositions")

http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true

request = Net::HTTP::Get.new(url)
request["OK-ACCESS-KEY"] = '<apiKey>'

response = http.request(request)
puts response.read_body
```

```java copyTrading_getExistingLeadingPositions_example
import com.mashape.unirest.http.HttpResponse;
import com.mashape.unirest.http.Unirest;

HttpResponse<String> response = Unirest.get("https://www.okx.com/api/v5/copytrading/current-subpositions")
  .header("OK-ACCESS-KEY", "<apiKey>")
  .asString();
```

```php copyTrading_getExistingLeadingPositions_example
<?php
require_once('vendor/autoload.php');

$client = new \GuzzleHttp\Client();

$response = $client->request('GET', 'https://www.okx.com/api/v5/copytrading/current-subpositions', [
  'headers' => [
    'OK-ACCESS-KEY' => '<apiKey>',
  ],
]);

echo $response->getBody();
```

```csharp copyTrading_getExistingLeadingPositions_example
using RestSharp;

var client = new RestClient("https://www.okx.com/api/v5/copytrading/current-subpositions");
var request = new RestRequest(Method.GET);
request.AddHeader("OK-ACCESS-KEY", "<apiKey>");
IRestResponse response = client.Execute(request);
```

```swift copyTrading_getExistingLeadingPositions_example
import Foundation

let headers = ["OK-ACCESS-KEY": "<apiKey>"]

let request = NSMutableURLRequest(url: NSURL(string: "https://www.okx.com/api/v5/copytrading/current-subpositions")! 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()
```