> 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.

# Get positions

GET https://www.okx.com/api/v5/account/positions

Retrieve information on your positions. When the account is in net mode, net positions are returned; in long/short mode, long or short positions are returned.

Reference: https://okx-demo.ferndocs.com/api/api-reference/account/get-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.
  - Allowed values: `MARGIN`, `SWAP`, `FUTURES`, `OPTION`
- `instId` (string, optional) — Instrument ID, e.g. BTC-USDT-SWAP. Multiple instrument IDs (no more than 10) separated with comma.
- `posId` (string, optional) — Single position ID or multiple position IDs (no more than 20) separated with comma.

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

## Types

### ApiV5AccountPositionsGetResponsesContentApplicationJsonSchemaDataItems

- `instType` (string, optional) — Instrument type.
- `instId` (string, optional) — Instrument ID.
- `mgnMode` (string, optional) — Margin mode.
- `posId` (string, optional) — Position ID.
- `posSide` (string, optional) — Position side.
- `pos` (string, optional) — Quantity of positions.
- `availPos` (string, optional) — Position that can be closed.
- `avgPx` (string, optional) — Average open price.
- `upl` (string, optional) — Unrealized profit and loss.
- `uplRatio` (string, optional) — Unrealized profit and loss ratio.
- `lever` (string, optional) — Leverage.
- `liqPx` (string, optional) — Estimated liquidation price.
- `markPx` (string, optional) — Latest mark price.
- `imr` (string, optional) — Initial margin requirement, only applicable to cross.
- `margin` (string, optional) — Margin, can be added or reduced, only applicable to isolated.
- `mgnRatio` (string, optional) — Margin ratio.
- `mmr` (string, optional) — Maintenance margin requirement.
- `liab` (string, optional) — Liabilities, only applicable to MARGIN.
- `liabCcy` (string, optional) — Liabilities currency, only applicable to MARGIN.
- `interest` (string, optional) — Interest accrued.
- `notionalUsd` (string, optional) — Notional value of positions in USD.
- `adl` (string, optional) — Auto-deleveraging indicator, 1-5, larger means higher probability.
- `ccy` (string, optional) — Currency used for margin.
- `last` (string, optional) — Latest traded price.
- `posCcy` (string, optional) — Position currency, only applicable to MARGIN.
- `deltaBS` (string, optional) — Delta (Black-Scholes), only applicable to OPTION.
- `gammaBS` (string, optional) — Gamma (Black-Scholes), only applicable to OPTION.
- `thetaBS` (string, optional) — Theta (Black-Scholes), only applicable to OPTION.
- `vegaBS` (string, optional) — Vega (Black-Scholes), only applicable to OPTION.
- `cTime` (string, optional) — Creation time, Unix timestamp in milliseconds.
- `uTime` (string, optional) — Latest update time, Unix timestamp in milliseconds.
- `tradeId` (string, optional) — Last trade ID.

## Examples

**Response**

```json
{
  "code": "0",
  "msg": "",
  "data": [
    {
      "instType": "MARGIN",
      "instId": "BTC-USDT",
      "mgnMode": "isolated",
      "posId": "1752810569801498626",
      "posSide": "net",
      "pos": "0.00190433573",
      "availPos": "0.00190433573",
      "avgPx": "62961.4",
      "upl": "-0.0000033452492717",
      "uplRatio": "-0.0105311101755551",
      "lever": "5",
      "liqPx": "53615.448336593756",
      "markPx": "62891.9",
      "imr": "",
      "margin": "0.000317654",
      "mgnRatio": "9.404143929947395",
      "mmr": "0.0000318005395854",
      "liab": "-99.9998177776581948",
      "liabCcy": "USDT",
      "interest": "0",
      "notionalUsd": "119.756628017499",
      "adl": "1",
      "ccy": "BTC",
      "last": "62892.9",
      "posCcy": "BTC",
      "deltaBS": "",
      "gammaBS": "",
      "thetaBS": "",
      "vegaBS": "",
      "cTime": "1724740225685",
      "uTime": "1724742632153",
      "tradeId": "785524470",
      "baseBal": "",
      "baseBorrowed": "",
      "baseInterest": "",
      "bePx": "",
      "bizRefId": "",
      "bizRefType": "",
      "clSpotInUseAmt": "",
      "closeOrderAlgo": [],
      "deltaPA": "",
      "fee": "",
      "fundingFee": "",
      "gammaPA": "",
      "hedgedPos": "",
      "idxPx": "62890.5",
      "liqPenalty": "",
      "maxSpotInUseAmt": "",
      "nonSettleAvgPx": "",
      "optVal": "",
      "pendingCloseOrdLiabVal": "0",
      "pnl": "",
      "quoteBal": "",
      "quoteBorrowed": "",
      "quoteInterest": "",
      "realizedPnl": "",
      "settledPnl": "",
      "spotInUseAmt": "",
      "spotInUseCcy": "",
      "thetaPA": "",
      "uplLastPx": "-0.0000033199677697",
      "uplRatioLastPx": "-0.0104515220008934",
      "usdPx": "",
      "vegaPA": ""
    }
  ]
}
```

**SDK Code**

```python account_getPositions_example
import requests

url = "https://www.okx.com/api/v5/account/positions"

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

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

print(response.json())
```

```javascript account_getPositions_example
const url = 'https://www.okx.com/api/v5/account/positions';
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 account_getPositions_example
package main

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

func main() {

	url := "https://www.okx.com/api/v5/account/positions"

	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 account_getPositions_example
require 'uri'
require 'net/http'

url = URI("https://www.okx.com/api/v5/account/positions")

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 account_getPositions_example
import com.mashape.unirest.http.HttpResponse;
import com.mashape.unirest.http.Unirest;

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

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

$client = new \GuzzleHttp\Client();

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

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

```csharp account_getPositions_example
using RestSharp;

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

```swift account_getPositions_example
import Foundation

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

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