NAV
δΈ­ζ–‡
HTTP Python

Overview

Welcome to our API documentation. OKX provides REST and WebSocket APIs to suit your trading needs.

API Resources and Support

Tutorials


Python libraries


Customer service

API Technical Support QR Code

API key Creation

Please refer to my api page regarding API Key creation.

Generating an API key

Create an API key on the website before signing any requests. After creating an API key, keep the following information safe:

The system returns randomly-generated API keys and SecretKeys. You will need to provide the Passphrase to access the API. We store the salted hash of your Passphrase for authentication. We cannot recover the Passphrase if you have lost it. You will need to create a new set of API key.

API key permissions

There are three permissions below that can be associated with an API key. One or more permission can be assigned to any key.

API key security

Users can get the usage records of the API key with trade or withdraw permissions but unlinked to any IP address though Security Center.

REST Authentication

Making Requests

All private REST requests must contain the following headers:

Request bodies should have content type application/json and be in valid JSON format.

Signature

Signing Messages

The OK-ACCESS-SIGN header is generated as follows:

Example: sign=CryptoJS.enc.Base64.stringify(CryptoJS.HmacSHA256(timestamp + 'GET' + '/api/v5/account/balance?ccy=BTC', SecretKey))

The timestamp value is the same as the OK-ACCESS-TIMESTAMP header with millisecond ISO format, e.g. 2020-12-08T09:08:57.715Z.

The request method should be in UPPERCASE: e.g. GET and POST.

The requestPath is the path of requesting an endpoint.

Example: /api/v5/account/balance

The body refers to the String of the request body. It can be omitted if there is no request body (frequently the case for GET requests).

Example: {"instId":"BTC-USDT","lever":"5","mgnMode":"isolated"}

The SecretKey is generated when you create an API key.

Example: 22582BD0CFF14C41EDBF1AB98506286D

WebSocket

Overview

WebSocket is a new HTML5 protocol that achieves full-duplex data transmission between the client and server, allowing data to be transferred effectively in both directions. A connection between the client and server can be established with just one handshake. The server will then be able to push data to the client according to preset rules. Its advantages include:

Connect

Connection limit: 3 requests per second (based on IP)

When subscribing to a public channel, use the address of the public service. When subscribing to a private channel, use the address of the private service

Request limit:

The total number of 'subscribe'/'unsubscribe'/'login' requests per connection is limited to 480 times per hour.

Connection count limit

The limit will be set at 30 WebSocket connections per specific WebSocket channel per sub-account. Each WebSocket connection is identified by the unique connId.


The WebSocket channels subject to this limitation are as follows:

  1. Orders channel
  2. Account channel
  3. Positions channel
  4. Balance and positions channel
  5. Position risk warning channel
  6. Account greeks channel

If users subscribe to the same channel through the same WebSocket connection through multiple arguments, for example, by using {"channel": "orders", "instType": "ANY"} and {"channel": "orders", "instType": "SWAP"}, it will be counted once only. If users subscribe to the listed channels (such as orders and accounts) using either the same or different connections, it will not affect the counting, as these are considered as two different channels. The system calculates the number of WebSocket connections per channel.


The platform will send the number of active connections to clients through the channel-conn-count event message to new channel subscriptions.

Connection count update

{
    "event":"channel-conn-count",
    "channel":"orders",
    "connCount": "2",
    "connId":"abcd1234"
}


When the limit is breached, generally the latest connection that sends the subscription request will be rejected. Client will receive the usual subscription acknowledgement followed by the channel-conn-count-error from the connection that the subscription has been terminated. In exceptional circumstances the platform may unsubscribe existing connections.

Connection limit error

{
    "event": "channel-conn-count-error",
    "channel": "orders",
    "connCount": "30",
    "connId":"a4d3ae55"
}


Order operations through WebSocket, including place, amend and cancel orders, are not impacted through this change.

Login

Request Example

{
  "op": "login",
  "args": [
    {
      "apiKey": "******",
      "passphrase": "******",
      "timestamp": "1538054050",
      "sign": "7L+zFQ+CEgGu5rzCj4+BdV2/uUHGqddA9pI6ztsRRPs="
    }
  ]
}

Request Parameters

Parameter Type Required Description
op String Yes Operation
login
args Array of objects Yes List of account to login
> apiKey String Yes API Key
> passphrase String Yes API Key password
> timestamp String Yes Unix Epoch time, the unit is seconds
> sign String Yes Signature string

Successful Response Example

{
  "event": "login",
  "code": "0",
  "msg": "",
  "connId": "a4d3ae55"
}

Failure Response Example

{
  "event": "error",
  "code": "60009",
  "msg": "Login failed.",
  "connId": "a4d3ae55"
}

Response parameters

Parameter Type Required Description
event String Yes Operation
login
error
code String No Error code
msg String No Error message
connId String Yes WebSocket connection ID

apiKey: Unique identification for invoking API. Requires user to apply one manually.

passphrase: API Key password

timestamp: the Unix Epoch time, the unit is seconds, e.g. 1704876947

sign: signature string, the signature algorithm is as follows:

First concatenate timestamp, method, requestPath, strings, then use HMAC SHA256 method to encrypt the concatenated string with SecretKey, and then perform Base64 encoding.

secretKey: The security key generated when the user applies for API key, e.g. 22582BD0CFF14C41EDBF1AB98506286D

Example of timestamp: const timestamp = '' + Date.now() / 1,000

Among sign example: sign=CryptoJS.enc.Base64.stringify(CryptoJS.HmacSHA256(timestamp +'GET'+'/users/self/verify', secretKey))

method: always 'GET'.

requestPath : always '/users/self/verify'

Subscribe

Subscription Instructions

Request format description

{
  "id": "1512",
  "op": "subscribe",
  "args": ["<SubscriptionTopic>"]
}

WebSocket channels are divided into two categories: public and private channels.

Public channels -- No authentication is required, include tickers channel, K-Line channel, limit price channel, order book channel, and mark price channel etc.

Private channels -- including account channel, order channel, and position channel, etc -- require log in.

Users can choose to subscribe to one or more channels, and the total length of multiple channels cannot exceed 64 KB.

Below is an example of subscription parameters. The requirement of subscription parameters for each channel is different. For details please refer to the specification of each channels.

Request Example

{
    "id": "1512",
    "op":"subscribe",
    "args":[
        {
            "channel":"tickers",
            "instId":"BTC-USDT"
        }
    ]
}

Request parameters

Parameter Type Required Description
id String No Unique identifier of the message
Provided by client. It will be returned in response message for identifying the corresponding request.
A combination of case-sensitive alphanumerics, all numbers, or all letters of up to 32 characters.
op String Yes Operation
subscribe
args Array of objects Yes List of subscribed channels
> channel String Yes Channel name
> instType String No Instrument type
SPOT
MARGIN
SWAP
FUTURES
OPTION
ANY
> instFamily String No Instrument family
Applicable to FUTURES/SWAP/OPTION
> instId String No Instrument ID

Response Example

{
    "id": "1512",
    "event": "subscribe",
    "arg": {
        "channel": "tickers",
        "instId": "BTC-USDT"
    },
    "connId": "accb8e21"
}

Return parameters

Parameter Type Required Description
id String No Unique identifier of the message
event String Yes Event
subscribe
error
arg Object No Subscribed channel
> channel String Yes Channel name
> instType String No Instrument type
SPOT
MARGIN
SWAP
FUTURES
OPTION
ANY
> instFamily String No Instrument family
Applicable to FUTURES/SWAP/OPTION
> instId String No Instrument ID
code String No Error code
msg String No Error message
connId String Yes WebSocket connection ID

Unsubscribe

Unsubscribe from one or more channels.

Request format description

{
  "op": "unsubscribe",
  "args": ["< SubscriptionTopic> "]
}

Request Example

{
  "op": "unsubscribe",
  "args": [
    {
      "channel": "tickers",
      "instId": "BTC-USDT"
    }
  ]
}

Request parameters

Parameter Type Required Description
op String Yes Operation
unsubscribe
args Array of objects Yes List of channels to unsubscribe from
> channel String Yes Channel name
> instType String No Instrument type
SPOT
MARGIN
SWAP
FUTURES
OPTION
ANY
> instFamily String No Instrument family
Applicable to FUTURES/SWAP/OPTION
> instId String No Instrument ID

Response Example

{
    "event": "unsubscribe",
    "arg": {
        "channel": "tickers",
        "instId": "BTC-USDT"
    },
    "connId": "d0b44253"
}

Response parameters

Parameter Type Required Description
event String Yes Event
unsubscribe
error
arg Object No Unsubscribed channel
> channel String Yes Channel name
> instType String No Instrument type
SPOT
MARGIN
SWAP
FUTURES
OPTION
> instFamily String No Instrument family
Applicable to FUTURES/SWAP/OPTION
> instId String No Instrument ID
code String No Error code
msg String No Error message

Notification

WebSocket has introduced a new message type (event = notice).

Client will receive the information in the following scenarios:

60 seconds prior to the upgrade of the WebSocket service, the notification message will be sent to users indicating that the connection will soon be disconnected. Users are encouraged to establish a new connection to prevent any disruptions caused by disconnection.

Response Example

{
    "event": "notice",
    "code": "64008",
    "msg": "The connection will soon be closed for a service upgrade. Please reconnect.",
    "connId": "a4d3ae55"
}



The feature is supported by WebSocket Public (/ws/v5/public) and Private (/ws/v5/private) for now.

Account mode

To facilitate your trading experience, please set the appropriate account mode before starting trading.

In the trading account trading system, 4 account modes are supported: Spot mode, Futures mode, Multi-currency margin mode, and Portfolio margin mode.

You need to set on the Web/App for the first set of every account mode.

Production Trading Services

The Production Trading URL:

Demo Trading Services

Currently, the API works for Demo Trading, but some functions are not supported, such as withdraw,deposit,purchase/redemption, etc.

The Demo Trading URL:

OKX account can be used for login on Demo Trading. If you already have an OKX account, you can log in directly.

Start API Demo Trading by the following steps:
Login OKX β€”> Trade β€”> Demo Trading β€”> Personal Center β€”> Demo Trading API -> Create Demo Trading API Key β€”> Start your Demo Trading

Http Header Example

Content-Type: application/json

OK-ACCESS-KEY: 37c541a1-****-****-****-10fe7a038418

OK-ACCESS-SIGN: leaVRETrtaoEQ3yI9qEtI1CZ82ikZ4xSG5Kj8gnl3uw=

OK-ACCESS-PASSPHRASE: 1****6

OK-ACCESS-TIMESTAMP: 2020-03-28T12:21:41.274Z

x-simulated-trading: 1

Demo Trading Explorer

You need to sign in to your OKX account before accessing the explorer. The interface only allow access to the demo trading environment.

Try demo trading explorer

General Info

The rules for placing orders at the exchange level are as follows:


The rules for trading are as follows:


The rules for the returning data are as follows:


instFamily and uly parameter explanation:

Contract Type uly instFamily settleCcy Delivery contract instId Swap contract instId
USDT-margined contract BTC-USDT BTC-USDT USDT BTC-USDT-250808 BTC-USDT-SWAP
USDC-margined contract BTC-USDC BTC-USDC USDC BTC-USDC-250808 BTC-USDC-SWAP
USD-margined contract BTC-USD BTC-USD_UM USDβ“ˆ BTC-USD_UM-250808 BTC-USD_UM-SWAP
Coin-margined contract BTC-USD BTC-USD BTC BTC-USD-250808 BTC-USD-SWAP

Note:
1. USDβ“ˆ represents USD and multiple USD stable coins, like USDC, USDG.
2. The settlement and margin currency refers to the settleCcy field returned by the Get instruments endpoint.

Transaction Timeouts

Orders may not be processed in time due to network delay or busy OKX servers. You can configure the expiry time of the request using expTime if you want the order request to be discarded after a specific time.

If expTime is specified in the requests for Place (multiple) orders or Amend (multiple) orders, the request will not be processed if the current system time of the server is after the expTime.

REST API

Set the following parameters in the request header

Parameter Type Required Description
expTime String No Request effective deadline. Unix timestamp format in milliseconds, e.g. 1597026383085

The following endpoints are supported:

Request Example

curl -X 'POST' \
  'https://openapi.okx.com/api/v5/trade/order' \
  -H 'accept: application/json' \
  -H 'Content-Type: application/json' \
  -H 'OK-ACCESS-KEY: *****' \
  -H 'OK-ACCESS-SIGN: *****'' \
  -H 'OK-ACCESS-TIMESTAMP: *****'' \
  -H 'OK-ACCESS-PASSPHRASE: *****'' \
  -H 'expTime: 1597026383085' \   // request effective deadline
  -d '{
  "instId": "BTC-USDT",
  "tdMode": "cash",
  "side": "buy",
  "ordType": "limit",
  "px": "1000",
  "sz": "0.01"
}'

WebSocket

The following parameters are set in the request

Parameter Type Required Description
expTime String No Request effective deadline. Unix timestamp format in milliseconds, e.g. 1597026383085

The following endpoints are supported:

Request Example

{
    "id": "1512",
    "op": "order",
    "expTime":"1597026383085",  // request effective deadline
    "args": [{
        "side": "buy",
        "instId": "BTC-USDT",
        "tdMode": "isolated",
        "ordType": "market",
        "sz": "100"
    }]
}

Rate Limits

Our REST and WebSocket APIs use rate limits to protect our APIs against malicious usage so our trading platform can operate reliably and fairly.
When a request is rejected by our system due to rate limits, the system returns error code 50011 (Rate limit reached. Please refer to API documentation and throttle requests accordingly).
The rate limit is different for each endpoint. You can find the limit for each endpoint from the endpoint details. Rate limit definitions are detailed below:

For Trading-related APIs (place order, cancel order, and amend order) the following conditions apply:

Sub-account rate limit

At the sub-account level, we allow a maximum of 1000 order requests per 2 seconds. Only new order requests and amendment order requests will be counted towards this limit. The limit encompasses all requests from the endpoints below. For batch order requests consisting of multiple orders, each order will be counted individually. Error code 50061 is returned when the sub-account rate limit is exceeded. The existing rate limit rule per instrument ID remains unchanged and the existing rate limit and sub-account rate limit will operate in parallel. If clients require a higher rate limit, clients can trade via multiple sub-accounts.

Fill ratio based sub-account rate limit

This is only applicable to >= VIP5 customers.
As an incentive for more efficient trading, the exchange will offer a higher sub-account rate limit to clients with a high trade fill ratio.

The exchange calculates two ratios based on the transaction data from the past 7 days at 00:00 UTC.

  1. Sub-account fill ratio: This ratio is determined by dividing (the trade volume in USDT of the sub-account) by (sum of (new and amendment request count per symbol * symbol multiplier) of the sub-account). Note that the master trading account itself is also considered as a sub-account in this context.
  2. Master account aggregated fill ratio: This ratio is calculated by dividing (the trade volume in USDT on the master account level) by (the sum (new and amendment count per symbol * symbol multiplier] of all sub-accounts).


The symbol multiplier allows for fine-tuning the weight of each symbol. A smaller symbol multiplier (<1) is used for smaller pairs that require more updates per trading volume. All instruments have a default symbol multiplier, and some instruments will have overridden symbol multipliers.

InstType Override rule Overridden symbol multiplier Default symbol multiplier
Perpetual Futures Per instrument ID 1
Instrument ID:
BTC-USDT-SWAP
BTC-USD-SWAP
ETH-USDT-SWAP
ETH-USD-SWAP
0.2
Expiry Futures Per instrument Family 0.3
Instrument Family:
BTC-USDT
BTC-USD
ETH-USDT
ETH-USD
0.1
Spot Per instrument ID 0.5
Instrument ID:
BTC-USDT
ETH-USDT
0.1
Options Per instrument Family 0.1

The fill ratio computation excludes block trading, spread trading, MMP and fiat orders for order count; and excludes block trading, spread trading for trade volume. Only successful order requests (sCode=0) are considered.



At 08:00 UTC, the system will use the maximum value between the sub-account fill ratio and the master account aggregated fill ratio based on the data snapshot at 00:00 UTC to determine the sub-account rate limit based on the table below. For broker (non-disclosed) clients, the system considers the sub-account fill ratio only.

Fill ratio[x<=ratio<y) Sub-account rate limit per 2 seconds(new and amendment)
Tier 1 [0,1) 1,000
Tier 2 [1,2) 1,250
Tier 3 [2,3) 1,500
Tier 4 [3,5) 1,750
Tier 5 [5,10) 2,000
Tier 6 [10,20) 2,500
Tier 7 [20,50) 3,000
Tier 8 >= 50 10,000

If there is an improvement in the fill ratio and rate limit to be uplifted, the uplift will take effect immediately at 08:00 UTC. However, if the fill ratio decreases and the rate limit needs to be lowered, a one-day grace period will be granted, and the lowered rate limit will only be implemented on T+1 at 08:00 UTC. On T+1, if the fill ratio improves, the higher rate limit will be applied accordingly. In the event of client demotion to VIP4, their rate limit will be downgraded to Tier 1, accompanied by a one-day grace period.


If the 7-day trading volume of a sub-account is less than 1,000,000 USDT, the fill ratio of the master account will be applied to it.


For newly created sub-accounts, the Tier 1 rate limit will be applied at creation until T+1 8am UTC, at which the normal rules will be applied.


Block trading, spread trading, MMP and spot/margin orders are exempted from the sub-account rate limit.


The exchange offers GET / Account rate limit endpoint that provides ratio and rate limit data, which will be updated daily at 8am UTC. It will return the sub-account fill ratio, the master account aggregated fill ratio, current sub-account rate limit and sub-account rate limit on T+1 (applicable if the rate limit is going to be demoted).

The fill ratio and rate limit calculation example is shown below. Client has 3 accounts, symbol multiplier for BTC-USDT-SWAP = 1 and XRP-USDT = 0.1.

  1. Account A (master account):
    1. BTC-USDT-SWAP trade volume = 100 USDT, order count = 10;
    2. XRP-USDT trade volume = 20 USDT, order count = 15;
    3. Sub-account ratio = (100+20) / (10 * 1 + 15 * 0.1) = 10.4
  2. Account B (sub-account):
    1. BTC-USDT-SWAP trade volume = 200 USDT, order count = 100;
    2. XRP-USDT trade volume = 20 USDT, order count = 30;
    3. Sub-account ratio = (200+20) / (100 * 1 + 30 * 0.1) = 2.13
  3. Account C (sub-account):
    1. BTC-USDT-SWAP trade volume = 300 USDT, order count = 1000;
    2. XRP-USDT trade volume = 20 USDT, order count = 45;
    3. Sub-account ratio = (300+20) / (100 * 1 + 45 * 0.1) = 3.06
  4. Master account aggregated fill ratio = (100+20+200+20+300+20) / (10 * 1 + 15 * 0.1 + 100 * 1 + 30 * 0.1 + 100 * 1 + 45 * 0.1) = 3.01
  5. Rate limit of accounts
    1. Account A = max(10.4, 3.01) = 10.4 -> 2500 order requests/2s
    2. Account B = max(2.13, 3.01) = 3.01 -> 1750 order requests/2s
    3. Account C = max(3.06, 3.01) = 3.06 -> 1750 order requests/2s

Best practices

If you require a higher request rate than our rate limit, you can set up different sub-accounts to batch request rate limits. We recommend this method for throttling or spacing out requests in order to maximize each accounts' rate limit and avoid disconnections or rejections.

Market Maker Program

High-caliber trading teams are welcomed to work with OKX as market makers in providing a liquid, fair, and orderly platform to all users. OKX market makers could enjoy favourable fees in return for meeting the market making obligations.

Prerequisites (Satisfy any condition):

Interested parties can reach out to us at [email protected]

Remarks:

Market making obligations and trading fees will be shared to successful parties only.

Broker Program

If your business platform offers cryptocurrency services, you can apply to join the OKX Broker Program, become our partner broker, enjoy exclusive broker services, and earn high rebates through trading fees generated by OKX users.
The Broker Program includes, and is not limited to, integrated trading platforms, trading bots, copy trading platforms, trading bot providers, quantitative strategy institutions, asset management platforms etc.

Relevant information for specific Broker Program documentation and product services will be provided following successful applications.

Trading Account

The API endpoints of Account require authentication.

REST API

Get instruments

Retrieve available instruments info of current account.

Rate Limit: 20 requests per 2 seconds

Rate limit rule: User ID + Instrument Type

HTTP Request

GET /api/v5/account/instruments

Request Example

GET /api/v5/account/instruments?instType=SPOT
import okx.Account as Account

# API initialization
apikey = "YOUR_API_KEY"
secretkey = "YOUR_SECRET_KEY"
passphrase = "YOUR_PASSPHRASE"

flag = "1" # Production trading: 0, Demo trading: 1

accountAPI = Account.AccountAPI(apikey, secretkey, passphrase, False, flag)

result = accountAPI.get_instruments(instType="SPOT")
print(result)

Request Parameters

Parameter Type Required Description
instType String Yes Instrument type
SPOT: Spot
MARGIN: Margin
SWAP: Perpetual Futures
FUTURES: Expiry Futures
OPTION: Option
EVENTS: Event Contracts
seriesId String Conditional Series ID, e.g. BTC-ABOVE-DAILY. Required when instType is EVENTS
instFamily String Conditional Instrument family
Only applicable to FUTURES/SWAP/OPTION. If instType is OPTION, instFamily is required.
instId String No Instrument ID

Response Example

{
    "code": "0",
    "data": [
        {
            "auctionEndTime": "",
            "baseCcy": "BTC",
            "ctMult": "",
            "ctType": "",
            "ctVal": "",
            "ctValCcy": "",
            "contTdSwTime": "1704876947000",
            "elp": "0",
            "rpi": "0",
            "expTime": "",
            "futureSettlement": false,
            "groupId": "4",
            "instFamily": "",
            "instId": "BTC-EUR",
            "instType": "SPOT",
            "lever": "",
            "listTime": "1704876947000",
            "lotSz": "0.00000001",
            "maxIcebergSz": "9999999999.0000000000000000",
            "maxLmtAmt": "1000000",
            "maxLmtSz": "9999999999",
            "maxMktAmt": "1000000",
            "maxMktSz": "1000000",
            "maxPlatOILmt": "1000000000",
            "maxPlatOICoinLmt": "",
            "maxStopSz": "1000000",
            "maxTriggerSz": "9999999999.0000000000000000",
            "maxTwapSz": "9999999999.0000000000000000",
            "minSz": "0.00001",
            "optType": "",
            "openType": "call_auction",
            "preMktSwTime": "",
            "posLmtPct": "30",
            "posLmtAmt": "2500000",
            "quoteCcy": "EUR",
            "tradeQuoteCcyList": [
                "EUR"
            ],
            "settleCcy": "",
            "state": "live",
            "ruleType": "normal",
            "stk": "",
            "tickSz": "1",
            "uly": "",
            "instIdCode": 1000000000,   
            "instCategory": "1",
            "initPxLmtPct": "0.05",
            "floatPxLmtPct": "0.03",
            "maxPxLmtPct": "0.15",
            "upcChg": [
                {
                    "param": "tickSz",
                    "newValue": "0.0001",
                    "effTime": "1704876947000"
                }
            ]
        }
    ],
    "msg": ""
}

Response Parameters

Parameter Type Description
instType String Instrument type
seriesId String Series ID, e.g. BTC-ABOVE-DAILY. Only applicable to EVENTS
instId String Instrument ID, e.g. BTC-USD-SWAP
uly String Underlying, e.g. BTC-USD
Only applicable to MARGIN/FUTURES/SWAP/OPTION
groupId String Instrument trading fee group ID
Spot:
3: Spot TRY
5: Spot BRL
7: Spot AED
8: Spot AUD
10: Spot SGD
11: Spot zero
12: Spot group one
13: Spot group two
14: Spot group three
15: Spot special rule
17: Spot stablecoin
22: Spot RWA group two

Expiry futures:
5: Expiry futures group one
6: Expiry futures group two
8: XPERP group two
10: XPERP RWA group two

Perpetual futures:
4: Perpetual futures group one
5: Perpetual futures group two
6: SWAP RWA group one
7: SWAP RWA group two

Options:
1: Options crypto-margined

instType and groupId should be used together to determine a trading fee group. Users should use this endpoint together with fee rates endpoint to get the trading fee of a specific symbol.

Some enum values may not apply to you; the actual return values shall prevail.
instFamily String Instrument family, e.g. BTC-USD
Only applicable to MARGIN/FUTURES/SWAP/OPTION
baseCcy String Base currency, e.g. BTC inBTC-USDT
Only applicable to SPOT/MARGIN
quoteCcy String Quote currency, e.g. USDT in BTC-USDT
Only applicable to SPOT/MARGIN
settleCcy String Settlement and margin currency, e.g. BTC
Only applicable to FUTURES/SWAP/OPTION
ctVal String Contract value
Only applicable to FUTURES/SWAP/OPTION
ctMult String Contract multiplier
Only applicable to FUTURES/SWAP/OPTION
ctValCcy String Contract value currency
Only applicable to FUTURES/SWAP/OPTION
optType String Option type, C: Call P: put
Only applicable to OPTION
stk String Strike price
Only applicable to OPTION
listTime String Listing time, Unix timestamp format in milliseconds, e.g. 1597026383085
auctionEndTime String The end time of call auction, Unix timestamp format in milliseconds, e.g. 1597026383085
Only applicable to SPOT that are listed through call auctions, return "" in other cases (deprecated, use contTdSwTime)
contTdSwTime String Continuous trading switch time. The switch time from call auction, prequote to continuous trading, Unix timestamp format in milliseconds. e.g. 1597026383085.
Only applicable to SPOT/MARGIN that are listed through call auction or prequote, return "" in other cases.
preMktSwTime String The time a pre-market instrument switched to normal trading, Unix timestamp format in milliseconds, e.g. 1597026383085.
Only applicable to pre-market SWAP and pre-market X-Perp FUTURES. Populated when a pre-market X-Perp converts to a normal X-Perp
openType String Open type
fix_price: fix price opening
pre_quote: pre-quote
call_auction: call auction
Only applicable to SPOT/MARGIN, return "" for all other business lines
elp String ELP maker permission
0: ELP is not enabled for this symbol
1: ELP is enabled for this symbol, but current users don't have permission to place ELP orders for it.
2: ELP is enabled for this symbol, and current users have permission to place ELP orders for it.

It doesn't mean there will be ELP liquidity when elp is 1/2.
rpi String RPI maker permission.
0: not enabled for this instrument
1: enabled, but the current user has no permission to place RPI orders
2: enabled and permitted
A 1/2 value does not imply RPI liquidity is present.
elp remains accepted as an alias until October 31, 2026.
expTime String Expiry time
Applicable to SPOT/MARGIN/FUTURES/SWAP/OPTION. For FUTURES/OPTION, it is natural delivery/exercise time. It is the instrument offline time when there is SPOT/MARGIN/FUTURES/SWAP/ manual offline. Update once change.
lever String Max Leverage,
Not applicable to SPOT, OPTION
tickSz String Tick size, e.g. 0.0001.
For OPTION/EVENTS, it is the minimum tickSz among tick band. Use "Get instrument tick bands" endpoint with the corresponding instType for accurate tickSz per price range.
lotSz String Lot size
If it is a derivatives contract, the value is the number of contracts.
If it is SPOT/MARGIN, the value is the quantity in base currency.
minSz String Minimum order size
If it is a derivatives contract, the value is the number of contracts.
If it is SPOT/MARGIN, the value is the quantity in base currency.
ctType String Contract type
linear: linear contract
inverse: inverse contract
Only applicable to FUTURES/SWAP
state String Instrument status
live
suspend
rebase: can't be traded during rebasing, only applicable to SWAP
post_only: only post-only orders are accepted; existing post-only orders can be amended and cancelled. Other order types (market, IOC, FOK, normal limit) are rejected. Only applicable to SWAP
preopen e.g. Futures and options contracts rollover from generation to trading start; certain symbols before they go live
test: Test pairs, can't be traded
settling: Settling, only applicable to EVENTS
ruleType String Trading rule types
normal: normal trading
pre_market: pre-market trading, including pre-market X-Perp FUTURES
rebase_contract: pre-market rebase contract
xperp: perpetual-style futures, only applicable to certain FUTURES contracts. A pre-market X-Perp changes from pre_market to xperp after it converts to a normal X-Perp
posLmtAmt String Maximum position value (USD) for this instrument at the user level (shared across master and sub-accounts), based on the notional value of all same-direction open positions and resting orders. The effective user limit is max(posLmtAmt, oiUSD Γ— posLmtPct). Applicable to SWAP/FUTURES.
posLmtPct String Maximum position ratio (e.g., 30 for 30%) a user (shared across master and sub-accounts) may hold relative to the platform's current total position value. The effective user limit is max(posLmtAmt, oiUSD Γ— posLmtPct). Applicable to SWAP/FUTURES.
maxPlatOILmt String Platform-wide maximum position value (USD) for this instrument. If the platform total open interest (USD) reaches or exceeds this value, all users’ new opening orders for this instrument are rejected; otherwise, orders pass.
Applicable to SWAP/FUTURES
maxPlatOICoinLmt String Platform-wide maximum position value (coins) for this instrument. If the platform total open interest (coins) reaches or exceeds this value, all users’ new opening orders for this instrument are rejected; otherwise, orders pass.
Applicable to SWAP/FUTURES
longPosRemainingQuota String The remaining long position value (USD) the user is permitted to open, netting all existing long positions and resting buy orders. The quota is shared across the master account and all subaccounts.
shortPosRemainingQuota String The remaining short position value (USD) the user is permitted to open, netting all existing short positions and resting sell orders. The quota is shared across the master account and all subaccounts.
maxLmtSz String The maximum order quantity of a single limit order.
If it is a derivatives contract, the value is the number of contracts.
If it is SPOT/MARGIN, the value is the quantity in base currency.
maxMktSz String The maximum order quantity of a single market order.
If it is a derivatives contract, the value is the number of contracts.
If it is SPOT/MARGIN, the value is the quantity in USDT.
maxLmtAmt String Max USD amount for a single limit order
maxMktAmt String Max USD amount for a single market order
Only applicable to SPOT/MARGIN
maxTwapSz String The maximum order quantity of a single TWAP order.
If it is a derivatives contract, the value is the number of contracts.
If it is SPOT/MARGIN, the value is the quantity in base currency.
The minimum order quantity of a single TWAP order is minSz*2
maxIcebergSz String The maximum order quantity of a single iceBerg order.
If it is a derivatives contract, the value is the number of contracts.
If it is SPOT/MARGIN, the value is the quantity in base currency.
maxTriggerSz String The maximum order quantity of a single trigger order.
If it is a derivatives contract, the value is the number of contracts.
If it is SPOT/MARGIN, the value is the quantity in base currency.
maxStopSz String The maximum order quantity of a single stop market order.
If it is a derivatives contract, the value is the number of contracts.
If it is SPOT/MARGIN, the value is the quantity in USDT.
futureSettlement Boolean Whether daily settlement for expiry feature is enabled
Applicable to FUTURES cross
tradeQuoteCcyList Array of strings List of quote currencies available for trading, e.g. ["USD", "USDC"].
instIdCode Integer Instrument ID code.
For simple binary encoding, you must use instIdCode instead of instId.
For the same instId, it's value may be different between production and demo trading.
It is null when the value is not generated.
instCategory String The asset category of the instrument’s base asset (the first segment of the instrument ID). For example, for BTC-USDT-SWAP, the instCategory represents the asset category of BTC.
1: Crypto
3: Stocks
4: Commodities
5: Forex
6: Bonds
"": Not available
initPxLmtPct String Initial price-limit band applied during the first 10 minutes after contract listing, e.g. 0.05 represents 5%. Use GET /api/v5/public/price-limit for the computed price limits.
Only applicable to SPOT/MARGIN/SWAP/FUTURES, returns "" for OPTION and EVENTS.
floatPxLmtPct String Floating price-limit band during normal trading, e.g. 0.03 represents 3%. Use GET /api/v5/public/price-limit for the computed price limits.
Only applicable to SPOT/MARGIN/SWAP/FUTURES, returns "" for OPTION and EVENTS.
maxPxLmtPct String Maximum price-limit cap (hard ceiling on order-price deviation from the index price), e.g. 0.15 represents 15%. Use GET /api/v5/public/price-limit for the computed price limits.
Only applicable to SPOT/MARGIN/SWAP/FUTURES, returns "" for OPTION and EVENTS.
upcChg Array of objects Upcoming changes. It is [] when there is no upcoming change.
> param String The parameter name to be updated.
tickSz
minSz: For FUTURES/SWAP, lotSz will be modified synchronously.
maxMktSz
> newValue String The parameter value that will replace the current one.
> effTime String Effective time. Unix timestamp format in milliseconds, e.g. 1597026383085

Get balance

Retrieve a list of assets (with non-zero balance), remaining balance, and available amount in the trading account.

Rate Limit: 10 requests per 2 seconds

Rate limit rule: User ID

HTTP Request

GET /api/v5/account/balance

Request Example

# Get the balance of all assets in the account
GET /api/v5/account/balance

# Get the balance of BTC and ETH assets in the account
GET /api/v5/account/balance?ccy=BTC,ETH

import okx.Account as Account

# API initialization
apikey = "YOUR_API_KEY"
secretkey = "YOUR_SECRET_KEY"
passphrase = "YOUR_PASSPHRASE"

flag = "1"  # Production trading:0 , demo trading:1

accountAPI = Account.AccountAPI(apikey, secretkey, passphrase, False, flag)

# Get account balance
result = accountAPI.get_account_balance()
print(result)

Request Parameters

Parameters Types Required Description
ccy String No Single currency or multiple currencies (no more than 20) separated with comma, e.g. BTC or BTC,ETH.

Response Example

{
    "code": "0",
    "data": [
        {
            "adjEq": "55415.624719833286",
            "availEq": "55415.624719833286",
            "borrowFroz": "0",
            "delta": "0",
            "deltaLever": "0",
            "deltaNeutralStatus": "0",
            "details": [
                {
                    "autoLendStatus": "off",
                    "autoLendMtAmt": "0",
                    "availBal": "4834.317093622894",
                    "availEq": "4834.3170936228935",
                    "borrowFroz": "0",
                    "cashBal": "4850.435693622894",
                    "ccy": "USDT",
                    "crossLiab": "0",
                    "colRes": "0",
                    "collateralEnabled": false,
                    "collateralRestrict": false,
                    "colBorrAutoConversion": "0",
                    "disEq": "4991.542013297616",
                    "eq": "4992.890093622894",
                    "eqUsd": "4991.542013297616",
                    "smtSyncEq": "0",
                    "spotCopyTradingEq": "0",
                    "fixedBal": "0",
                    "frozenBal": "158.573",
                    "frpType": "0",
                    "imr": "",
                    "interest": "0",
                    "isoEq": "0",
                    "isoLiab": "0",
                    "isoUpl": "0",
                    "liab": "0",
                    "maxLoan": "0",
                    "mgnRatio": "",
                    "mmr": "",
                    "notionalLever": "",
                    "ordFrozen": "0",
                    "rewardBal": "0",
                    "spotInUseAmt": "",
                    "clSpotInUseAmt": "",
                    "maxSpotInUse": "",
                    "spotIsoBal": "0",
                    "stgyEq": "150",
                    "twap": "0",
                    "uTime": "1705449605015",
                    "upl": "-7.545600000000006",
                    "uplLiab": "0",
                    "spotBal": "",
                    "openAvgPx": "",
                    "accAvgPx": "",
                    "spotUpl": "",
                    "spotUplRatio": "",
                    "totalPnl": "",
                    "totalPnlRatio": ""
                }
            ],
            "imr": "0",
            "isoEq": "0",
            "mgnRatio": "",
            "mmr": "0",
            "notionalUsd": "0",
            "notionalUsdForBorrow": "0",
            "notionalUsdForFutures": "0",
            "notionalUsdForOption": "0",
            "notionalUsdForSwap": "0",
            "ordFroz": "",
            "totalEq": "55837.43556134779",
            "uTime": "1705474164160",
            "upl": "0"
        }
    ],
    "msg": ""
}

Response Parameters

Parameters Types Description
uTime String Update time of account information, millisecond format of Unix timestamp, e.g. 1597026383085
totalEq String Total account assets denominated in USD
isoEq String Isolated margin equity in USD
Applicable to Futures mode/Multi-currency margin/Portfolio margin
adjEq String Adjusted equity in USD: totalEq minus haircut discounts applied to non-stablecoin collateral assets. This is the operative value used in the margin ratio calculation (mgnRatio = adjEq / mmr).
The net fiat value of the assets in the account that can provide margins for spot, expiry futures, perpetual futures and options under the cross-margin mode.
In multi-ccy or PM mode, the asset and margin requirement will all be converted to USD value to process the order check or liquidation.
Due to the volatility of each currency market, our platform calculates the actual USD value of each currency based on discount rates to balance market risks.
Applicable to Spot mode/Multi-currency margin and Portfolio margin
availEq String Account level available equity, excluding currencies that are restricted due to the collateralized borrowing limit.
Applicable to Multi-currency margin/Portfolio margin
ordFroz String Cross margin frozen for pending orders in USD
Only applicable to Spot mode/Multi-currency margin/Portfolio margin
imr String Initial Margin Requirement (IMR) in USD: equity locked across all open cross-margin positions. The sum of initial margins of all open positions and pending orders under cross-margin mode. Formula per position: position size Γ— markPx Γ— initial margin rate (= 1/lever). Returns empty string in Simple mode.
Applicable to Spot mode/Multi-currency margin/Portfolio margin
mmr String Maintenance Margin Requirement (MMR) in USD: the minimum equity required to avoid forced liquidation. The sum of maintenance margins of all open positions and pending orders under cross-margin mode. When adjEq ≀ mmr (equivalently, mgnRatio ≀ 1.0), the system begins forced liquidation of positions. Subscribe to the position-risk-warning WebSocket channel for proactive alerts.
Applicable to Spot mode/Multi-currency margin/Portfolio margin
borrowFroz String Potential borrowing IMR of the account in USD
Only applicable to Spot mode/Multi-currency margin/Portfolio margin. It is "" for other margin modes.
mgnRatio String Account-level margin ratio = adjEq / mmr. Values at or below 1.0 indicate the account is at or past the liquidation boundary. Monitor this field or subscribe to the position-risk-warning WebSocket channel for proactive alerts.
Applicable to Spot mode/Multi-currency margin/Portfolio margin
notionalUsd String Gross notional value of all open derivative positions converted to USD. Linear contracts: sz Γ— ctVal Γ— markPx. Inverse contracts: sz Γ— ctVal (USD-denominated face value). Gross = long and short are not netted.
Applicable to Spot mode/Multi-currency margin/Portfolio margin
notionalUsdForBorrow String Notional value for Borrow in USD
Applicable to Spot mode/Multi-currency margin/Portfolio margin
notionalUsdForSwap String Notional value of positions for Perpetual Futures in USD
Applicable to Multi-currency margin/Portfolio margin
notionalUsdForFutures String Notional value of positions for Expiry Futures in USD
Applicable to Multi-currency margin/Portfolio margin
notionalUsdForOption String Notional value of positions for Option in USD
Applicable to Spot mode/Multi-currency margin/Portfolio margin
upl String Unrealized PnL across all open cross-margin positions at the account level, in USD. Calculated using mark price (not last trade price). Positive = unrealized gain; negative = unrealized loss. Returns empty string in Simple mode and Single-currency margin mode.
Applicable to Multi-currency margin/Portfolio margin
delta String Delta (USD)
deltaLever String Delta neutral strategy account level delta leverage
deltaLever = delta / totalEq
deltaNeutralStatus String Delta risk status
0: normal
1: transfer restricted
2: delta reducing - cancel all pending orders if delta is greater than 5000 USD, only one delta reducing order allowed per index (spot, futures, swap)
details Array of objects Detailed asset information in all currencies
> ccy String Currency
> eq String Equity of currency
> cashBal String Cash balance
> uTime String Update time of currency balance information, Unix timestamp format in milliseconds, e.g. 1597026383085
> isoEq String Isolated margin equity of currency
Applicable to Futures mode/Multi-currency margin/Portfolio margin
> availEq String Available equity of currency
Applicable to Futures mode/Multi-currency margin/Portfolio margin
> disEq String Discount equity of currency in USD.
Applicable to Spot mode(enabled spot borrow)/Multi-currency margin/Portfolio margin
> fixedBal String Frozen balance for Dip Sniper and Peak Sniper
> availBal String Available balance of currency
> frozenBal String Frozen balance of currency
> ordFrozen String Margin frozen for open orders
Applicable to Spot mode/Futures mode/Multi-currency margin
> liab String Liabilities of currency
It is a positive value, e.g. 21625.64
Applicable to Spot mode/Multi-currency margin/Portfolio margin
> upl String The sum of the unrealized profit & loss of all margin and derivatives positions of currency.
Applicable to Futures mode/Multi-currency margin/Portfolio margin
> uplLiab String Liabilities due to Unrealized loss of currency
Applicable to Multi-currency margin/Portfolio margin
> crossLiab String Cross liabilities of currency
Applicable to Spot mode/Multi-currency margin/Portfolio margin
> rewardBal String Trial fund balance
> isoLiab String Isolated liabilities of currency
Applicable to Multi-currency margin/Portfolio margin
> mgnRatio String Cross maintenance margin ratio of currency
The index for measuring the risk of a certain asset in the account.
Applicable to Futures mode and when there is cross position
> imr String Cross initial margin requirement at the currency level
Applicable to Futures mode and when there is cross position
> mmr String Cross maintenance margin requirement at the currency level
Applicable to Futures mode and when there is cross position
> interest String Accrued interest of currency
It is a positive value, e.g. 9.01
Applicable to Spot mode/Multi-currency margin/Portfolio margin
> twap String Risk indicator of forced repayment
Divided into multiple levels from 0 to 5, the larger the number, the more likely the forced repayment will be triggered.
Applicable to Spot mode/Multi-currency margin/Portfolio margin
> frpType String Forced repayment (FRP) type
0: no FRP
1: user based FRP
2: platform based FRP

Return 1/2 when twap is >= 1, applicable to Spot mode/Multi-currency margin/Portfolio margin
> maxLoan String Maximum borrowable amount for the currency under the current account conditions. Affects the amount available for margin borrowing and transfers.
Applicable to cross of Spot mode/Multi-currency margin/Portfolio margin
> eqUsd String Equity in USD of currency
> borrowFroz String Potential borrowing IMR of currency in USD
Applicable to Multi-currency margin/Portfolio margin. It is "" for other margin modes.
> notionalLever String Leverage of currency
Applicable to Futures mode
> stgyEq String Total equity allocated to trading bots for the currency. Covers Spot Grid, Futures Grid, Signal Bot, Futures Martingale, Spot Martingale, Infinite Grid, and Recurring Buy strategies.
> isoUpl String Isolated unrealized profit and loss of currency
Applicable to Futures mode/Multi-currency margin/Portfolio margin
> spotInUseAmt String Actual spot hedging amount in use for the currency.
Applicable to Portfolio margin
> clSpotInUseAmt String User-defined spot hedging amount for the currency. Applicable to Portfolio margin
> maxSpotInUse String System-calculated maximum possible spot hedging amount for the currency.
Applicable to Portfolio margin
> spotIsoBal String Balance acquired through spot copy trading (as a follower or lead trader), including amounts currently frozen by open orders. For example, if 1 BTC was purchased via copy trading and 0.4 BTC is frozen in an open sell order, spotIsoBal returns 1, not 0.6.
Applicable to copy trading. Applicable to Spot mode/Futures mode.
> smtSyncEq String Smart sync equity
The default is "0", only applicable to copy trader.
> spotCopyTradingEq String Spot smart sync equity.
The default is "0", only applicable to copy trader.
> spotBal String Spot balance. The unit is currency, e.g. BTC. More details
> openAvgPx String Spot average cost price. The unit is USD. More details
> accAvgPx String Spot accumulated cost price. The unit is USD. More details
> spotUpl String Spot unrealized profit and loss. The unit is USD. More details
> spotUplRatio String Spot unrealized profit and loss ratio. More details
> totalPnl String Spot accumulated profit and loss. The unit is USD. More details
> totalPnlRatio String Spot accumulated profit and loss ratio. More details
> colRes String Platform level collateral restriction status
0: The restriction is not enabled.
1: The restriction is not enabled. But the crypto is close to the platform's collateral limit.
2: The restriction is enabled. This crypto can't be used as margin for your new orders. This may result in failed orders. But it will still be included in the account's adjusted equity and doesn't impact margin ratio.
Refer to Introduction to the platform collateralized borrowing limit for more details.
> colBorrAutoConversion String Risk indicator of auto conversion. Divided into multiple levels from 1-5, the larger the number, the more likely the repayment will be triggered. The default will be 0, indicating there is no risk currently. 5 means this user is undergoing auto conversion now, 4 means this user will undergo auto conversion soon whereas 1/2/3 indicates there is a risk for auto conversion.
Applicable to Spot mode/Futures mode/Multi-currency margin/Portfolio margin
When the total liability for each crypto set as collateral exceeds a certain percentage of the platform's total limit, the auto-conversion mechanism may be triggered. This may result in the automatic sale of excess collateral crypto if you've set this crypto as collateral and have large borrowings. To lower this risk, consider reducing your use of the crypto as collateral or reducing your liabilities.
Refer to Introduction to the platform collateralized borrowing limit for more details.
> collateralRestrict Boolean Platform level collateralized borrow restriction
true
false
(deprecated, use colRes instead)
> collateralEnabled Boolean true: Collateral enabled
false: Collateral disabled
Applicable to Multi-currency margin
> autoLendStatus String Auto lend status
unsupported: auto lend is not supported by this currency
off: auto lend is supported but turned off
pending: auto lend is turned on but pending matching
active: auto lend is turned on and matched
> autoLendMtAmt String Auto lend currency matched amount
Return "0" when autoLendStatus is unsupported/off/pending. Return matched amount when autoLendStatus is active

Distribution of applicable fields under each account level are as follows:

Parameters Spot mode Futures mode Multi-currency margin mode Portfolio margin mode
uTime Yes Yes Yes Yes
totalEq Yes Yes Yes Yes
isoEq Yes Yes Yes
adjEq Yes Yes Yes
availEq Yes Yes
ordFroz Yes Yes Yes
imr Yes Yes Yes
mmr Yes Yes Yes
borrowFroz Yes Yes Yes
mgnRatio Yes Yes Yes
notionalUsd Yes Yes Yes
notionalUsdForSwap Yes Yes
notionalUsdForFutures Yes Yes
notionalUsdForOption Yes Yes Yes
notionalUsdForBorrow Yes Yes Yes
upl Yes Yes
details Yes Yes Yes Yes
> ccy Yes Yes Yes Yes
> eq Yes Yes Yes Yes
> cashBal Yes Yes Yes Yes
> uTime Yes Yes Yes Yes
> isoEq Yes Yes Yes
> availEq Yes Yes Yes
> disEq Yes Yes Yes
> availBal Yes Yes Yes Yes
> frozenBal Yes Yes Yes Yes
> ordFrozen Yes Yes Yes Yes
> liab Yes Yes Yes
> upl Yes Yes Yes
> uplLiab Yes Yes
> crossLiab Yes Yes Yes
> isoLiab Yes Yes
> mgnRatio Yes
> interest Yes Yes Yes
> twap Yes Yes Yes
> maxLoan Yes Yes Yes
> eqUsd Yes Yes Yes Yes
> borrowFroz Yes Yes Yes
> notionalLever Yes
> stgyEq Yes Yes Yes Yes
> isoUpl Yes Yes Yes
> spotInUseAmt Yes
> clSpotInUseAmt Yes
> maxSpotInUse Yes
> spotIsoBal Yes Yes
> imr Yes
> mmr Yes
> smtSyncEq Yes Yes Yes Yes
> spotCopyTradingEq Yes Yes Yes Yes
> spotBal Yes Yes Yes Yes
> openAvgPx Yes Yes Yes Yes
> accAvgPx Yes Yes Yes Yes
> spotUpl Yes Yes Yes Yes
> spotUplRatio Yes Yes Yes Yes
> totalPnl Yes Yes Yes Yes
> totalPnlRatio Yes Yes Yes Yes
> collateralEnabled Yes

Get positions

Retrieve information on your positions. When the account is in net mode, net positions will be displayed, and when the account is in long/short mode, long or short positions will be displayed. Return in reverse chronological order using ctime.

Rate Limit: 10 requests per 2 seconds

Rate limit rule: User ID

HTTP Request

GET /api/v5/account/positions

Request Example

# Query BTC-USDT position information
GET /api/v5/account/positions?instId=BTC-USDT

import okx.Account as Account

# API initialization
apikey = "YOUR_API_KEY"
secretkey = "YOUR_SECRET_KEY"
passphrase = "YOUR_PASSPHRASE"

flag = "1"  # Production trading:0 , demo trading:1

accountAPI = Account.AccountAPI(apikey, secretkey, passphrase, False, flag)

# Get positions information
result = accountAPI.get_positions()
print(result)

Request Parameters

Parameter Type Required Description
instType String No Instrument type
MARGIN
SWAP
FUTURES
OPTION
EVENTS
instId will be checked against instType when both parameters are passed.
instId String No Instrument ID, e.g. BTC-USDT-SWAP. Single instrument ID or multiple instrument IDs (no more than 10) separated with comma
posId String No Single position ID or multiple position IDs (no more than 20) separated with comma.
There is attribute expiration, the posId and position information will be cleared if it is more than 30 days after the last full close position.

Response Example

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

Response Parameters

Parameter Type Description
instType String Instrument type
MARGIN
SWAP
FUTURES
OPTION
EVENTS
mgnMode String Margin mode
cross
isolated
posId String Position ID
posSide String Position side
long, pos is positive
short, pos is positive
net (FUTURES/SWAP/OPTION: positive pos means long position and negative pos means short position. For MARGIN, pos is always positive, posCcy being base currency means long position, posCcy being quote currency means short position.)
pos String Position quantity. Unit: number of contracts for SWAP/FUTURES/OPTIONS; base currency amount for MARGIN. Sign (net mode): positive = long, negative = short. In long/short mode, separate records are returned per side β€” check posSide. In the isolated margin mode, when doing manual transfers, a position with pos of 0 will be generated after the deposit is transferred (represents a funded-but-empty position record created after a margin deposit).
hedgedPos String Hedged position size
Only return for accounts in delta neutral strategy, stgyType:1. Return "" for accounts in general strategy.
baseBal String Base currency balance, only applicable to MARGIN(Quick Margin ModeοΌ‰(Deprecated)
quoteBal String Quote currency balance, only applicable to MARGIN(Quick Margin ModeοΌ‰(Deprecated)
baseBorrowed String Base currency amount already borrowed, only applicable to MARGIN(Quick Margin ModeοΌ‰(Deprecated)
baseInterest String Base Interest, undeducted interest that has been incurred, only applicable to MARGIN(Quick Margin ModeοΌ‰(Deprecated)
quoteBorrowed String Quote currency amount already borrowed, only applicable to MARGIN(Quick Margin ModeοΌ‰(Deprecated)
quoteInterest String Quote Interest, undeducted interest that has been incurred, only applicable to MARGIN(Quick Margin ModeοΌ‰(Deprecated)
posCcy String Position currency, only applicable to MARGIN positions.
availPos String Position that can be closed
Only applicable to MARGIN and OPTION.
For MARGIN position, the rest of sz will be SPOT trading after the liability is repaid while closing the position. Please get the available reduce-only amount from "Get maximum available tradable amount" if you want to reduce the amount of SPOT trading as much as possible.
avgPx String Volume-weighted average entry price of the current open position. Denominated in quote currency for linear contracts (e.g., USDT for BTC-USDT-SWAP) and in USD for inverse contracts (e.g., BTC-USD-SWAP). Recalculated after each fill that changes position size.
Under cross-margin mode, the entry price of expiry futures will update at settlement to the last settlement price, and when the position is opened or increased.
nonSettleAvgPx String Non-settlement entry price
The non-settlement entry price only reflects the average price at which the position is opened or increased.
Applicable to cross FUTURES positions.
markPx String Latest Mark price
upl String Unrealized PnL for this position, denominated in the instrument's settlement currency (see ccy). Formula: (markPx βˆ’ avgPx) Γ— pos Γ— ctVal for linear; (1/avgPx βˆ’ 1/markPx) Γ— pos Γ— ctVal for inverse. For account-level USD total, see upl in GET /api/v5/account/balance.
uplRatio String Unrealized profit and loss ratio calculated by mark price.
uplLastPx String Unrealized profit and loss calculated by last price. Main usage is showing, actual value is upl.
uplRatioLastPx String Unrealized profit and loss ratio calculated by last price.
instId String Instrument ID, e.g. BTC-USDT-SWAP
lever String Leverage
Not applicable to OPTION and positions of cross margin mode under Portfolio margin
liqPx String Estimated mark price at which this position would be forcibly liquidated. This is an estimate based on current equity and margin rates β€” the actual liquidation price can change quickly due to funding rate accrual, other position changes, or rapid market moves.
Not applicable to OPTION
imr String Initial margin requirement for this specific cross-margin position, in USD. Formula: position size Γ— markPx Γ— initial margin rate (1/lever). For total account IMR, see imr in GET /api/v5/account/balance. Empty string for isolated positions. Only applicable to cross.
margin String Margin, can be added or reduced. Only applicable to isolated.
mgnRatio String Maintenance margin ratio
mmr String Maintenance margin requirement
liab String Liabilities, only applicable to MARGIN.
liabCcy String Liabilities currency, only applicable to MARGIN.
interest String Interest. Undeducted interest that has been incurred.
tradeId String Last trade ID
optVal String Option Value, only applicable to OPTION.
pendingCloseOrdLiabVal String The amount of close orders of isolated margin liability.
notionalUsd String Notional value of positions in USD
adl String Auto-Deleveraging (ADL) indicator. Range: 0–5, where 0 = lowest ADL priority (least likely to be forcibly deleveraged) and 5 = highest priority (first in queue if the insurance fund is depleted). Priority increases with higher unrealized profit and higher leverage.
Only applicable to FUTURES/SWAP/OPTION
ccy String Currency used for margin
last String Latest traded price
idxPx String Latest underlying index price
usdPx String Latest USD price of the ccy on the market, only applicable to FUTURES/SWAP/OPTION
bePx String Breakeven price
deltaBS String delta: Black-Scholes Greeks in dollars, only applicable to OPTION
deltaPA String delta: Greeks in coins, only applicable to OPTION
gammaBS String gamma: Black-Scholes Greeks in dollars, only applicable to OPTION
gammaPA String gamma: Greeks in coins, only applicable to OPTION
thetaBS String theta:Black-Scholes Greeks in dollars, only applicable to OPTION
thetaPA String theta:Greeks in coins, only applicable to OPTION
vegaBS String vega:Black-Scholes Greeks in dollars, only applicable to OPTION
vegaPA String vega:Greeks in coins, only applicable to OPTION
spotInUseAmt String Spot in use amount
Applicable to Portfolio margin
spotInUseCcy String Spot in use unit, e.g. BTC
Applicable to Portfolio margin
clSpotInUseAmt String User-defined spot risk offset amount
Applicable to Portfolio margin
maxSpotInUseAmt String Max possible spot risk offset amount
Applicable to Portfolio margin
bizRefId String External business id, e.g. experience coupon id
bizRefType String External business type
realizedPnl String Realized profit and loss
Only applicable to FUTURES/SWAP/OPTION
realizedPnl=pnl+fee+fundingFee+liqPenalty+settledPnl
settledPnl String Accumulated settled profit and loss (calculated by settlement price)
Only applicable to cross FUTURES
pnl String Accumulated pnl of closing order(s) (excluding the fee).
fee String Accumulated fee since the current position was opened. Resets to 0 when the position is fully closed. For per-fill fees, use GET /api/v5/trade/fills.
Negative number represents the user transaction fee charged by the platform. Positive number represents rebate.
fundingFee String Accumulated funding fee
liqPenalty String Accumulated liquidation penalty. It is negative when there is a value.
closeOrderAlgo Array of objects Close position algo orders attached to the position. This array will have values only after you request "Place algo order" with closeFraction=1.
> algoId String Algo ID
> slTriggerPx String Stop-loss trigger price.
> slTriggerPxType String Stop-loss trigger price type.
last: last price
index: index price
mark: mark price
> tpTriggerPx String Take-profit trigger price.
> tpTriggerPxType String Take-profit trigger price type.
last: last price
index: index price
mark: mark price
> closeFraction String Fraction of position to be closed when the algo order is triggered.
cTime String Creation time, Unix timestamp format in milliseconds, e.g. 1597026383085
uTime String Latest time position was adjusted, Unix timestamp format in milliseconds, e.g. 1597026383085

Get positions history

Retrieve the updated position data for the last 3 months. Return in reverse chronological order using utime. Getting positions history is supported under Portfolio margin mode since 04:00 AM (UTC) on November 11, 2024.

Rate Limit: 10 requests per 2 seconds

Rate limit rule: User ID

HTTP Request

GET /api/v5/account/positions-history

Request Example

GET /api/v5/account/positions-history
import okx.Account as Account

# API initialization
apikey = "YOUR_API_KEY"
secretkey = "YOUR_SECRET_KEY"
passphrase = "YOUR_PASSPHRASE"

flag = "1"  # Production trading:0 , demo trading:1

accountAPI = Account.AccountAPI(apikey, secretkey, passphrase, False, flag)

# Get positions history
result = accountAPI.get_positions_history()
print(result)

Request Parameters

Parameter Type Required Description
instType String No Instrument type
MARGIN
SWAP
FUTURES
OPTION
EVENTS
instId String No Instrument ID, e.g. BTC-USD-SWAP
mgnMode String No Margin mode
cross isolated
type String No The type of latest close position
1: Close position partially;2:Close all;3:Liquidation;4:Partial liquidation; 5:ADL - position not fully closed; 6:ADL - position fully closed
It is the latest type if there are several types for the same position.
posId String No Position ID. There is attribute expiration. The posId will be expired if it is more than 30 days after the last full close position, then position will use new posId.
after String No Pagination of data to return records earlier than the requested uTime, Unix timestamp format in milliseconds, e.g. 1597026383085
before String No Pagination of data to return records newer than the requested uTime, Unix timestamp format in milliseconds, e.g. 1597026383085
limit String No Number of results per request. The maximum is 100. The default is 100. All records that have the same uTime will be returned at the current request

Response Example

{
    "code": "0",
    "data": [
        {
            "cTime": "1654177169995",
            "ccy": "BTC",
            "closeAvgPx": "29786.5999999789081085",
            "closeTotalPos": "1",
            "instId": "BTC-USD-SWAP",
            "instType": "SWAP",
            "lever": "10.0",
            "mgnMode": "cross",
            "openAvgPx": "29783.8999999995535393",
            "openMaxPos": "1",
            "realizedPnl": "0.001",
            "fee": "-0.0001",
            "fundingFee": "0",
            "liqPenalty": "0",
            "pnl": "0.0011",
            "pnlRatio": "0.000906447858888",
            "posId": "452587086133239818",
            "posSide": "long",
            "direction": "long",
            "triggerPx": "",
            "type": "1",
            "uTime": "1654177174419",
            "uly": "BTC-USD",
            "nonSettleAvgPx":"",
            "settledPnl":""
        }
    ],
    "msg": ""
}

Response Parameters

Parameter Type Description
instType String Instrument type
MARGIN
SWAP
FUTURES
OPTION
EVENTS
instId String Instrument ID
mgnMode String Margin mode
cross isolated
type String The type of latest close position
1:Close position partially;2:Close all;3:Liquidation;4:Partial liquidation; 5:ADL;
It is the latest type if there are several types for the same position.
cTime String Created time of position
uTime String Updated time of position
openAvgPx String Average price of opening position
Under cross-margin mode, the entry price of expiry futures will update at settlement to the last settlement price, and when the position is opened or increased.
nonSettleAvgPx String Non-settlement entry price
The non-settlement entry price only reflects the average price at which the position is opened or increased.
Only applicable to cross FUTURES
closeAvgPx String Average price of closing position
posId String Position ID
openMaxPos String Max quantity of position
closeTotalPos String Position's cumulative closed volume
realizedPnl String Realized profit and loss
Only applicable to FUTURES/SWAP/OPTION
realizedPnl=pnl+fee+fundingFee+liqPenalty+settledPnl
settledPnl String Accumulated settled profit and loss (calculated by settlement price)
Only applicable to cross FUTURES
pnlRatio String Realized P&L ratio
fee String Accumulated fee
Negative number represents the user transaction fee charged by the platform.Positive number represents rebate.
fundingFee String Accumulated funding fee
liqPenalty String Accumulated liquidation penalty. It is negative when there is a value.
pnl String Profit and loss (excluding the fee).
posSide String Position mode side
long: Hedge mode long
short: Hedge mode short
net: Net mode
lever String Leverage
direction String Direction: long short
Only applicable to MARGIN/FUTURES/SWAP/OPTION
triggerPx String trigger mark price. There is value when type is equal to 3, 4 or 5. It is "" when type is equal to 1 or 2
uly String Underlying
ccy String Currency used for margin

Get account and position risk

Get account and position risk

Rate Limit: 10 requests per 2 seconds

Rate limit rule: User ID

HTTP Request

GET /api/v5/account/account-position-risk

Request Example

GET /api/v5/account/account-position-risk

import okx.Account as Account

# API initialization
apikey = "YOUR_API_KEY"
secretkey = "YOUR_SECRET_KEY"
passphrase = "YOUR_PASSPHRASE"

flag = "1"  # Production trading:0 , demo trading:1

accountAPI = Account.AccountAPI(apikey, secretkey, passphrase, False, flag)

# Get account and position risk
result = accountAPI.get_account_position_risk()
print(result)

Request Parameters

Parameter Type Required Description
instType String No Instrument type
MARGIN
SWAP
FUTURES
OPTION

Response Example

{
    "code":"0",
    "data":[
        {
            "adjEq":"174238.6793649711331679",
            "balData":[
                {
                    "ccy":"BTC",
                    "disEq":"78846.7803721021362242",
                    "eq":"1.3863533369419636"
                },
                {
                    "ccy":"USDT",
                    "disEq":"73417.2495112863300127",
                    "eq":"73323.395564963177146"
                }
            ],
            "posData":[
                {
                    "baseBal": "0.4",
                    "ccy": "",
                    "instId": "BTC-USDT",
                    "instType": "MARGIN",
                    "mgnMode": "isolated",
                    "notionalCcy": "0",
                    "notionalUsd": "0",
                    "pos": "0",
                    "posCcy": "",
                    "posId": "310388685292318723",
                    "posSide": "net",
                    "quoteBal": "0"
                }
            ],
            "ts":"1620282889345"
        }
    ],
    "msg":""
}

Response Parameters

Parameters Types Description
ts String Update time of account information, millisecond format of Unix timestamp, e.g. 1597026383085
adjEq String Adjusted / Effective equity in USD
Applicable to Multi-currency margin and Portfolio margin
balData Array of objects Detailed asset information in all currencies
> ccy String Currency
> eq String Equity of currency
> disEq String Discount equity of currency in USD.
posData Array of objects Detailed position information in all currencies
> instType String Instrument type
> mgnMode String Margin mode
cross
isolated
> posId String Position ID
> instId String Instrument ID, e.g. BTC-USDT-SWAP
> pos String Quantity of positions contract. In the isolated margin mode, when doing manual transfers, a position with pos of 0 will be generated after the deposit is transferred
> baseBal String Base currency balance, only applicable to MARGIN(Quick Margin ModeοΌ‰(Deprecated)
> quoteBal String Quote currency balance, only applicable to MARGIN(Quick Margin ModeοΌ‰(Deprecated)
> posSide String Position side
long
short
net (FUTURES/SWAP/OPTION: positive pos means long position and negative pos means short position. MARGIN: posCcy being base currency means long position, posCcy being quote currency means short position.)
> posCcy String Position currency, only applicable to MARGIN positions.
> ccy String Currency used for margin
> notionalCcy String Notional value of positions in coin
> notionalUsd String Notional value of positions in USD

Get bills details (last 7 days)

Retrieve the bills of the account. The bill refers to all transaction records that result in changing the balance of an account. Pagination is supported, and the response is sorted with the most recent first. This endpoint can retrieve data from the last 7 days.

Rate Limit: 5 requests per second

Rate limit rule: User ID

HTTP Request

GET /api/v5/account/bills

Request Example

GET /api/v5/account/bills

GET /api/v5/account/bills?instType=MARGIN

import okx.Account as Account

# API initialization
apikey = "YOUR_API_KEY"
secretkey = "YOUR_SECRET_KEY"
passphrase = "YOUR_PASSPHRASE"

flag = "1"  # Production trading:0 , demo trading:1

accountAPI = Account.AccountAPI(apikey, secretkey, passphrase, False, flag)

# Get bills details (last 7 days)
result = accountAPI.get_account_bills()
print(result)

Request Parameters

Parameter Type Required Description
instType String No Instrument type
SPOT
MARGIN
SWAP
FUTURES
OPTION
EVENTS
instId String No Instrument ID, e.g. BTC-USDT
ccy String No Bill currency
mgnMode String No Margin mode
isolated
cross
ctType String No Contract type
linear
inverse
Only applicable to FUTURES/SWAP
type String No Bill type
Please refer to Get bill types for the list of available types.
subType String No Bill subtype
Please refer to Get bill types for the list of available types.
after String No Pagination of data to return records earlier than the requested bill ID.
before String No Pagination of data to return records newer than the requested bill ID.
begin String No Filter with a begin timestamp ts. Unix timestamp format in milliseconds, e.g. 1597026383085
end String No Filter with an end timestamp ts. Unix timestamp format in milliseconds, e.g. 1597026383085
limit String No Number of results per request. The maximum is 100. The default is 100.

Response Example

{
    "code": "0",
    "msg": "",
    "data": [{
        "bal": "8694.2179403378290202",
        "balChg": "0.0219338232210000",
        "billId": "623950854533513219",
        "ccy": "USDT",
        "clOrdId": "",
        "earnAmt": "",
        "earnApr": "",
        "execType": "T",
        "fee": "-0.000021955779",
        "fillFwdPx": "",
        "fillIdxPx": "27104.1",
        "fillMarkPx": "",
        "fillMarkVol": "",
        "fillPxUsd": "",
        "fillPxVol": "",
        "fillTime": "1695033476166",
        "from": "",
        "instId": "BTC-USDT",
        "instType": "SPOT",
        "interest": "0",
        "mgnMode": "isolated",
        "notes": "",
        "ordId": "623950854525124608",
        "pnl": "0",
        "posBal": "0",
        "posBalChg": "0",
        "px": "27105.9",
        "subType": "1",
        "sz": "0.021955779",
        "tag": "",
        "to": "",
        "tradeId": "586760148",
        "ts": "1695033476167",
        "type": "2"
    }]
} 

Response Parameters

Parameter Type Description
instType String Instrument type
billId String Bill ID
type String Bill type
subType String Bill subtype
ts String The time when the balance complete update, Unix timestamp format in milliseconds, e.g.1597026383085
balChg String Signed change in account balance for this event, in the currency specified by the ccy field. Positive: balance increased (e.g., received funding fee rebate, closed profitable trade). Negative: balance decreased (e.g., paid trading fee, settled a loss).
posBalChg String Change in balance amount at the position level
bal String Balance at the account level
posBal String Balance at the position level
sz String Quantity
For FUTURES/SWAP/OPTION, it is fill quantity or position quantity, the unit is contract. The value is always positive.
For other scenarios. the unit is account balance currency(ccy).
px String Price which related to subType
  • Trade filled price for
  • 1: Buy 2: Sell 3: Open long 4: Open short 5: Close long 6: Close short 204: block trade buy 205: block trade sell 206: block trade open long 207: block trade open short 208: block trade close long 209: block trade close short 114: Forced repayment buy 115: Forced repayment sell
  • Liquidation Price for
  • 100: Partial liquidation close long 101: Partial liquidation close short 102: Partial liquidation buy 103: Partial liquidation sell 104: Liquidation long 105: Liquidation short 106: Liquidation buy 107: Liquidation sell 16: Repay forcibly 17: Repay interest by borrowing forcibly 110: Liquidation transfer in 111: Liquidation transfer out
  • Delivery price for
  • 112: Delivery long 113: Delivery short
  • Exercise price for
  • 170: Exercised 171: Counterparty exercised 172: Expired OTM
  • Mark price for
  • 173: Funding fee expense 174: Funding fee income
    ccy String Account balance currency
    pnl String Profit and loss
    fee String Fee
    Negative number represents the user transaction fee charged by the platform.
    Positive number represents rebate.
    Trading fee rule
    earnAmt String Auto earn amount
    Only applicable when type is 381
    earnApr String Auto earn APR
    Only applicable when type is 381
    mgnMode String Margin mode
    isolated cross cash
    When bills are not generated by trading, the field returns ""
    instId String Instrument ID, e.g. BTC-USDT
    ordId String Order ID
    Return order ID when the type is 2/5/9
    Return "" when there is no order.
    execType String Liquidity taker or maker
    T: taker
    M: maker
    from String The remitting account
    6: Funding account
    18: Trading account
    Only applicable to transfer. When bill type is not transfer, the field returns "".
    to String The beneficiary account
    6: Funding account
    18: Trading account
    Only applicable to transfer. When bill type is not transfer, the field returns "".
    notes String Notes
    interest String Interest
    tag String Order tag
    fillTime String Last filled time
    tradeId String Last traded ID
    clOrdId String Client Order ID as assigned by the client
    A combination of case-sensitive alphanumerics, all numbers, or all letters of up to 32 characters.
    fillIdxPx String Index price at the moment of trade execution
    For cross currency spot pairs, it returns baseCcy-USDT index price. For example, for LTC-ETH, this field returns the index price of LTC-USDT.
    fillMarkPx String Mark price when filled
    Applicable to FUTURES/SWAP/OPTIONS, return "" for other instrument types
    fillPxVol String Implied volatility when filled
    Only applicable to options; return "" for other instrument types
    fillPxUsd String Options price when filled, in the unit of USD
    Only applicable to options; return "" for other instrument types
    fillMarkVol String Mark volatility when filled
    Only applicable to options; return "" for other instrument types
    fillFwdPx String Forward price when filled
    Only applicable to options; return "" for other instrument types

    Get bills details (last 3 months)

    Retrieve the account’s bills. The bill refers to all transaction records that result in changing the balance of an account. Pagination is supported, and the response is sorted with most recent first. This endpoint can retrieve data from the last 3 months.

    Rate Limit: 5 requests per 2 seconds

    Rate limit rule: User ID

    HTTP Request

    GET /api/v5/account/bills-archive

    Request Example

    GET /api/v5/account/bills-archive
    
    GET /api/v5/account/bills-archive?instType=MARGIN
    
    
    import okx.Account as Account
    
    # API initialization
    apikey = "YOUR_API_KEY"
    secretkey = "YOUR_SECRET_KEY"
    passphrase = "YOUR_PASSPHRASE"
    
    flag = "1"  # Production trading:0 , demo trading:1
    
    accountAPI = Account.AccountAPI(apikey, secretkey, passphrase, False, flag)
    
    # Get bills details (last 3 months)
    result = accountAPI.get_account_bills_archive()
    print(result)
    

    Request Parameters

    Parameter Type Required Description
    instType String No Instrument type
    SPOT
    MARGIN
    SWAP
    FUTURES
    OPTION
    EVENTS
    instId String No Instrument ID, e.g. BTC-USDT
    ccy String No Bill currency
    mgnMode String No Margin mode
    isolated
    cross
    ctType String No Contract type
    linear
    inverse
    Only applicable to FUTURES/SWAP
    type String No Bill type
    Please refer to Get bill types for the list of available types.
    subType String No Bill subtype
    Please refer to Get bill types for the list of available types.
    after String No Pagination of data to return records earlier than the requested bill ID.
    before String No Pagination of data to return records newer than the requested bill ID.
    begin String No Filter with a begin timestamp ts. Unix timestamp format in milliseconds, e.g. 1597026383085
    end String No Filter with an end timestamp ts. Unix timestamp format in milliseconds, e.g. 1597026383085
    limit String No Number of results per request. The maximum is 100. The default is 100.

    Response Example

    {
        "code": "0",
        "msg": "",
        "data": [{
            "bal": "8694.2179403378290202",
            "balChg": "0.0219338232210000",
            "billId": "623950854533513219",
            "ccy": "USDT",
            "clOrdId": "",
            "earnAmt": "",
            "earnApr": "",
            "execType": "T",
            "fee": "-0.000021955779",
            "fillFwdPx": "",
            "fillIdxPx": "27104.1",
            "fillMarkPx": "",
            "fillMarkVol": "",
            "fillPxUsd": "",
            "fillPxVol": "",
            "fillTime": "1695033476166",
            "from": "",
            "instId": "BTC-USDT",
            "instType": "SPOT",
            "interest": "0",
            "mgnMode": "isolated",
            "notes": "",
            "ordId": "623950854525124608",
            "pnl": "0",
            "posBal": "0",
            "posBalChg": "0",
            "px": "27105.9",
            "subType": "1",
            "sz": "0.021955779",
            "tag": "",
            "to": "",
            "tradeId": "586760148",
            "ts": "1695033476167",
            "type": "2"
        }]
    } 
    

    Response Parameters

    Parameter Type Description
    instType String Instrument type
    billId String Bill ID
    type String Bill type
    subType String Bill subtype
    ts String The time when the balance complete update, Unix timestamp format in milliseconds, e.g.1597026383085
    balChg String Change in balance amount at the account level
    posBalChg String Change in balance amount at the position level
    bal String Balance at the account level
    posBal String Balance at the position level
    sz String Quantity
    For FUTURES/SWAP/OPTION, it is fill quantity or position quantity, the unit is contract. The value is always positive.
    For other scenarios. the unit is account balance currency(ccy).
    px String Price which related to subType
  • Trade filled price for
  • 1: Buy 2: Sell 3: Open long 4: Open short 5: Close long 6: Close short 204: block trade buy 205: block trade sell 206: block trade open long 207: block trade open short 208: block trade close long 209: block trade close short 114: Forced repayment buy 115: Forced repayment sell
  • Liquidation Price for
  • 100: Partial liquidation close long 101: Partial liquidation close short 102: Partial liquidation buy 103: Partial liquidation sell 104: Liquidation long 105: Liquidation short 106: Liquidation buy 107: Liquidation sell 16: Repay forcibly 17: Repay interest by borrowing forcibly 110: Liquidation transfer in 111: Liquidation transfer out
  • Delivery price for
  • 112: Delivery long 113: Delivery short
  • Exercise price for
  • 170: Exercised 171: Counterparty exercised 172: Expired OTM
  • Mark price for
  • 173: Funding fee expense 174: Funding fee income
    ccy String Account balance currency
    pnl String Profit and loss
    fee String Fee
    Negative number represents the user transaction fee charged by the platform.
    Positive number represents rebate.
    Trading fee rule
    earnAmt String Auto earn amount
    Only applicable when type is 381
    earnApr String Auto earn APR
    Only applicable when type is 381
    mgnMode String Margin mode
    isolated cross cash
    When bills are not generated by trading, the field returns ""
    instId String Instrument ID, e.g. BTC-USDT
    ordId String Order ID
    Return order ID when the type is 2/5/9
    Return "" when there is no order.
    execType String Liquidity taker or maker
    T: taker M: maker
    from String The remitting account
    6: Funding account
    18: Trading account
    Only applicable to transfer. When bill type is not transfer, the field returns "".
    to String The beneficiary account
    6: Funding account
    18: Trading account
    Only applicable to transfer. When bill type is not transfer, the field returns "".
    notes String Notes
    interest String Interest
    tag String Order tag
    fillTime String Last filled time
    tradeId String Last traded ID
    clOrdId String Client Order ID as assigned by the client
    A combination of case-sensitive alphanumerics, all numbers, or all letters of up to 32 characters.
    fillIdxPx String Index price at the moment of trade execution
    For cross currency spot pairs, it returns baseCcy-USDT index price. For example, for LTC-ETH, this field returns the index price of LTC-USDT.
    fillMarkPx String Mark price when filled
    Applicable to FUTURES/SWAP/OPTIONS, return "" for other instrument types
    fillPxVol String Implied volatility when filled
    Only applicable to options; return "" for other instrument types
    fillPxUsd String Options price when filled, in the unit of USD
    Only applicable to options; return "" for other instrument types
    fillMarkVol String Mark volatility when filled
    Only applicable to options; return "" for other instrument types
    fillFwdPx String Forward price when filled
    Only applicable to options; return "" for other instrument types

    Apply bills details (since 2021)

    Apply for bill data since 1 February, 2021 except for the current quarter.

    Rate Limit: 1 request per 10 seconds

    Rate limit rule: User ID

    HTTP Request

    POST /api/v5/account/bills-history-archive

    Request Example

    POST /api/v5/account/bills-history-archive
    body
    {
        "year":"2023",
        "quarter":"Q1"
    }
    

    Request Parameters

    Parameter Type Required Description
    year String Yes 4 digits year
    quarter String Yes Quarter, valid value is Q1, Q2, Q3, Q4
    type String No Bill type. Multiple values are supported, separated by commas, e.g. 1,2,3. If not specified, all types are returned.
    Please refer to Get bill types for the list of available types.

    Response Example

    {
        "code": "0",
        "data": [
            {
                "result": "true",
                "ts": "1646892328000"
            }
        ],
        "msg": ""
    }
    

    Response Parameters

    Parameter Type Description
    result String Whether there is already a download link for this section
    true: Existed, can check from "Get bills details (since 2021)".
    false: Does not exist and is generating, can check the download link after 2 hours
    The data of file is in reverse chronological order using billId.
    ts String The first request time when the server receives. Unix timestamp format in milliseconds, e.g. 1597026383085

    Get bills details (since 2021)

    Apply for bill data since 1 February, 2021 except for the current quarter.

    Rate Limit: 10 requests per 2 seconds

    Rate limit rule: User ID

    HTTP Request

    GET /api/v5/account/bills-history-archive

    Response Example

    GET /api/v5/account/bills-history-archive?year=2023&quarter=Q4
    
    

    Request Parameters

    Parameter Type Required Description
    year String Yes 4 digits year
    quarter String Yes Quarter, valid value is Q1, Q2, Q3, Q4
    type String No Bill type. Multiple values are supported, separated by commas, e.g. 1,2,3. If not specified, all types are returned.
    Please refer to Get bill types for the list of available types.

    Response Example

    {
        "code": "0",
        "data": [
            {
                "fileHref": "http://xxx",
                "state": "finished",
                "ts": "1646892328000"
            }
        ],
        "msg": ""
    }
    

    Response Parameters

    Parameter Type Description
    fileHref String Download file link.
    The expiration of every link is 5 and a half hours. If you already apply the files for the same quarter, then it don’t need to apply again within 30 days.
    ts String The first request time when the server receives. Unix timestamp format in milliseconds, e.g. 1597026383085
    state String Download link status
    "finished" "ongoing" "failed": Failed, please apply again

    Field descriptions in the decompressed CSV file

    Parameter Type Description
    instType String Instrument type
    billId String Bill ID
    subType String Bill subtype
    ts String The time when the balance complete update, Unix timestamp format in milliseconds, e.g.1597026383085
    balChg String Change in balance amount at the account level
    posBalChg String Change in balance amount at the position level
    bal String Balance at the account level
    posBal String Balance at the position level
    sz String Quantity
    px String Price which related to subType
  • Trade filled price for
  • 1: Buy 2: Sell 3: Open long 4: Open short 5: Close long 6: Close short 204: block trade buy 205: block trade sell 206: block trade open long 207: block trade open short 208: block trade close long 209: block trade close short 114: Forced repayment buy 115: Forced repayment sell
  • Liquidation Price for
  • 100: Partial liquidation close long 101: Partial liquidation close short 102: Partial liquidation buy 103: Partial liquidation sell 104: Liquidation long 105: Liquidation short 106: Liquidation buy 107: Liquidation sell 16: Repay forcibly 17: Repay interest by borrowing forcibly 110: Liquidation transfer in 111: Liquidation transfer out
  • Delivery price for
  • 112: Delivery long 113: Delivery short
  • Exercise price for
  • 170: Exercised 171: Counterparty exercised 172: Expired OTM
  • Mark price for
  • 173: Funding fee expense 174: Funding fee income
    ccy String Account balance currency
    pnl String Profit and loss
    fee String Fee
    Negative number represents the user transaction fee charged by the platform.
    Positive number represents rebate.
    Trading fee rule
    mgnMode String Margin mode
    isolated cross cash
    When bills are not generated by trading, the field returns ""
    instId String Instrument ID, e.g. BTC-USDT
    ordId String Order ID
    Return order ID when the type is 2/5/9
    Return "" when there is no order.
    execType String Liquidity taker or maker
    T: taker M: maker
    interest String Interest
    tag String Order tag
    fillTime String Last filled time
    tradeId String Last traded ID
    clOrdId String Client Order ID as assigned by the client
    A combination of case-sensitive alphanumerics, all numbers, or all letters of up to 32 characters.
    fillIdxPx String Index price at the moment of trade execution
    For cross currency spot pairs, it returns baseCcy-USDT index price. For example, for LTC-ETH, this field returns the index price of LTC-USDT.
    fillMarkPx String Mark price when filled
    Applicable to FUTURES/SWAP/OPTIONS, return "" for other instrument types
    fillPxVol String Implied volatility when filled
    Only applicable to options; return "" for other instrument types
    fillPxUsd String Options price when filled, in the unit of USD
    Only applicable to options; return "" for other instrument types
    fillMarkVol String Mark volatility when filled
    Only applicable to options; return "" for other instrument types
    fillFwdPx String Forward price when filled
    Only applicable to options; return "" for other instrument types

    Get bill types

    Get all bill types, and the mapping of bill type and subType.

    Rate limit: 20 requests per 2 seconds

    Rate limit rule: UserId

    HTTP request

    GET /api/v5/account/subtypes

    Request example

    GET /api/v5/account/subtypes
    

    Request parameters

    Parameter Type Required Description
    type String No Bill type. Multiple values are supported, separated by commas, e.g. 1,2,3. If not specified, all types are returned.

    Response example

    {
        "code": "0",
        "data": [
            {
                "type": "1",
                "typeDesc": "Transfer",
                "subTypeDetails": [
                    {
                        "subType": "11",
                        "subTypeDesc": "Transfer in"
                    },
                    {
                        "subType": "12",
                        "subTypeDesc": "Transfer out"
                    }
                ]
            }
        ],
        "msg": ""
    }
    

    Response parameters

    Parameter Type Description
    type String Bill type
    typeDesc String Bill type description, "" means the type is not enabled.
    subTypeDetails Array of objects Sub-type details
    > subType String Sub-type
    > subTypeDesc String Sub-type description, "" means the type is not enabled.

    Get account configuration

    Retrieve current account configuration.

    Rate Limit: 5 requests per 2 seconds

    Rate limit rule: User ID

    HTTP Request

    GET /api/v5/account/config

    Request Example

    GET /api/v5/account/config
    
    
    import okx.Account as Account
    
    # API initialization
    apikey = "YOUR_API_KEY"
    secretkey = "YOUR_SECRET_KEY"
    passphrase = "YOUR_PASSPHRASE"
    
    flag = "1"  # Production trading:0 , demo trading:1
    
    accountAPI = Account.AccountAPI(apikey, secretkey, passphrase, False, flag)
    
    # Retrieve current account configuration
    result = accountAPI.get_account_config()
    print(result)
    

    Request Parameters

    none

    Response Example

    {
        "code": "0",
        "data": [
            {
                "acctLv": "2",
                "acctStpMode": "cancel_maker",
                "autoLoan": false,
                "ctIsoMode": "automatic",
                "enableSpotBorrow": false,
                "greeksType": "PA",
                "feeType": "0",
                "ip": "",
                "type": "0",
                "kycLv": "3",
                "label": "v5 test",
                "level": "Lv1",
                "levelTmp": "",
                "liquidationGear": "-1",
                "mainUid": "44705892343619584",
                "mgnIsoMode": "automatic",
                "opAuth": "1",
                "perm": "read_only,withdraw,trade",
                "posMode": "long_short_mode",
                "roleType": "0",
                "spotBorrowAutoRepay": false,
                "spotOffsetType": "",
                "spotRoleType": "0",
                "spotTraderInsts": [],
                "stgyType": "0",
                "traderInsts": [],
                "uid": "44705892343619584",
                "settleCcy": "USDC",
                "settleCcyList": ["USD", "USDC", "USDG"]
            }
        ],
        "msg": ""
    }
    

    Response Parameters

    Parameter Type Description
    uid String Account ID of current request.
    mainUid String Main Account ID of current request.
    The current request account is main account if uid = mainUid.
    The current request account is sub-account if uid != mainUid.
    acctLv String Account mode
    1: Spot mode
    2: Futures mode
    3: Multi-currency margin
    4: Portfolio margin
    acctStpMode String Account self-trade prevention mode
    cancel_maker
    cancel_taker
    cancel_both
    The default value is cancel_maker. Users can log in to the webpage through the master account to modify this configuration
    posMode String Position mode
    long_short_mode: long/short, only applicable to FUTURES/SWAP
    net_mode: net
    autoLoan Boolean Whether to borrow coins automatically
    true: borrow coins automatically
    false: not borrow coins automatically
    greeksType String Current display type of Greeks
    PA: Greeks in coins
    BS: Black-Scholes Greeks in dollars
    feeType String Fee type
    0: fee is charged in the currency you receive from the trade
    1: fee is always charged in the quote currency of the trading pair
    level String The user level of the current real trading volume on the platform, e.g Lv1, which means regular user level.
    levelTmp String Temporary experience user level of special users, e.g Lv1
    ctIsoMode String Contract isolated margin trading settings
    automatic: Auto transfers
    autonomy: Manual transfers
    mgnIsoMode String Margin isolated margin trading settings
    auto_transfers_ccy: New auto transfers, enabling both base and quote currency as the margin for isolated margin trading
    automatic: Auto transfers
    quick_margin: Quick Margin Mode (For new accounts, including subaccounts, some defaults will be automatic, and others will be quick_margin)
    spotOffsetType String Risk offset type
    1: Spot-Derivatives(USDT) to be offsetted
    2: Spot-Derivatives(Coin) to be offsetted
    3: Only derivatives to be offsetted
    Only applicable to Portfolio margin

    (Deprecated)
    stgyType String Strategy type
    0: general strategy
    1: delta neutral strategy
    roleType String Role type
    0: General user
    1: Leading trader
    2: Copy trader
    traderInsts Array of strings Leading trade instruments, only applicable to Leading trader
    spotRoleType String SPOT copy trading role type.
    0: General userοΌ›1: Leading traderοΌ›2: Copy trader
    spotTraderInsts Array of strings Spot lead trading instruments, only applicable to lead trader
    opAuth String Whether the optional trading was activated
    0: not activate
    1: activated
    kycLv String Main account KYC level
    0: No verification
    1: level 1 completed
    2: level 2 completed
    3: level 3 completed
    If the request originates from a subaccount, kycLv is the KYC level of the main account.
    If the request originates from the main account, kycLv is the KYC level of the current account.
    label String API key note of current request API key. No more than 50 letters (case sensitive) or numbers, which can be pure letters or pure numbers.
    ip String IP addresses that linked with current API key, separate with commas if more than one, e.g. 117.37.203.58,117.37.203.57. It is an empty string "" if there is no IP bonded.
    perm String The permission of the current requesting API key or Access token
    read_only: Read
    trade: Trade
    withdraw: Withdraw
    liquidationGear String The maintenance margin ratio level of liquidation alert
    3 and -1 means that you will get hourly liquidation alerts on app and channel "Position risk warning" when your margin level drops to or below 300%. -1 is the initial value which has the same effect as -3
    0 means that there is not alert
    enableSpotBorrow Boolean Whether borrow is allowed or not in Spot mode
    true: Enabled
    false: Disabled
    spotBorrowAutoRepay Boolean Whether auto-repay is allowed or not in Spot mode
    true: Enabled
    false: Disabled
    type String Account type
    0: Main account
    1: Standard sub-account
    2: Managed trading sub-account
    5: Custody trading sub-account - Copper
    9: Managed trading sub-account - Copper
    12: Custody trading sub-account - Komainu
    settleCcy String Current account's USD-margined contract settle currency
    settleCcyList String Current account's USD-margined contract settle currency list, like ["USD", "USDC", "USDG"].

    Set position mode

    Futures mode and Multi-currency mode: FUTURES and SWAP support both long/short mode and net mode. In net mode, users can only have positions in one direction; In long/short mode, users can hold positions in long and short directions.
    Portfolio margin mode: FUTURES and SWAP only support net mode

    Rate Limit: 5 requests per 2 seconds

    Rate limit rule: User ID

    HTTP Request

    POST /api/v5/account/set-position-mode

    Request Example

    POST /api/v5/account/set-position-mode
    body 
    {
        "posMode":"long_short_mode"
    }
    
    
    import okx.Account as Account
    
    # API initialization
    apikey = "YOUR_API_KEY"
    secretkey = "YOUR_SECRET_KEY"
    passphrase = "YOUR_PASSPHRASE"
    
    flag = "1"  # Production trading:0 , demo trading:1
    
    accountAPI = Account.AccountAPI(apikey, secretkey, passphrase, False, flag)
    
    # Set position mode
    result = accountAPI.set_position_mode(
        posMode="long_short_mode"
    )
    print(result)
    

    Request Parameters

    Parameter Type Required Description
    posMode String Yes Position mode
    long_short_mode: long/short, only applicable to FUTURES/SWAP
    net_mode: net

    Response Example

    {
        "code": "0",
        "msg": "",
        "data": [{
            "posMode": "long_short_mode"
        }]
    }
    

    Response Parameters

    Parameter Type Description
    posMode String Position mode

    Set leverage


    There are 10 different scenarios for leverage setting:

    1. Set leverage for MARGIN instruments under isolated-margin trade mode at pairs level.
    2. Set leverage for MARGIN instruments under cross-margin trade mode and Spot mode (enabled borrow) at currency level.
    3. Set leverage for MARGIN instruments under cross-margin trade mode and Futures mode account mode at pairs level.
    4. Set leverage for MARGIN instruments under cross-margin trade mode and Multi-currency margin at currency level.
    5. Set leverage for MARGIN instruments under cross-margin trade mode and Portfolio margin at currency level.
    6. Set leverage for FUTURES instruments under cross-margin trade mode at underlying level.
    7. Set leverage for FUTURES instruments under isolated-margin trade mode and buy/sell position mode at contract level.
    8. Set leverage for FUTURES instruments under isolated-margin trade mode and long/short position mode at contract and position side level.
    9. Set leverage for SWAP instruments under cross-margin trade at contract level.
    10. Set leverage for SWAP instruments under isolated-margin trade mode and buy/sell position mode at contract level.
    11. Set leverage for SWAP instruments under isolated-margin trade mode and long/short position mode at contract and position side level.

    Note that the request parameter posSide is only required when margin mode is isolated in long/short position mode for FUTURES/SWAP instruments (see scenario 8 and 11 above).
    Please refer to the request examples on the right for each case.

    Rate limit: 20 requests per 2 seconds

    Rate limit rule: User ID

    HTTP Request

    POST /api/v5/account/set-leverage

    Request Example

    # 1. Set leverage for `MARGIN` instruments under `isolated-margin` trade mode at pairs level.
    POST /api/v5/account/set-leverage
    body
    {
        "instId":"BTC-USDT",
        "lever":"5",
        "mgnMode":"isolated"
    }
    
    # 2. Set leverage for `MARGIN` instruments under `cross-margin` trade mode and Spot mode (enabled borrow) at currency level.
    POST /api/v5/account/set-leverage
    body
    {
        "ccy":"BTC",
        "lever":"5",
        "mgnMode":"cross"
    }
    
    # 3. Set leverage for `MARGIN` instruments under `cross-margin` trade mode and Futures mode account mode at pairs level.
    POST /api/v5/account/set-leverage
    body
    {
        "instId":"BTC-USDT",
        "lever":"5",
        "mgnMode":"cross"
    }
    
    # 4. Set leverage for `MARGIN` instruments under `cross-margin` trade mode and Multi-currency margin at currency level.
    POST /api/v5/account/set-leverage
    body
    {
        "ccy":"BTC",
        "lever":"5",
        "mgnMode":"cross"
    }
    
    # 5. Set leverage for `MARGIN` instruments under `cross-margin` trade mode and Portfolio margin at currency level.
    POST /api/v5/account/set-leverage
    body
    {
        "ccy":"BTC",
        "lever":"5",
        "mgnMode":"cross"
    }
    
    # 6. Set leverage for `FUTURES` instruments under `cross-margin` trade mode at underlying level.
    POST /api/v5/account/set-leverage
    body
    {
        "instId":"BTC-USDT-200802",
        "lever":"5",
        "mgnMode":"cross"
    }
    
    # 7. Set leverage for `FUTURES` instruments under `isolated-margin` trade mode and buy/sell order placement mode at contract level.
    POST /api/v5/account/set-leverage
    body
    {
        "instId":"BTC-USDT-200802",
        "lever":"5",
        "mgnMode":"isolated"
    }
    
    # 8. Set leverage for `FUTURES` instruments under `isolated-margin` trade mode and long/short order placement mode at contract and position side level.
    POST /api/v5/account/set-leverage
    body
    {
        "instId":"BTC-USDT-200802",
        "lever":"5",
        "posSide":"long",
        "mgnMode":"isolated"
    }
    
    # 9. Set leverage for `SWAP` instruments under `cross-margin` trade at contract level.
    POST /api/v5/account/set-leverage
    body
    {
        "instId":"BTC-USDT-SWAP",
        "lever":"5",
        "mgnMode":"cross"
    }
    
    # 10. Set leverage for `SWAP` instruments under `isolated-margin` trade mode and buy/sell order placement mode at contract level.
    POST /api/v5/account/set-leverage
    body
    {
        "instId":"BTC-USDT-SWAP",
        "lever":"5",
        "mgnMode":"isolated"
    }
    
    # 11. Set leverage for `SWAP` instruments under `isolated-margin` trade mode and long/short order placement mode at contract and position side level.
    POST /api/v5/account/set-leverage
    body
    {
        "instId":"BTC-USDT-SWAP",
        "lever":"5",
        "posSide":"long",
        "mgnMode":"isolated"
    }
    
    import okx.Account as Account
    
    # API initialization
    apikey = "YOUR_API_KEY"
    secretkey = "YOUR_SECRET_KEY"
    passphrase = "YOUR_PASSPHRASE"
    
    flag = "1"  # Production trading:0 , demo trading:1
    
    accountAPI = Account.AccountAPI(apikey, secretkey, passphrase, False, flag)
    
    # Set leverage for MARGIN instruments under isolated-margin trade mode at pairs level.
    result = accountAPI.set_leverage(
        instId="BTC-USDT",
        lever="5",
        mgnMode="isolated"
    )
    print(result)
    

    Request Parameters

    Parameter Type Required Description
    instId String Conditional Instrument ID
    Only applicable to cross FUTURES SWAP of Spot mode/Multi-currency margin/Portfolio margin, cross MARGINFUTURESSWAP and isolated position.
    And required in applicable scenarios.
    ccy String Conditional Currency used for margin, used for the leverage setting for the currency in auto borrow.
    Only applicable to cross MARGIN of Spot mode/Multi-currency margin/Portfolio margin.
    And required in applicable scenarios.
    lever String Yes Leverage
    mgnMode String Yes Margin mode
    isolated cross
    Can only be cross if ccy is passed.
    posSide String Conditional Position side
    long short
    Only required when margin mode is isolated in long/short mode for FUTURES/SWAP.

    Response Example

    {
      "code": "0",
      "msg": "",
      "data": [
        {
          "lever": "30",
          "mgnMode": "isolated",
          "instId": "BTC-USDT-SWAP",
          "posSide": "long"
        }
      ]
    }
    

    Response Parameters

    Parameter Type Description
    lever String Leverage
    mgnMode String Margin mode
    cross isolated
    instId String Instrument ID
    posSide String Position side

    Get maximum order quantity

    The maximum quantity to buy or sell. It corresponds to the "sz" from placement.

    Rate Limit: 20 requests per 2 seconds

    Rate limit rule: User ID

    HTTP Request

    GET /api/v5/account/max-size

    Request Example

    GET /api/v5/account/max-size?instId=BTC-USDT&tdMode=isolated
    
    
    import okx.Account as Account
    
    # API initialization
    apikey = "YOUR_API_KEY"
    secretkey = "YOUR_SECRET_KEY"
    passphrase = "YOUR_PASSPHRASE"
    
    flag = "1"  # Production trading:0 , demo trading:1
    
    accountAPI = Account.AccountAPI(apikey, secretkey, passphrase, False, flag)
    
    # Get maximum buy/sell amount or open amount
    result = accountAPI.get_max_order_size(
        instId="BTC-USDT",
        tdMode="isolated"
    )
    print(result)
    

    Request Parameters

    Parameter Type Required Description
    instId String Yes Single instrument or multiple instruments (no more than 5) in the same instrument type separated with comma, e.g. BTC-USDT,ETH-USDT
    tdMode String Yes Trade mode
    cross
    isolated
    cash
    spot_isolated: only applicable to Futures mode.
    ccy String Conditional Currency used for margin
    Applicable to isolated MARGIN and cross MARGIN orders in Futures mode.
    px String No Price
    When the price is not specified, it will be calculated according to the current limit price for FUTURES and SWAP, the last traded price for other instrument types.
    The parameter will be ignored when multiple instruments are specified.
    leverage String No Leverage for instrument
    The default is current leverage
    Only applicable to MARGIN/FUTURES/SWAP
    tradeQuoteCcy String No The quote currency used for trading. Only applicable to SPOT.
    The default value is the quote currency of the instId, for example: for BTC-USD, the default is USD.
    outcome String No Market outcome to trade on.
    yes
    no
    Only applicable and optional for EVENTS, the default value is yes

    Response Example

    {
        "code": "0",
        "msg": "",
        "data": [{
            "ccy": "BTC",
            "instId": "BTC-USDT",
            "maxBuy": "0.0500695098559788",
            "maxSell": "64.4798671570072269"
      }]
    }
    

    Response Parameters

    Parameter Type Description
    instId String Instrument ID
    ccy String Currency used for margin
    maxBuy String SPOT/MARGIN: The maximum quantity in base currency that you can buy
    The cross-margin order under Futures mode mode, quantity of coins is based on base currency.
    FUTURES/SWAP/OPTIONS: The maximum quantity of contracts that you can buy
    maxSell String SPOT/MARGIN: The maximum quantity in quote currency that you can sell
    The cross-margin order under Futures mode mode, quantity of coins is based on base currency.
    FUTURES/SWAP/OPTIONS: The maximum quantity of contracts that you can sell

    Get maximum available balance/equity

    Available balance for isolated margin positions and SPOT, available equity for cross margin positions.

    Rate Limit: 20 requests per 2 seconds

    Rate limit rule: User ID

    HTTP Request

    GET /api/v5/account/max-avail-size

    Request Example

    # Query maximum available transaction amount when cross MARGIN BTC-USDT use BTC as margin
    GET /api/v5/account/max-avail-size?instId=BTC-USDT&tdMode=cross&ccy=BTC
    
    # Query maximum available transaction amount for SPOT BTC-USDT
    GET /api/v5/account/max-avail-size?instId=BTC-USDT&tdMode=cash
    
    
    import okx.Account as Account
    
    # API initialization
    apikey = "YOUR_API_KEY"
    secretkey = "YOUR_SECRET_KEY"
    passphrase = "YOUR_PASSPHRASE"
    
    flag = "1"  # Production trading:0 , demo trading:1
    
    accountAPI = Account.AccountAPI(apikey, secretkey, passphrase, False, flag)
    
    # Get maximum available transaction amount for SPOT BTC-USDT
    result = accountAPI.get_max_avail_size(
        instId="BTC-USDT",
        tdMode="cash"
    )
    print(result)
    

    Request Parameters

    Parameter Type Required Description
    instId String Yes Single instrument or multiple instruments (no more than 5) separated with comma, e.g. BTC-USDT,ETH-USDT
    ccy String Conditional Currency used for margin
    Applicable to isolated MARGIN and cross MARGIN in Futures mode.
    tdMode String Yes Trade mode
    cross
    isolated
    cash
    spot_isolated: only applicable to Futures mode
    reduceOnly Boolean No Whether to reduce position only
    Only applicable to MARGIN
    px String No The price of closing position.
    Only applicable to reduceOnly MARGIN.
    tradeQuoteCcy String No The quote currency used for trading. Only applicable to SPOT.
    The default value is the quote currency of the instId, for example: for BTC-USD, the default is USD.

    Response Example

    {
      "code": "0",
      "msg": "",
      "data": [
        {
          "instId": "BTC-USDT",
          "availBuy": "100",
          "availSell": "1"
        }
      ]
    }
    

    Response Parameters

    Parameter Type Description
    instId String Instrument ID
    availBuy String Maximum available balance/equity to buy
    availSell String Maximum available balance/equity to sell

    Increase/decrease margin

    Increase or decrease the margin of the isolated position. Margin reduction may result in the change of the actual leverage.

    Rate Limit: 20 requests per 2 seconds

    Rate limit rule: User ID

    HTTP Request

    POST /api/v5/account/position/margin-balance

    Request Example

    POST /api/v5/account/position/margin-balance 
    body
    {
        "instId":"BTC-USDT-200626",
        "posSide":"short",
        "type":"add",
        "amt":"1"
    }
    
    
    import okx.Account as Account
    
    # API initialization
    apikey = "YOUR_API_KEY"
    secretkey = "YOUR_SECRET_KEY"
    passphrase = "YOUR_PASSPHRASE"
    
    flag = "1"  # Production trading:0 , demo trading:1
    
    accountAPI = Account.AccountAPI(apikey, secretkey, passphrase, False, flag)
    
    # Increase margin
    result = accountAPI.adjustment_margin(
        instId="BTC-USDT-SWAP",
        posSide="short",
        type= "add",
        amt="1"
    )
    print(result)
    

    Request Parameters

    Parameter Type Required Description
    instId String Yes Instrument ID
    posSide String Yes Position side, the default is net
    long
    short
    net
    type String Yes add: add margin
    reduce: reduce margin
    amt String Yes Amount to be increased or decreased.
    ccy String Conditional Currency
    Applicable to isolated MARGIN orders

    Response Example

    {
        "code": "0",
        "msg": "",
        "data": [{
                "amt": "0.3",
                "ccy": "BTC",
                "instId": "BTC-USDT",
                "leverage": "",
                "posSide": "net",
                "type": "add"
            }]
    }
    

    Response Parameters

    Parameter Type Description
    instId String Instrument ID
    posSide String Position side, long short
    amt String Amount to be increase or decrease
    type String add: add margin
    reduce: reduce margin
    leverage String Real leverage after the margin adjustment
    ccy String Currency

    Get leverage

    Rate Limit: 20 requests per 2 seconds

    Rate limit rule: User ID

    HTTP Request

    GET /api/v5/account/leverage-info

    Request Example

    GET /api/v5/account/leverage-info?instId=BTC-USDT-SWAP&mgnMode=cross
    
    
    import okx.Account as Account
    
    # API initialization
    apikey = "YOUR_API_KEY"
    secretkey = "YOUR_SECRET_KEY"
    passphrase = "YOUR_PASSPHRASE"
    
    flag = "1"  # Production trading:0 , demo trading:1
    
    accountAPI = Account.AccountAPI(apikey, secretkey, passphrase, False, flag)
    
    # Get leverage
    result = accountAPI.get_leverage(
        instId="BTC-USDT-SWAP",
        mgnMode="cross"
    )
    print(result)
    

    Request Parameters

    Parameter Type Required Description
    instId String Conditional Instrument ID
    Single instrument ID or multiple instrument IDs (no more than 20) separated with comma
    ccy String Conditional Currency,used for getting leverage of currency level.
    Applicable to cross MARGIN of Spot mode/Multi-currency margin/Portfolio margin.
    Supported single currency or multiple currencies (no more than 20) separated with comma.
    mgnMode String Yes Margin mode
    cross isolated

    Response Example

    {
        "code": "0",
        "msg": "",
        "data": [{
            "ccy":"",
            "instId": "BTC-USDT-SWAP",
            "mgnMode": "cross",
            "posSide": "long",
            "lever": "10"
        },{
            "ccy":"",
            "instId": "BTC-USDT-SWAP",
            "mgnMode": "cross",
            "posSide": "short",
            "lever": "10"
        }]
    }
    

    Response Parameters

    Parameter Type Description
    instId String Instrument ID
    ccy String Currency,used for getting leverage of currency level.
    Applicable to cross MARGIN of Spot mode/Multi-currency margin/Portfolio margin.
    mgnMode String Margin mode
    posSide String Position side
    long
    short
    net
    In long/short mode, the leverage in both directions long/short will be returned.
    lever String Leverage

    Get leverage estimated info

    Rate Limit: 5 requests per 2 seconds

    Rate limit rule: User ID

    HTTP Request

    GET /api/v5/account/adjust-leverage-info

    Request Example

    GET /api/v5/account/adjust-leverage-info?instType=MARGIN&mgnMode=isolated&lever=3&instId=BTC-USDT
    
    

    Request Parameters

    Parameter Type Required Description
    instType String Yes Instrument type
    MARGIN
    SWAP
    FUTURES
    mgnMode String Yes Margin mode
    isolated
    cross
    lever String Yes Leverage
    instId String Conditional Instrument ID, e.g. BTC-USDT
    It is required for these scenarioes: SWAP and FUTURES, Margin isolation, Margin cross in Futures mode.
    ccy String Conditional Currency used for margin, e.g. BTC
    It is required for isolated margin and cross margin in Futures mode, Multi-currency margin and Portfolio margin
    posSide String No posSide
    net: The default value
    long
    short

    Response Example

    {
        "code": "0",
        "data": [
            {
                "estAvailQuoteTrans": "",
                "estAvailTrans": "1.1398040558348279",
                "estLiqPx": "",
                "estMaxAmt": "10.6095865868904898",
                "estMgn": "0.0701959441651721",
                "estQuoteMaxAmt": "176889.6871254563042714",
                "estQuoteMgn": "",
                "existOrd": false,
                "maxLever": "10",
                "minLever": "0.01"
            }
        ],
        "msg": ""
    }
    

    Response Parameters

    Parameter Type Description
    estAvailQuoteTrans String The estimated margin(in quote currency) can be transferred out under the corresponding leverage
    For cross, it is the maximum quantity that can be transferred from the trading account.
    For isolated, it is the maximum quantity that can be transferred from the isolated position
    Only applicable to MARGIN
    estAvailTrans String The estimated margin can be transferred out under the corresponding leverage.
    For cross, it is the maximum quantity that can be transferred from the trading account.
    For isolated, it is the maximum quantity that can be transferred from the isolated position
    The unit is base currency for MARGIN
    It is not applicable to the scenario when increasing leverage for isolated position under FUTURES and SWAP
    estLiqPx String The estimated liquidation price under the corresponding leverage. Only return when there is a position.
    estMgn String The estimated margin needed by position under the corresponding leverage.
    For the MARGIN position, it is margin in base currency
    estQuoteMgn String The estimated margin (in quote currency) needed by position under the corresponding leverage
    estMaxAmt String For MARGIN, it is the estimated maximum loan in base currency under the corresponding leverage
    For SWAP and FUTURES, it is the estimated maximum quantity of contracts that can be opened under the corresponding leverage
    estQuoteMaxAmt String The MARGIN estimated maximum loan in quote currency under the corresponding leverage.
    existOrd Boolean Whether there is pending orders
    true
    false
    maxLever String Maximum leverage
    minLever String Minimum leverage

    Get the maximum loan of instrument

    Rate Limit: 20 requests per 2 seconds

    Rate limit rule: User ID

    HTTP Request

    GET /api/v5/account/max-loan

    Request Example

    # Max loan of cross `MARGIN` for currencies of trading pair in `Spot mode` (enabled borrowing)
    GET  /api/v5/account/max-loan?instId=BTC-USDT&mgnMode=cross
    
    # Max loan for currency in `Spot mode` (enabled borrowing)
    GET  /api/v5/account/max-loan?ccy=USDT&mgnMode=cross
    
    # Max loan of isolated `MARGIN` in `Futures mode`
    GET  /api/v5/account/max-loan?instId=BTC-USDT&mgnMode=isolated
    
    # Max loan of cross `MARGIN` in `Futures mode` (Margin Currency is BTC)
    GET  /api/v5/account/max-loan?instId=BTC-USDT&mgnMode=cross&mgnCcy=BTC
    
    # Max loan of cross `MARGIN` in `Multi-currency margin`
    GET  /api/v5/account/max-loan?instId=BTC-USDT&mgnMode=cross
    
    
    import okx.Account as Account
    
    # API initialization
    apikey = "YOUR_API_KEY"
    secretkey = "YOUR_SECRET_KEY"
    passphrase = "YOUR_PASSPHRASE"
    
    flag = "1"  # Production trading:0 , demo trading:1
    
    accountAPI = Account.AccountAPI(apikey, secretkey, passphrase, False, flag)
    
    # Max loan of cross MARGIN in Futures mode (Margin Currency is BTC)
    result = accountAPI.get_max_loan(
        instId="BTC-USDT",
        mgnMode="cross",
        mgnCcy="BTC"
    )
    print(result)
    

    Request Parameters

    Parameter Type Required Description
    mgnMode String Yes Margin mode
    isolated cross
    instId String Conditional Single instrument or multiple instruments (no more than 5) separated with comma, e.g. BTC-USDT,ETH-USDT
    ccy String Conditional Currency
    Applicable to get Max loan of manual borrow for the currency in Spot mode (enabled borrowing)
    mgnCcy String Conditional Margin currency
    Applicable to isolated MARGIN and cross MARGIN in Futures mode.
    tradeQuoteCcy String No The quote currency for trading. Only applicable to SPOT.
    The default value is the quote currency of instId, e.g. USD for BTC-USD.

    Response Example

    {
      "code": "0",
      "msg": "",
      "data": [
        {
          "instId": "BTC-USDT",
          "mgnMode": "isolated",
          "mgnCcy": "",
          "maxLoan": "0.1",
          "ccy": "BTC",
          "side": "sell"
        },
        {
          "instId": "BTC-USDT",
          "mgnMode": "isolated",
          "mgnCcy": "",
          "maxLoan": "0.2",
          "ccy": "USDT",
          "side": "buy"
        }
      ]
    }
    

    Response Parameters

    Parameter Type Description
    instId String Instrument ID
    mgnMode String Margin mode
    mgnCcy String Margin currency
    maxLoan String Max loan
    ccy String Currency
    side String Order side
    buy sell

    Get fee rates

    Rate Limit: 5 requests per 2 seconds

    Rate limit rule: User ID

    HTTP Request

    GET /api/v5/account/trade-fee

    Request Example

    # Query trade fee rate of SPOT BTC-USDT
    GET /api/v5/account/trade-fee?instType=SPOT&instId=BTC-USDT
    
    import okx.Account as Account
    
    # API initialization
    apikey = "YOUR_API_KEY"
    secretkey = "YOUR_SECRET_KEY"
    passphrase = "YOUR_PASSPHRASE"
    
    flag = "1"  # Production trading:0 , demo trading:1
    
    accountAPI = Account.AccountAPI(apikey, secretkey, passphrase, False, flag)
    
    # Get trading fee rates of current account
    result = accountAPI.get_fee_rates(
        instType="SPOT",
        instId="BTC-USDT"
    )
    print(result)
    

    Request Parameters

    Parameter Type Required Description
    instType String Yes Instrument type
    SPOT
    MARGIN
    SWAP
    FUTURES
    OPTION
    EVENTS
    instId String No Instrument ID, e.g. BTC-USDT
    Applicable to SPOT/MARGIN
    Specifying this parameter returns the correct applicable fee rates (e.g., market maker rates for users in incentive programs).
    instFamily String No Instrument family, e.g. BTC-USD
    Applicable to FUTURES/SWAP/OPTION
    groupId String No Instrument trading fee group ID
    Only one of groupId and instId/instFamily can be passed in

    Users can use instruments endpoint to fetch the mapping of an instrument ID and its trading fee group ID

    Response Example

    {
        "code": "0",
        "data": [
            {
                "category": "1",
                "delivery": "",
                "exercise": "",
                "feeGroup": [
                    {
                        "elpMaker": "-0.0008",
                        "rpiMaker": "-0.0008",
                        "groupId": "1",
                        "maker": "-0.0008",
                        "taker": "-0.001"
                    }
                ],
                "fiat": [],
                "instType": "SPOT",
                "level": "Lv1",
                "maker": "-0.0008",
                "makerU": "",
                "makerUSDC": "",
                "ruleType": "normal",
                "taker": "-0.001",
                "takerU": "",
                "takerUSDC": "",
                "ts": "1763979985847"
            }
        ],
        "msg": ""
    }
    

    Response Parameters

    Parameter Type Description
    level String Fee rate Level
    feeGroup Array of objects Fee groups.
    Applicable to SPOT/MARGIN/SWAP/FUTURES/OPTION/EVENTS
    > taker String Taker fee
    K1 parameter for EVENTS taker fee formula: K1 Γ— C Γ— (P Γ— (1-P)) (C = number of contracts, P = price)
    > maker String Maker fee
    K2 parameter for EVENTS maker fee formula: K2 Γ— C Γ— (P Γ— (1-P)) (C = number of contracts, P = price)
    > groupId String Instrument trading fee group ID

    instType and groupId should be used together to determine a trading fee group. Users should use this endpoint together with instruments endpoint to get the trading fee of a specific symbol.
    > elpMaker String ELP Maker effective fee rate. Returns "" if ELP is not applicable to the instrument.
    > rpiMaker String RPI maker effective fee rate. Returns "" if RPI is not applicable to the instrument.
    elpMaker remains accepted as an alias until October 31, 2026.
    delivery String Delivery fee rate
    exercise String Fee rate for exercising the option
    instType String Instrument type
    ts String Data return time, Unix timestamp format in milliseconds, e.g. 1597026383085
    taker String For SPOT/MARGIN, it is taker fee rate of the USDT trading pairs.
    For FUTURES/SWAP/OPTION, it is the fee rate of crypto-margined contracts
    (deprecated)
    maker String For SPOT/MARGIN, it is maker fee rate of the USDT trading pairs.
    For FUTURES/SWAP/OPTION, it is the fee rate of crypto-margined contracts
    (deprecated)
    takerU String Taker fee rate of USDT-margined contracts, only applicable to FUTURES/SWAP(deprecated)
    makerU String Maker fee rate of USDT-margined contracts, only applicable to FUTURES/SWAP(deprecated)
    takerUSDC String For SPOT/MARGIN, it is taker fee rate of the USDβ“ˆ&Crypto trading pairs.
    For FUTURES/SWAP, it is the fee rate of USDC-margined contracts
    (deprecated)
    makerUSDC String For SPOT/MARGIN, it is maker fee rate of the USDβ“ˆ&Crypto trading pairs.
    For FUTURES/SWAP, it is the fee rate of USDC-margined contracts
    (deprecated)
    ruleType String Trading rule types
    normal: normal trading
    pre_market: pre-market trading
    (deprecated)
    category String Currency category.(deprecated)
    fiat Array of objects Details of fiat fee rate(deprecated)
    > ccy String Fiat currency.
    > taker String Taker fee rate
    > maker String Maker fee rate
    settle String Settlement fee rate for users whose positions match the event contract settlement result. Users holding the opposite positions will not be charged during settlement. Only applicable to EVENTS

    Get interest accrued data

    Get the interest accrued data for the past year

    Rate Limit: 5 requests per 2 seconds

    Rate limit rule: User ID

    HTTP Request

    GET /api/v5/account/interest-accrued

    Request Example

    GET /api/v5/account/interest-accrued
    
    
    import okx.Account as Account
    
    # API initialization
    apikey = "YOUR_API_KEY"
    secretkey = "YOUR_SECRET_KEY"
    passphrase = "YOUR_PASSPHRASE"
    
    flag = "1"  # Production trading:0 , demo trading:1
    
    accountAPI = Account.AccountAPI(apikey, secretkey, passphrase, False, flag)
    
    # Get interest accrued data
    result = accountAPI.get_interest_accrued()
    print(result)
    

    Request Parameters

    Parameter Type Required Description
    type String No Loan type
    2: Market loans
    Default is 2
    ccy String No Loan currency, e.g. BTC
    Only applicable to Market loans
    Only applicable toMARGIN
    instId String No Instrument ID, e.g. BTC-USDT
    Only applicable to Market loans
    mgnMode String No Margin mode
    cross
    isolated
    Only applicable to Market loans
    after String No Pagination of data to return records earlier than the requested timestamp, Unix timestamp format in milliseconds, e.g. 1597026383085
    before String No Pagination of data to return records newer than the requested, Unix timestamp format in milliseconds, e.g. 1597026383085
    limit String No Number of results per request. The maximum is 100. The default is 100.

    Response Example

    {
        "code": "0",
        "data": [
            {
                "ccy": "USDT",
                "instId": "",
                "interest": "0.0003960833333334",
                "interestRate": "0.0000040833333333",
                "liab": "97",
                "totalLiab": "",
                "interestFreeLiab": "",
                "mgnMode": "",
                "ts": "1637312400000",
                "type": "1"
            },
            {
                "ccy": "USDT",
                "instId": "",
                "interest": "0.0004083333333334",
                "interestRate": "0.0000040833333333",
                "liab": "100",
                "mgnMode": "",
                "ts": "1637049600000",
                "type": "1"
            }
        ],
        "msg": ""
    }
    

    Response Parameters

    Parameter Type Description
    type String Loan type
    2: Market loans
    ccy String Loan currency, e.g. BTC
    instId String Instrument ID, e.g. BTC-USDT
    Only applicable to Market loans
    mgnMode String Margin mode
    cross
    isolated
    interest String Interest accrued
    interestRate String Hourly borrowing interest rate
    liab String Liability
    totalLiab String Total liability for current account
    interestFreeLiab String Interest-free liability for current account
    ts String Timestamp for interest accrued, Unix timestamp format in milliseconds, e.g. 1597026383085

    Get interest rate

    Get the user's current leveraged currency borrowing market interest rate

    Rate Limit: 5 requests per 2 seconds

    Rate limit rule: User ID

    HTTP Request

    GET /api/v5/account/interest-rate

    Request Example

    GET /api/v5/account/interest-rate
    
    import okx.Account as Account
    
    # API initialization
    apikey = "YOUR_API_KEY"
    secretkey = "YOUR_SECRET_KEY"
    passphrase = "YOUR_PASSPHRASE"
    
    flag = "1"  # Production trading:0 , demo trading:1
    
    accountAPI = Account.AccountAPI(apikey, secretkey, passphrase, False, flag)
    
    # Get the user's current leveraged currency borrowing interest rate
    result = accountAPI.get_interest_rate()
    print(result)
    

    Request Parameters

    Parameters Types Required Description
    ccy String No Currency, e.g. BTC
    {
        "code":"0",
        "msg":"",
        "data":[
            {
                "ccy":"BTC",
                "interestRate":"0.0001"
            },
            {
                "ccy":"LTC",
                "interestRate":"0.0003"
            }
        ]
    }
    

    Response Parameters

    Parameter Type Description
    interestRate String Hourly borrowing interest rate
    ccy String Currency

    Set fee type

    Set the fee type.

    Rate Limit: 5 requests per 2 seconds

    Rate limit rule: User ID

    HTTP Request

    POST /api/v5/account/set-fee-type

    Request Example

    POST /api/v5/account/set-fee-type 
    body
    {
        "feeType":"0"
    }
    
    

    Request Parameters

    Parameter Type Required Description
    feeType String Yes Fee type
    0: fee is charged in the currency you receive from the trade (default)
    1: fee is always charged in the quote currency of the trading pair (only effective for Spot)

    Response Example

    {
        "code": "0",
        "msg": "",
        "data": [
            {
                "feeType": "0"
            }
        ]
    }
    

    Response Parameters

    Parameter Type Description
    feeType String Fee type
    0: fee is charged in the currency you receive from the trade
    1: fee is always charged in the quote currency of the trading pair

    Set greeks (PA/BS)

    Set the display type of Greeks.

    Rate Limit: 5 requests per 2 seconds

    Rate limit rule: User ID

    HTTP Request

    POST /api/v5/account/set-greeks

    Request Example

    POST /api/v5/account/set-greeks 
    body
    {
        "greeksType":"PA"
    }
    
    
    import okx.Account as Account
    
    # API initialization
    apikey = "YOUR_API_KEY"
    secretkey = "YOUR_SECRET_KEY"
    passphrase = "YOUR_PASSPHRASE"
    
    flag = "1"  # Production trading:0 , demo trading:1
    
    accountAPI = Account.AccountAPI(apikey, secretkey, passphrase, False, flag)
    
    # Set greeks (PA/BS)
    result = accountAPI.set_greeks(greeksType="PA")
    print(result)
    

    Request Parameters

    Parameter Type Required Description
    greeksType String Yes Display type of Greeks.
    PA: Greeks in coins
    BS: Black-Scholes Greeks in dollars

    Response Example

    {
        "code": "0",
        "msg": "",
        "data": [{
            "greeksType": "PA"
        }]
    }
    

    Response Parameters

    Parameter Type Description
    greeksType String Display type of Greeks.

    Isolated margin trading settings

    You can set the currency margin and futures/perpetual Isolated margin trading mode

    Rate Limit: 5 requests per 2 seconds

    Rate limit rule: User ID

    HTTP Request

    POST /api/v5/account/set-isolated-mode

    Request Example

    POST /api/v5/account/set-isolated-mode
    body
    {
        "isoMode":"automatic",
        "type":"MARGIN"
    }
    
    import okx.Account as Account
    
    # API initialization
    apikey = "YOUR_API_KEY"
    secretkey = "YOUR_SECRET_KEY"
    passphrase = "YOUR_PASSPHRASE"
    
    flag = "1"  # Production trading:0 , demo trading:1
    
    accountAPI = Account.AccountAPI(apikey, secretkey, passphrase, False, flag)
    
    # Isolated margin trading settings
    result = accountAPI.set_isolated_mode(
        isoMode="automatic",
        type="MARGIN"
    )
    print(result)
    

    Request Parameters

    Parameter Type Required Description
    isoMode String Yes Isolated margin trading settings
    auto_transfers_ccy: New auto transfers, enabling both base and quote currency as the margin for isolated margin trading. Only applicable to MARGIN.
    automatic: Auto transfers
    type String Yes Instrument type
    MARGIN
    CONTRACTS

    Response Example

    {
        "code": "0",
        "data": [
            {
                "isoMode": "automatic"
            }
        ],
        "msg": ""
    }
    

    Response Parameters

    Parameter Type Description
    isoMode String Isolated margin trading settings
    automatic: Auto transfers

    Get maximum withdrawals

    Retrieve the maximum transferable amount from trading account to funding account. If no currency is specified, the transferable amount of all owned currencies will be returned.

    Rate Limit: 20 requests per 2 seconds

    Rate limit rule: User ID

    HTTP Request

    GET /api/v5/account/max-withdrawal

    Request Example

    GET /api/v5/account/max-withdrawal
    
    
    import okx.Account as Account
    
    # API initialization
    apikey = "YOUR_API_KEY"
    secretkey = "YOUR_SECRET_KEY"
    passphrase = "YOUR_PASSPHRASE"
    
    flag = "1"  # Production trading:0 , demo trading:1
    
    accountAPI = Account.AccountAPI(apikey, secretkey, passphrase, False, flag)
    
    # Get maximum withdrawals
    result = accountAPI.get_max_withdrawal()
    print(result)
    

    Request Parameters

    Parameter Type Required Description
    ccy String No Single currency or multiple currencies (no more than 20) separated with comma, e.g. BTC or BTC,ETH.

    Response Example

    {
        "code": "0",
        "msg": "",
        "data": [{
                "ccy": "BTC",
                "maxWd": "124",
                "maxWdEx": "125",
                "spotOffsetMaxWd": "",
                "spotOffsetMaxWdEx": ""
            },
            {
                "ccy": "ETH",
                "maxWd": "10",
                "maxWdEx": "12",
                "spotOffsetMaxWd": "",
                "spotOffsetMaxWdEx": ""
            }
        ]
    }
    

    Response Parameters

    Parameter Type Description
    ccy String Currency
    maxWd String Max withdrawal (excluding borrowed assets under Spot mode/Multi-currency margin/Portfolio margin)
    maxWdEx String Max withdrawal (including borrowed assets under Spot mode/Multi-currency margin/Portfolio margin)
    spotOffsetMaxWd String Max withdrawal under Spot-Derivatives risk offset mode (excluding borrowed assets under Portfolio margin)
    Applicable to Portfolio margin
    spotOffsetMaxWdEx String Max withdrawal under Spot-Derivatives risk offset mode (including borrowed assets under Portfolio margin)
    Applicable to Portfolio margin

    Get account risk state

    Only applicable to Portfolio margin account

    Rate Limit: 10 requests per 2 seconds

    Rate limit rule: User ID

    HTTP Request

    GET /api/v5/account/risk-state

    Request Example

    GET /api/v5/account/risk-state
    
    import okx.Account as Account
    
    # API initialization
    apikey = "YOUR_API_KEY"
    secretkey = "YOUR_SECRET_KEY"
    passphrase = "YOUR_PASSPHRASE"
    
    flag = "1"  # Production trading:0 , demo trading:1
    
    accountAPI = Account.AccountAPI(apikey, secretkey, passphrase, False, flag)
    
    # Get account risk state
    result = accountAPI.get_account_position_risk()
    print(result)
    

    Response Example

    {
        "code": "0",
        "data": [
            {
                "atRisk": false,
                "atRiskIdx": [],
                "atRiskMgn": [],
                "ts": "1635745078794"
            }
        ],
        "msg": ""
    }
    

    Response Parameters

    Parameters Types Description
    atRisk Boolean Account risk status in auto-borrow mode
    true: the account is currently in a specific risk state
    false: the account is currently not in a specific risk state
    atRiskIdx Array of strings derivatives risk unit list
    atRiskMgn Array of strings margin risk unit list
    ts String Unix timestamp format in milliseconds, e.g.1597026383085

    Get borrow interest and limit

    Rate Limit: 5 requests per 2 seconds

    Rate limit rule: User ID

    HTTP Request

    GET /api/v5/account/interest-limits

    Request Example

    GET /api/v5/account/interest-limits?ccy=BTC
    
    
    import okx.Account as Account
    
    # API initialization
    apikey = "YOUR_API_KEY"
    secretkey = "YOUR_SECRET_KEY"
    passphrase = "YOUR_PASSPHRASE"
    
    flag = "1"  # Production trading:0 , demo trading:1
    
    accountAPI = Account.AccountAPI(apikey, secretkey, passphrase, False, flag)
    
    # Get borrow interest and limit
    result = accountAPI.get_interest_limits(
        ccy="BTC"
    )
    print(result)
    

    Request Parameters

    Parameter Type Required Description
    type String No Loan type
    2: Market loans
    Default is 2
    ccy String No Loan currency, e.g. BTC

    Response Example

    {
        "code": "0",
        "data": [
            {
                "debt": "0.85893159114900247077000000000000",
                "interest": "0.00000000000000000000000000000000",
                "loanAlloc": "",
                "nextDiscountTime": "1729490400000",
                "nextInterestTime": "1729490400000",
                "records": [
                    {
                        "availLoan": "",
                        "avgRate": "",
                        "ccy": "BTC",
                        "interest": "0",
                        "loanQuota": "175.00000000",
                        "posLoan": "",
                        "rate": "0.0000276",
                        "surplusLmt": "175.00000000",
                        "surplusLmtDetails": {},
                        "usedLmt": "0.00000000",
                        "usedLoan": "",
                        "interestFreeLiab": "",
                        "potentialBorrowingAmt": ""
                    }
                ]
            }
        ],
        "msg": ""
    }
    

    Response Parameters

    Parameter Type Description
    debt String Current debt in USD
    interest String Current interest in USD, the unit is USD
    Only applicable to Market loans
    nextDiscountTime String Next deduct time, Unix timestamp format in milliseconds, e.g. 1597026383085
    nextInterestTime String Next accrual time, Unix timestamp format in milliseconds, e.g. 1597026383085
    loanAlloc String VIP Loan allocation for the current trading account
    1. The unit is percent(%). Range is [0, 100]. Precision is 0.01%
    2. If master account did not assign anything, then "0"
    3. "" if shared between master and sub-account
    records Array of objects Details for currencies
    > ccy String Loan currency, e.g. BTC
    > rate String Current daily borrowing rate
    > loanQuota String Borrow limit of master account
    If loan allocation has been assigned, then it is the borrow limit of the current trading account
    > surplusLmt String Available amount across all sub-accounts
    If loan allocation has been assigned, then it is the available amount to borrow by the current trading account
    > usedLmt String Borrowed amount for current account
    If loan allocation has been assigned, then it is the borrowed amount by the current trading account
    > interest String Interest to be deducted
    Only applicable to Market loans
    > interestFreeLiab String Interest-free liability for current account
    > potentialBorrowingAmt String Potential borrowing amount for current account
    > surplusLmtDetails Object The details of available amount across all sub-accounts
    The value of surplusLmt is the minimum value within this array. It can help you judge the reason that surplusLmt is not enough.
    Only applicable to VIP loans
    Deprecated
    >> allAcctRemainingQuota String Total remaining quota for master account and sub-accounts Deprecated
    >> curAcctRemainingQuota String The remaining quota for the current account.
    Only applicable to the case in which the sub-account is assigned the loan allocation
    Deprecated
    >> platRemainingQuota String Remaining quota for the platform.
    The format like "600" will be returned when it is more than curAcctRemainingQuota or allAcctRemainingQuota
    Deprecated
    > posLoan String Frozen amount for current account (Within the locked quota)
    Only applicable to VIP loans
    Deprecated
    > availLoan String Available amount for current account (Within the locked quota)
    Only applicable to VIP loans
    Deprecated
    > usedLoan String Borrowed amount for current account
    Only applicable to VIP loans
    Deprecated
    > avgRate String Average hourly interest of borrowed coin
    only applicable to VIP loans
    Deprecated

    Manual borrow / repay

    Only applicable to Spot mode (enabled borrowing)

    Rate Limit: 1 request per 3 seconds

    Rate limit rule: Master Account User ID

    HTTP Request

    POST /api/v5/account/spot-manual-borrow-repay

    Request Example

    POST /api/v5/account/spot-manual-borrow-repay 
    body
    {
        "ccy":"USDT",
        "side":"borrow",
        "amt":"100"
    }
    
    import okx.Account as Account
    
    # API initialization
    apikey = "YOUR_API_KEY"
    secretkey = "YOUR_SECRET_KEY"
    passphrase = "YOUR_PASSPHRASE"
    
    flag = "1"  # Production trading:0 , demo trading:1
    accountAPI = Account.AccountAPI(apikey, secretkey, passphrase, False, flag)
    
    result = accountAPI.spot_manual_borrow_repay(ccy="USDT", side="borrow", amt= "1")
    print(result)
    

    Request Parameters

    Parameter Type Required Description
    ccy String Yes Currency, e.g. BTC
    side String Yes Side
    borrow
    repay
    amt String Yes Amount

    Response Example

    {
        "code": "0",
        "data": [
            {
                "ccy":"USDT",
                "side":"borrow",
                "amt":"100"
            }
        ],
        "msg": ""
    }
    

    Response Parameters

    Parameter Type Description
    ccy String Currency, e.g. BTC
    side String Side
    borrow
    repay
    amt String Actual amount

    Set auto repay

    Only applicable to Spot mode (enabled borrowing)

    Rate Limit: 5 requests per 2 seconds

    Rate limit rule: User ID

    HTTP Request

    POST /api/v5/account/set-auto-repay

    Request Example

    POST /api/v5/account/set-auto-repay
    body
    {
        "autoRepay": true
    }
    
    import okx.Account as Account
    
    # API initialization
    apikey = "YOUR_API_KEY"
    secretkey = "YOUR_SECRET_KEY"
    passphrase = "YOUR_PASSPHRASE"
    
    flag = "1"  # Production trading:0 , demo trading:1
    accountAPI = Account.AccountAPI(apikey, secretkey, passphrase, False, flag)
    
    result = accountAPI.set_auto_repay(autoRepay=True)
    print(result)
    

    Request Parameters

    Parameter Type Required Description
    autoRepay Boolean Yes Whether auto repay is allowed or not under Spot mode
    true: Enable auto repay
    false: Disable auto repay

    Response Example

    {
        "code": "0",
        "msg": "",
        "data": [
            {
                "autoRepay": true
            }
        ]
    }
    

    Response Parameters

    Parameter Type Description
    autoRepay Boolean Whether auto repay is allowed or not under Spot mode
    true: Enable auto repay
    false: Disable auto repay

    Get borrow/repay history

    Retrieve the borrow/repay history under Spot mode

    Rate Limit: 5 requests per 2 seconds

    Rate limit rule: User ID

    HTTP Request

    GET /api/v5/account/spot-borrow-repay-history

    Request Example

    GET /api/v5/account/spot-borrow-repay-history
    
    import okx.Account as Account
    
    # API initialization
    apikey = "YOUR_API_KEY"
    secretkey = "YOUR_SECRET_KEY"
    passphrase = "YOUR_PASSPHRASE"
    
    flag = "1"   # Production trading:0 , demo trading:1
    accountAPI = Account.AccountAPI(apikey, secretkey, passphrase, False, flag)
    
    result = accountAPI.spot_borrow_repay_history(ccy="USDT", type="auto_borrow")
    print(result)
    

    Request Parameters

    Parameter Type Required Description
    ccy String No Currency, e.g. BTC
    type String No Event type
    auto_borrow
    auto_repay
    manual_borrow
    manual_repay
    after String No Pagination of data to return records earlier than the requested ts (included), Unix timestamp format in milliseconds, e.g. 1597026383085
    before String No Pagination of data to return records newer than the requested ts(included), Unix timestamp format in milliseconds, e.g. 1597026383085
    limit String No Number of results per request. The maximum is 100. The default is 100.

    Response Example

    {
        "code": "0",
        "data": [
            {
                "accBorrowed": "0",
                "amt": "6764.802661157592",
                "ccy": "USDT",
                "ts": "1725330976644",
                "type": "auto_repay"
            }
        ],
        "msg": ""
    }
    

    Response Parameters

    Parameter Type Description
    ccy String Currency, e.g. BTC
    type String Event type
    auto_borrow
    auto_repay
    manual_borrow
    manual_repay
    amt String Amount
    accBorrowed String Accumulated borrow amount
    ts String Timestamp for the event, Unix timestamp format in milliseconds, e.g. 1597026383085

    Position builder (new)

    Calculates portfolio margin information for virtual position/assets or current position of the user.
    You can add up to 200 virtual positions and 200 virtual assets in one request.

    Rate Limit: 2 requests per 2 seconds

    Rate limit rule: User ID

    HTTP Request

    POST /api/v5/account/position-builder

    Request Example

    # Both real and virtual positions and assets are calculated 
    POST /api/v5/account/position-builder
    body
    {
        "inclRealPosAndEq": false,
        "simPos":[
             {
                "pos":"-10",
                "instId":"BTC-USDT-SWAP",
                "avgPx":"100000"
             },
             {
                "pos":"10",
                "instId":"LTC-USDT-SWAP",
                "avgPx":"8000"
             }
        ],
        "simAsset":[
            {
                "ccy": "USDT",
                "amt": "100"
            }
        ],
        "greeksType":"CASH"
    }
    
    
    # Only existing real positions are calculated
    POST /api/v5/account/position-builder
    body
    {
       "inclRealPosAndEq":true
    }
    
    
    # Only virtual positions are calculated
    POST /api/v5/account/position-builder
    body
    {
        "acctLv": "4",
        "inclRealPosAndEq": false,
        "simPos":[
            {
                "pos":"10",
                "instId":"BTC-USDT-SWAP",
                "avgPx":"100000"
            },
            {
                "pos":"10",
                "instId":"LTC-USDT-SWAP",
                "avgPx":"8000"
            }
        ]
    }
    
    # Switch to Multi-currency margin mode
    POST /api/v5/account/position-builder
    body
    {
        "acctLv": "3",
        "lever":"10",
        "simPos":[
            {
                "pos":"10",
                "instId":"BTC-USDT-SWAP",
                "avgPx":"100000",
                "lever":"5"
            },
            {
                "pos":"10",
                "instId":"LTC-USDT-SWAP",
                "avgPx":"8000"
            }
        ]
    }
    
    import okx.Account as Account
    
    # API initialization
    apikey = "YOUR_API_KEY"
    secretkey = "YOUR_SECRET_KEY"
    passphrase = "YOUR_PASSPHRASE"
    
    flag = "1"  # Production trading:0 , demo trading:1
    
    accountAPI = Account.AccountAPI(apikey, secretkey, passphrase, False, flag)
    
    result = accountAPI.position_builder(
        inclRealPosAndEq=True,
        simPos=[
            {
                "pos": "10",
                "instId": "BTC-USDT-SWAP"
            },
            {
                "pos": "10",
                "instId": "LTC-USDT-SWAP"
            }
        ]
    )
    print(result)
    

    Request Parameters

    Parameter Type Required Description
    acctLv String No Switch to account mode
    3: Multi-currency margin
    4: Portfolio margin
    The default is 4
    inclRealPosAndEq Boolean No Whether import existing positions and assets
    The default is true
    lever String No Cross margin leverage in Multi-currency margin mode, the default is 1.
    If the allowed leverage is exceeded, set according to the maximum leverage.
    Only applicable to Multi-currency margin
    simPos Array of objects No List of simulated positions
    > instId String Yes Instrument ID, e.g. BTC-USDT-SWAP
    Applicable to SWAP/FUTURES/OPTION
    > pos String Yes Quantity of positions
    > avgPx String Yes Average open price
    > lever String No leverage
    Only applicable to Multi-currency margin
    The default is 1
    If the allowed leverage is exceeded, set according to the maximum leverage.
    simAsset Array of objects No List of simulated assets
    When inclRealPosAndEq is true, only real assets are considered and virtual assets are ignored
    > ccy String Yes Currency, e.g. BTC
    > amt String Yes Currency amount
    greeksType String No Greeks type
    BS: Black-Scholes Model Greeks
    PA: Crypto Greeks
    CASH: Empirical Greeks
    The default is BS
    idxVol String No Price volatility percentage, indicating what this price change means towards each of the values. In decimal form, range -0.99 ~ 1, in 0.01 increment.
    Default 0

    Response Example

    {
        "code": "0",
        "data": [
            {
                "acctLever": "-0.1364949794742562",
                "assets": [
                    {
                        "availEq": "0",
                        "borrowImr": "0",
                        "borrowMmr": "",
                        "ccy": "BTC",
                        "spotInUse": "0"
                    },
                    {
                        "availEq": "0",
                        "borrowImr": "0",
                        "borrowMmr": "",
                        "ccy": "LTC",
                        "spotInUse": "0"
                    },
                    {
                        "availEq": "0",
                        "borrowImr": "0",
                        "borrowMmr": "",
                        "ccy": "USDC",
                        "spotInUse": "0"
                    },
                    {
                        "availEq": "-78589.37",
                        "borrowImr": "7855.32188898",
                        "borrowMmr": "",
                        "ccy": "USDT",
                        "spotInUse": "0"
                    }
                ],
                "borrowMmr": "1571.064377796",
                "derivMmr": "1375.4837063088003",
                "eq": "-78553.21888979999",
                "marginRatio": "-25.95365779811705",
                "positions": [],
                "riskUnitData": [
                    {
                        "delta": "-9704.903689800001",
                        "gamma": "0",
                        "imrBf": "",
                        "imr": "1538.9669514070802",
                        "mmrBf": "",
                        "mmr": "1183.8207318516002",
                        "mr1": "1164.4109244719994",
                        "mr1FinalResult": {
                            "pnl": "-1164.4109244719994",
                            "spotShock": "0.12",
                            "volShock": "up"
                        },
                        "mr1Scenarios": {
                            "volSame": {
                                "0": "0",
                                "0.08": "-776.2739496480004",
                                "-0.08": "776.2739496480004",
                                "0.04": "-388.1369748240002",
                                "0.12": "-1164.4109244719994",
                                "-0.12": "1164.4109244719994",
                                "-0.04": "388.1369748240002"
                            },
                            "volShockDown": {
                                "0": "0",
                                "0.08": "-776.2739496480004",
                                "-0.08": "776.2739496480004",
                                "0.04": "-388.1369748240002",
                                "0.12": "-1164.4109244719994",
                                "-0.12": "1164.4109244719994",
                                "-0.04": "388.1369748240002"
                            },
                            "volShockUp": {
                                "0": "0",
                                "0.08": "-776.2739496480004",
                                "-0.08": "776.2739496480004",
                                "0.04": "-388.1369748240002",
                                "0.12": "-1164.4109244719994",
                                "-0.12": "1164.4109244719994",
                                "-0.04": "388.1369748240002"
                            }
                        },
                        "mr2": "0",
                        "mr3": "0",
                        "mr4": "19.4098073796",
                        "mr5": "0",
                        "mr6": "1164.4109244720003",
                        "mr6FinalResult": {
                            "pnl": "-2328.8218489440005",
                            "spotShock": "0.24"
                        },
                        "mr7": "43.67206660410001",
                        "mr8": "1571.064377796",
                        "mr9": "0",
                        "portfolios": [
                            {
                                "amt": "-10",
                                "avgPx": "100000",
                                "delta": "-9704.903689800001",
                                "floatPnl": "290.6300000000003",
                                "gamma": "0",
                                "instId": "BTC-USDT-SWAP",
                                "instType": "SWAP",
                                "isRealPos": false,
                                "markPxBf": "",
                                "markPx": "97093.7",
                                "notionalUsd": "9703.22",
                                "posSide": "net",
                                "theta": "0",
                                "vega": "0"
                            }
                        ],
                        "riskUnit": "BTC",
                        "theta": "0",
                        "upl": "290.49631020000027",
                        "vega": "0"
                    },
                    {
                        "delta": "1019.5308",
                        "gamma": "0",
                        "imrBf": "",
                        "imr": "249.16186679436",
                        "mmrBf": "",
                        "mmr": "191.6629744572",
                        "mr1": "183.50672805719995",
                        "mr1FinalResult": {
                            "pnl": "-183.50672805719995",
                            "spotShock": "-0.18",
                            "volShock": "up"
                        },
                        "mr1Scenarios": {
                            "volSame": {
                                "0": "0",
                                "-0.06": "-61.168909352399936",
                                "0.06": "61.168909352399936",
                                "-0.18": "-183.50672805719995",
                                "0.18": "183.50672805719995",
                                "0.12": "122.33781870480001",
                                "-0.12": "-122.33781870480001"
                            },
                            "volShockDown": {
                                "0": "0",
                                "-0.06": "-61.168909352399936",
                                "0.06": "61.168909352399936",
                                "-0.18": "-183.50672805719995",
                                "0.18": "183.50672805719995",
                                "0.12": "122.33781870480001",
                                "-0.12": "-122.33781870480001"
                            },
                            "volShockUp": {
                                "0": "0",
                                "-0.06": "-61.168909352399936",
                                "0.06": "61.168909352399936",
                                "-0.18": "-183.50672805719995",
                                "0.18": "183.50672805719995",
                                "0.12": "122.33781870480001",
                                "-0.12": "-122.33781870480001"
                            }
                        },
                        "mr2": "0",
                        "mr3": "0",
                        "mr4": "8.1562464",
                        "mr5": "0",
                        "mr6": "183.5067280572",
                        "mr6FinalResult": {
                            "pnl": "-367.0134561144",
                            "spotShock": "-0.36"
                        },
                        "mr7": "7.1367156",
                        "mr8": "1571.064377796",
                        "mr9": "0",
                        "portfolios": [
                            {
                                "amt": "10",
                                "avgPx": "8000",
                                "delta": "1019.5308",
                                "floatPnl": "-78980",
                                "gamma": "0",
                                "instId": "LTC-USDT-SWAP",
                                "instType": "SWAP",
                                "isRealPos": false,
                                "markPxBf": "",
                                "markPx": "102",
                                "notionalUsd": "1018.9",
                                "posSide": "net",
                                "theta": "0",
                                "vega": "0"
                            }
                        ],
                        "riskUnit": "LTC",
                        "theta": "0",
                        "upl": "-78943.6692",
                        "vega": "0"
                    }
                ],
                "totalImr": "9643.45070718144",
                "totalMmr": "2946.5480841048",
                "ts": "1736936801642",
                "upl": "-78653.1728898"
            }
        ],
        "msg": ""
    }
    

    Response Parameters

    Parameters Types Description
    eq String Adjusted equity (USD) for the account
    totalMmr String Total MMR (USD) for the account
    totalImr String Total IMR (USD) for the account
    borrowMmr String Borrow MMR (USD) for the account
    derivMmr String Derivatives MMR (USD) for the account
    marginRatio String Cross maintenance margin ratio for the account
    upl String UPL for the account
    acctLever String Leverage of the account
    ts String Update time for the account, Unix timestamp format in milliseconds, e.g. 1597026383085
    assets Array of objects Asset info
    > ccy String Currency, e.g. BTC
    > availEq String Currency equity
    > spotInUse String Spot in use
    > borrowMmr String Borrowing MMR (USD)(Deprecated)
    > borrowImr String Borrowing IMR (USD)
    riskUnitData Array of objects Risk unit info
    > riskUnit String Risk unit, e.g. BTC
    > mmrBf String Risk unit MMR before volatility (USD)
    Return "" if users don't pass in idxVol
    > mmr String Risk unit MMR (USD)
    > imrBf String Risk unit IMR before volatility (USD)
    Return "" if users don't pass in idxVol
    > imr String Risk unit IMR (USD)
    > upl String Risk unit UPL (USD)
    > mr1 String Stress testing value of spot and volatility (all derivatives, and spot trading in spot-derivatives risk offset mode)
    > mr2 String Stress testing value of time value of money (TVM) (for options)
    > mr3 String Stress testing value of volatility span (for options)
    > mr4 String Stress testing value of basis (for all derivatives)
    > mr5 String Stress testing value of interest rate risk (for options)
    > mr6 String Stress testing value of extremely volatile markets (for all derivatives, and spot trading in spot-derivatives risk offset mode)
    > mr7 String Stress testing value of position reduction cost (for all derivatives)
    > mr8 String Borrowing MMR/IMR
    > mr9 String USDT-USDC-USD hedge risk
    > mr1Scenarios Object MR1 scenario analysis
    >> volShockDown Object When volatility shocks down, the P&L of stress tests under different price volatility ratios, format in {change: value,...}
    change: price volatility ratio (in percentage), e.g. 0.01 representing 1%
    value: P&L under stress tests, measured in USD
    e.g. {"-0.15":"-2333.23", ...}
    >> volSame Object When volatility keeps the same, the P&L of stress tests under different price volatility ratios, format in {change: value,...}
    change: price volatility ratio (in percentage), e.g. 0.01 representing 1%
    value: P&L under stress tests, measured in USD
    e.g. {"-0.15":"-2333.23", ...}
    >> volShockUp Object When volatility shocks up, the P&L of stress tests under different price volatility ratios, format in {change: value,...}
    change: price volatility ratio (in percentage), e.g. 0.01 representing 1%
    value: P&L under stress tests, measured in USD
    e.g. {"-0.15":"-2333.23", ...}
    > mr1FinalResult Object MR1 worst-case scenario
    >> pnl String MR1 stress P&L (USD)
    >> spotShock String MR1 worst-case scenario spot shock (in percentage), e.g. 0.01 representing 1%
    >> volShock String MR1 worst-case scenario volatility shock
    down: volatility shock down
    unchange: volatility unchanged
    up: volatility shock up
    > mr6FinalResult Object MR6 scenario analysis
    >> pnl String MR6 stress P&L (USD)
    >> spotShock String MR6 worst-case scenario spot shock (in percentage), e.g. 0.01 representing 1%
    > delta String (Risk unit) The rate of change in the contract’s price with respect to changes in the underlying asset’s price.
    When the price of the underlying changes by x, the option’s price changes by delta multiplied by x.
    > gamma String (Risk unit) The rate of change in the delta with respect to changes in the underlying price.
    When the price of the underlying changes by x%, the option’s delta changes by gamma multiplied by x%.
    > theta String (Risk unit) The change in contract price each day closer to expiry.
    > vega String (Risk unit) The change of the option price when underlying volatility increases by 1%.
    > portfolios Array of objects Portfolios info
    Only applicable to Portfolio margin
    >> instId String Instrument ID, e.g. BTC-USDT-SWAP
    >> instType String Instrument type
    SPOT
    SWAP
    FUTURES
    OPTION
    >> amt String When instType is SPOT, it represents spot in use.
    When instType is SWAP/FUTURES/OPTION, it represents position amount.
    >> posSide String Position side
    long
    short
    net
    >> avgPx String Average open price
    >> markPxBf String Mark price before price volatility
    Return "" if users don't pass in idxVol
    >> markPx String Mark price
    >> floatPnl String Float P&L
    >> notionalUsd String Notional in USD
    >> delta String When instType is SPOT, it represents asset amount.
    When instType is SWAP/FUTURES/OPTION, it represents the rate of change in the contract’s price with respect to changes in the underlying asset’s price (by Instrument ID).
    >> gamma String The rate of change in the delta with respect to changes in the underlying price (by Instrument ID).
    When instType is SPOT, it will return "".
    >> theta String The change in contract price each day closer to expiry (by Instrument ID).
    When instType is SPOT, it will return "".
    >> vega String The change of the option price when underlying volatility increases by 1% (by Instrument ID).
    When instType is SPOT, it will return "".
    >> isRealPos Boolean Whether it is a real position
    If instType is SWAP/FUTURES/OPTION, it is a valid parameter, else it will return false
    positions Array of objects Position info
    Only applicable to Multi-currency margin
    > instId String Instrument ID, e.g. BTC-USDT-SWAP
    > instType String Instrument type
    SPOT
    SWAP
    FUTURES
    OPTION
    > amt String When instType is SPOT, it represents spot in use.
    When instType is SWAP/FUTURES/OPTION, it represents position amount.
    > posSide String Position side
    long
    short
    net
    > avgPx String Average open price
    > markPxBf String Mark price before price volatility
    Return "" if users don't pass in idxVol
    > markPx String Mark price
    > floatPnl String Float P&L
    > imrBf String IMR before price volatility
    > imr String IMR
    > mgnRatio String Maintenance margin ratio
    > lever String Leverage
    > notionalUsd String Notional in USD
    > isRealPos Boolean Whether it is a real position
    If instType is SWAP/FUTURES/OPTION, it is a valid parameter, else it will return false

    Position builder trend graph

    Rate limit: 1 request per 5 seconds

    Rate limit rule: User ID

    HTTP Request

    POST /api/v5/account/position-builder-graph

    Request Example

    {
       "inclRealPosAndEq":false,
       "simPos":[
          {
             "pos":"-10",
             "instId":"BTC-USDT-SWAP",
             "avgPx":"100000"
          },
          {
             "pos":"10",
             "instId":"LTC-USDT-SWAP",
             "avgPx":"8000"
          }
       ],
       "simAsset":[
          {
             "ccy":"USDT",
             "amt":"100"
          }
       ],
       "greeksType":"CASH",
       "type":"mmr",
       "mmrConfig":{
          "acctLv":"3",
          "lever":"1"
       }
    }
    

    Request Parameters

    Parameter Type Required Description
    inclRealPosAndEq Boolean No Whether to import existing positions and assets
    The default is true
    simPos Array of objects No List of simulated positions
    > instId String Yes Instrument ID, e.g. BTC-USDT-SWAP
    Applicable to SWAP/FUTURES/OPTION
    > pos String Yes Quantity of positions
    > avgPx String Yes Average open price
    > lever String No leverage
    Only applicable to Multi-currency margin
    The default is 1
    If the allowed leverage is exceeded, set according to the maximum leverage.
    simAsset Array of objects No List of simulated assets
    When inclRealPosAndEq is true, only real assets are considered and virtual assets are ignored
    > ccy String Yes Currency, e.g. BTC
    > amt String Yes Currency amount
    type String Yes Trending graph type
    mmr
    mmrConfig Object Yes MMR configuration
    > acctLv String No Switch to account mode
    3: Multi-currency margin
    4: Portfolio margin
    > lever String No Cross margin leverage in Multi-currency margin mode, the default is 1.
    If the allowed leverage is exceeded, set according to the maximum leverage.
    Only applicable to Multi-currency margin

    Response Example

    {
        "code": "0",
        "data": [
             {
                "type": "mmr",
                "mmrData": [
                   ......
                   {
                         "mmr": "1415.0254039225917",
                         "mmrRatio": "-47.45603627655477",
                         "shockFactor": "-0.94"
                   },
                   {
                         "mmr": "1417.732491243024",
                         "mmrRatio": "-47.436684685735386",
                         "shockFactor": "-0.93"
                   }
                   ......
                ]
             }
        ],
        "msg": ""
    }
    
    

    Response Parameters

    Parameters Types Description
    type String Graph type
    mmr
    mmrData Array Array of mmrData
    Return data in shockFactor ascending order
    > shockFactor String Price change ratio, data range -1 to 1.
    > mmr String Mmr at specific price
    > mmrRatio String Maintenance margin ratio at specific price

    Set risk offset amount

    Set risk offset amount. This does not represent the actual spot risk offset amount. Only applicable to Portfolio Margin Mode.

    Rate Limit: 10 requests per 2 seconds

    Rate limit rule: User ID

    HTTP Request

    POST /api/v5/account/set-riskOffset-amt

    Request Example

    # Set spot risk offset amount
    POST /api/v5/account/set-riskOffset-amt
    body
    {
       "ccy": "BTC",
       "clSpotInUseAmt": "0.5"
    }
    
    

    Request Parameters

    Parameter Type Required Description
    ccy String Yes Currency
    clSpotInUseAmt String Yes Spot risk offset amount defined by users

    Response Example

    {
       "code": "0",
       "msg": "",
       "data": [
          {
             "ccy": "BTC",
             "clSpotInUseAmt": "0.5"
          }
       ]
    }
    

    Response Parameters

    Parameters Types Description
    ccy String Currency
    clSpotInUseAmt String Spot risk offset amount defined by users

    Get Greeks

    Retrieve a greeks list of all assets in the account.

    Rate Limit: 10 requests per 2 seconds

    Rate limit rule: User ID

    HTTP Request

    GET /api/v5/account/greeks

    Request Example

    # Get the greeks of all assets in the account
    GET /api/v5/account/greeks
    
    # Get the greeks of BTC assets in the account
    GET /api/v5/account/greeks?ccy=BTC
    
    
    import okx.Account as Account
    
    # API initialization
    apikey = "YOUR_API_KEY"
    secretkey = "YOUR_SECRET_KEY"
    passphrase = "YOUR_PASSPHRASE"
    
    flag = "1"  # Production trading:0 , demo trading:1
    
    accountAPI = Account.AccountAPI(apikey, secretkey, passphrase, False, flag)
    
    # Retrieve a greeks list of all assets in the account
    result = accountAPI.get_greeks()
    print(result)
    

    Request Parameters

    Parameters Types Required Description
    ccy String No Single currency, e.g. BTC.

    Response Example

    {
        "code":"0",
        "data":[
            {            
               "thetaBS": "",
               "thetaPA":"",
               "deltaBS":"",
               "deltaPA":"",
               "gammaBS":"",
               "gammaPA":"",
               "vegaBS":"",    
               "vegaPA":"",
               "ccy":"BTC",
               "ts":"1620282889345"
            }
        ],
        "msg":""
    }
    

    Response Parameters

    Parameters Types Description
    deltaBS String delta: Black-Scholes Greeks in dollars
    deltaPA String delta: Greeks in coins
    gammaBS String gamma: Black-Scholes Greeks in dollars, only applicable to OPTION
    gammaPA String gamma: Greeks in coins, only applicable to OPTION
    thetaBS String theta: Black-Scholes Greeks in dollars, only applicable to OPTION
    thetaPA String theta: Greeks in coins, only applicable to OPTION
    vegaBS String vega: Black-Scholes Greeks in dollars, only applicable to OPTION
    vegaPA String vega:Greeks in coins, only applicable to OPTION
    ccy String Currency
    ts String Time of getting Greeks, Unix timestamp format in milliseconds, e.g. 1597026383085

    Get PM position limitation

    Retrieve cross position limitation of SWAP/FUTURES/OPTION under Portfolio margin mode.

    Rate Limit: 10 requests per 2 seconds

    Rate limit rule: User ID

    HTTP Request

    GET /api/v5/account/position-tiers

    Request Example

    # Query limitation of BTC-USDT
    GET /api/v5/account/position-tiers?instType=SWAP&uly=BTC-USDT
    
    
    import okx.Account as Account
    
    # API initialization
    apikey = "YOUR_API_KEY"
    secretkey = "YOUR_SECRET_KEY"
    passphrase = "YOUR_PASSPHRASE"
    
    flag = "1"  # Production trading:0 , demo trading:1
    
    accountAPI = Account.AccountAPI(apikey, secretkey, passphrase, False, flag)
    
    # Get PM position limitation
    result = accountAPI.get_account_position_tiers(
        instType="SWAP",
        uly="BTC-USDT"
    )
    print(result)
    

    Request Parameters

    Parameter Type Required Description
    instType String Yes Instrument type
    SWAP
    FUTURES
    OPTION
    instFamily String Yes Single instrument family or instrument families (no more than 5) separated with comma.

    Response Example

    {
      "code": "0",
      "data": [
        {
          "instFamily": "BTC-USDT",
          "maxSz": "10000",
          "posType": "",
          "uly": "BTC-USDT"
        }
      ],
      "msg": ""
    }
    

    Response Parameters

    Parameter Type Description
    uly String Underlying
    Applicable to FUTURES/SWAP/OPTION
    instFamily String Instrument family
    Applicable to FUTURES/SWAP/OPTION
    maxSz String Max number of positions
    posType String Limitation of position type, only applicable to cross OPTION under portfolio margin mode
    1: Contracts of pending orders and open positions for all derivatives instruments. 2: Contracts of pending orders for all derivatives instruments. 3: Pending orders for all derivatives instruments. 4: Contracts of pending orders and open positions for all derivatives instruments on the same side. 5: Pending orders for one derivatives instrument. 6: Contracts of pending orders and open positions for one derivatives instrument. 7: Contracts of one pending order.

    Activate option

    Rate Limit: 5 requests per 2 seconds

    Rate limit rule: User ID

    HTTP Request

    POST /api/v5/account/activate-option

    Request Example

    POST /api/v5/account/activate-option
    
    

    Request Parameters

    None

    Response Example

    {
        "code": "0",
        "msg": "",
        "data": [{
            "ts": "1600000000000"
        }]
    }
    

    Response Parameters

    Parameter Type Description
    ts String Activation time

    Set auto loan

    Only applicable to Multi-currency margin and Portfolio margin

    Rate Limit: 5 requests per 2 seconds

    Rate limit rule: User ID

    HTTP Request

    POST /api/v5/account/set-auto-loan

    Request Example

    POST /api/v5/account/set-auto-loan
    body
    {
        "autoLoan":true,
    }
    

    Request Parameters

    Parameter Type Required Description
    autoLoan Boolean No Whether to automatically make loans
    Valid values are true, false
    The default is true

    Response Example

    {
        "code": "0",
        "msg": "",
        "data": [{
            "autoLoan": true
        }]
    }
    

    Response Parameters

    Parameter Type Description
    autoLoan Boolean Whether to automatically make loans

    Preset account mode switch

    Pre-set the required information for account mode switching. When switching from Portfolio margin mode back to Futures mode / Multi-currency margin mode, and if there are existing cross-margin contract positions, it is mandatory to pre-set leverage.

    If the user does not follow the required settings, they will receive an error message during the pre-check or when setting the account mode.

    Rate limit: 5 requests per 2 seconds

    Rate limit rule: User ID

    HTTP Request

    POST /api/v5/account/account-level-switch-preset

    Request example

    # 1. Futures mode -> Multi-currency margin mode
    POST /api/v5/account/account-level-switch-preset
    {
        "acctLv": "3"
    }
    
    # 2. Multi-currency margin mode -> Futures mode
    POST /api/v5/account/account-level-switch-preset
    {
        "acctLv": "2"
    }
    
    # 3. Portfolio margin mode -> Futures mode/Multi-currency margin mode, the user have cross-margin contract position and lever is required
    POST /api/v5/account/account-level-switch-preset
    {
        "acctLv": "2",
        "lever": "10"
    }
    
    # 4. Portfolio margin mode -> Futures mode/Multi-currency margin mode, the user doesn't have cross-margin contract position and lever is not required
    POST /api/v5/account/account-level-switch-preset
    {
        "acctLv": "3"
    }
    
    

    Request parameters

    Parameter Type Required Description
    acctLv String Yes Account mode
    2: Futures mode
    3: Multi-currency margin code
    4: Portfolio margin mode
    lever String Optional Leverage
    Required when switching from Portfolio margin mode to Futures mode or Multi-currency margin mode, and the user holds cross-margin positions.
    riskOffsetType String Optional Risk offset type
    1: Spot-derivatives (USDT) risk offset
    2: Spot-derivatives (Crypto) risk offset
    3: Derivatives only mode
    4: Spot-derivatives (USDC) risk offset
    Applicable when switching from Futures mode or Multi-currency margin mode to Portfolio margin mode.
    (Deprecated)

    Response example 1. Futures mode -> Multi-currency margin mode

    {
        "acctLv": "3",
        "curAcctLv": "2",
        "lever": "",
        "riskOffsetType": ""
    }
    

    Response example 2. Multi-currency margin mode -> Futures mode

    {
        "acctLv": "2",
        "curAcctLv": "3",
        "lever": "",
        "riskOffsetType": ""
    }
    

    Response example 3. Portfolio margin mode -> Futures mode/Multi-currency margin mode

    {
        "acctLv": "2",
        "curAcctLv": "4",
        "lever": "10",
        "riskOffsetType": ""
    }
    

    Response example 4. Portfolio margin mode -> Futures mode/Multi-currency margin mode

    {
        "acctLv": "3",
        "curAcctLv": "4",
        "lever": "",
        "riskOffsetType": ""
    }
    

    Response parameters

    Parameter Type Description
    curAcctLv String Current account mode
    acctLv String Account mode after switch
    lever String The leverage user preset for cross-margin positions
    riskOffsetType String The risk offset type user preset(Deprecated)

    Precheck account mode switch

    Retrieve precheck information for account mode switching.

    Rate limit: 5 requests per 2 seconds

    Rate limit rule: User ID

    HTTP Request

    GET /api/v5/account/set-account-switch-precheck

    Request example

    GET /api/v5/account/set-account-switch-precheck?acctLv=3
    
    

    Request parameters

    Parameter Type Required Description
    acctLv String Yes Account mode
    1: Spot mode
    2: Futures mode
    3: Multi-currency margin code
    4: Portfolio margin mode

    Response example. Futures mode->Portfolio margin mode, need to finish the Q&A on web or mobile first

    {
        "code": "51070",
        "data": [],
        "msg": "You do not meet the requirements for switching to this account mode. Please upgrade the account mode on the OKX website or App"
    }
    

    Response example. Futures mode->Portfolio margin mode, unmatched information. sCode 1

    {
        "code": "0",
        "data": [
            {
                "acctLv": "3",
                "curAcctLv": "1",
                "mgnAft": null,
                "mgnBf": null,
                "posList": [],
                "posTierCheck": [],
                "riskOffsetType": "",
                "sCode": "1",
                "unmatchedInfoCheck": [
                    {
                        "posList": [],
                        "totalAsset": "",
                        "type": "repay_borrowings"
                    }
                ]
            }
        ],
        "msg": ""
    }
    

    Response example. Portfolio margin mode->Multi-currency margin code, the user has cross-margin positions but doesn't preset leverage. sCode 3

    {
        "code": "0",
        "data": [
            {
                "acctLv": "3",
                "curAcctLv": "4",
                "mgnAft": null,
                "mgnBf": null,
                "posList": [
                    {
                        "lever": "50",
                        "posId": "2005456500916518912"
                    },
                    {
                        "lever": "10",
                        "posId": "2005456108363218944"
                    },
                    {
                        "lever": "100",
                        "posId": "2005456332909477888"
                    },
                    {
                        "lever": "1",
                        "posId": "2005456415990251520"
                    }
                ],
                "posTierCheck": [],
                "riskOffsetType": "",
                "sCode": "3",
                "unmatchedInfoCheck": []
            }
        ],
        "msg": ""
    }
    

    Response example. Portfolio margin mode->Multi-currency margin code, the user finishes the leverage setting to 10, and passes the position tier an margin check. sCode 0.

    {
        "code": "0",
        "data": [
            {
                "acctLv": "3",
                "curAcctLv": "4",
                "mgnAft": {
                    "acctAvailEq": "106002.2061970689",
                    "details": [],
                    "mgnRatio": "148.1652396878421"
                },
                "mgnBf": {
                    "acctAvailEq": "77308.89735228613",
                    "details": [],
                    "mgnRatio": "4.460069474634038"
                },
                "posList": [
                    {
                        "lever": "50",
                        "posId": "2005456500916518912"
                    },
                    {
                        "lever": "50",
                        "posId": "2005456108363218944"
                    },
                    {
                        "lever": "50",
                        "posId": "2005456332909477888"
                    },
                    {
                        "lever": "50",
                        "posId": "2005456415990251520"
                    }
                ],
                "posTierCheck": [],
                "riskOffsetType": "",
                "sCode": "0",
                "unmatchedInfoCheck": []
            }
        ],
        "msg": ""
    }
    
    

    Response parameters

    Parameter Type Description
    sCode String Check code
    0: pass all checks
    1: unmatched information
    3: leverage setting is not finished
    4: position tier or margin check is not passed
    curAcctLv String Account mode
    1: Spot mode
    2: Futures mode
    3: Multi-currency margin code
    4: Portfolio margin mode
    Applicable to all scenarios
    acctLv String Account mode
    1: Spot mode
    2: Futures mode
    3: Multi-currency margin code
    4: Portfolio margin mode
    Applicable to all scenarios
    riskOffsetType String Risk offset type
    1: Spot-derivatives (USDT) risk offset
    2: Spot-derivatives (Crypto) risk offset
    3: Derivatives only mode
    4: Spot-derivatives (USDC) risk offset
    Applicable when acctLv is 4, return "" for other scenarios
    If the user preset before, it will use the user's specified value; if not, the default value 3 will be applied
    (Deprecated)
    unmatchedInfoCheck Array of objects Unmatched information list
    Applicable when sCode is 1, indicating there is unmatched information; return [] for other scenarios
    >> type String Unmatched information type
    asset_validation: asset validation
    pending_orders: order book pending orders
    pending_algos: pending algo orders and trading bots, such as iceberg, recurring buy and twap
    isolated_margin: isolated margin (quick margin and manual transfers)
    isolated_contract: isolated contract (manual transfers)
    contract_long_short: contract positions in hedge mode
    cross_margin: cross margin positions
    cross_option_buyer: cross options buyer
    isolated_option: isolated options (only applicable to spot mode)
    growth_fund: positions with trial funds
    all_positions: all positions
    spot_lead_copy_only_simple_single: copy trader and customize lead trader can only use spot mode or Futures mode
    stop_spot_custom: spot customize copy trading
    stop_futures_custom: contract customize copy trading
    lead_portfolio: lead trader can not switch to portfolio margin mode
    futures_smart_sync: you can not switch to spot mode when having smart contract sync
    vip_fixed_loan: vip loan
    repay_borrowings: borrowings
    compliance_restriction: due to compliance restrictions, margin trading services are unavailable
    compliance_kyc2: Due to compliance restrictions, margin trading services are unavailable. If you are not a resident of this region, please complete kyc2 identity verification.
    >> totalAsset String Total assets
    Only applicable when type is asset_validation, return "" for other scenarios
    >> posList Array of strings Unmatched position list (posId)
    Applicable when type is related to positions, return [] for other scenarios
    posList Array of objects Cross margin contract position list
    Applicable when curAcctLv is 4, acctLv is 2/3 and user has cross margin contract positions
    Applicable when sCode is 0/3/4
    > posId String Position ID
    > lever String Leverage of cross margin contract positions after switch
    posTierCheck Array of objects Cross margin contract positions that don't pass the position tier check
    Only applicable when sCode is 4
    > instFamily String Instrument family
    > instType String Instrument type
    SWAP
    FUTURES
    OPTION
    > pos String Quantity of position
    > lever String Leverage
    > maxSz String If acctLv is 2/3, it refers to the maximum position size allowed at the current leverage. If acctLv is 4, it refers to the maximum position limit for cross-margin positions under the PM mode.
    mgnBf Object The margin related information before switching account mode
    Applicable when sCode is 0/4, return null for other scenarios
    > acctAvailEq String Account available equity in USD
    Applicable when curAcctLv is 3/4, return "" for other scenarios
    > mgnRatio String Maintenance Margin ratio in USD
    Applicable when curAcctLv is 3/4, return "" for other scenarios
    > details Array of objects Detailed information
    Only applicable when curAcctLv is 2, return "" for other scenarios
    >> ccy String Currency
    >> availEq String Available equity of currency
    >> mgnRatio String Maintenance margin ratio of currency
    mgnAft Object The margin related information after switching account mode
    Applicable when sCode is 0/4, return null for other scenarios
    > acctAvailEq String Account available equity in USD
    Applicable when acctLv is 3/4, return "" for other scenarios
    > mgnRatio String Maintenance margin ratio in USD
    Applicable when acctLv is 3/4, return "" for other scenarios
    > details Array of objects Detailed information
    Only applicable when acctLv is 2, return "" for other scenarios
    >> ccy String Currency
    >> availEq String Available equity of currency
    >> mgnRatio String Maintenance margin ratio of currency

    Set account mode

    You need to set on the Web/App for the first set of every account mode. If users plan to switch account modes while holding positions, they should first call the preset endpoint to conduct necessary settings, then call the precheck endpoint to get unmatched information, margin check, and other related information, and finally call the account mode switch endpoint to switch account modes.

    Rate Limit: 5 requests per 2 seconds

    Rate limit rule: User ID

    HTTP Request

    POST /api/v5/account/set-account-level

    Request Example

    POST /api/v5/account/set-account-level
    body
    {
        "acctLv":"1"
    }
    

    Request Parameters

    Parameter Type Required Description
    acctLv String Yes Account mode
    1: Spot mode
    2: Futures mode
    3: Multi-currency margin code
    4: Portfolio margin mode

    Response Example

    {
        "code": "0",
        "data": [
            {
                "acctLv": "1"
            }
        ],
        "msg": ""
    }
    

    Response Parameters

    Parameter Type Description
    acctLv String Account mode

    Set collateral assets

    Rate Limit: 5 requests per 2 seconds

    Rate limit rule: User ID

    HTTP Request

    POST /api/v5/account/set-collateral-assets

    Request Example

    # Set all assets to be collateral
    POST /api/v5/account/set-collateral-assets
    body
    {
        "type":"all",
        "collateralEnabled":true
    }
    
    
    # Set custom assets to be non-collateral
    POST /api/v5/account/set-collateral-assets
    body
    {
        "type":"custom",
        "ccyList":["BTC","ETH"],
        "collateralEnabled":false
    }
    

    Request Parameters

    Parameter Type Required Description
    type String true Type
    all
    custom
    collateralEnabled Boolean true Whether or not set the assets to be collateral
    true: Set to be collateral
    false: Set to be non-collateral
    ccyList Array of strings conditional Currency list, e.g. ["BTC","ETH"]
    If type=custom, the parameter is required.

    Response Example

    {
        "code":"0",
        "msg":"",
        "data" :[
          {
            "type":"all",
            "ccyList":["BTC","ETH"],
            "collateralEnabled":false
          }
        ]  
    }
    

    Response Parameters

    Parameter Type Description
    type String Type
    all
    custom
    collateralEnabled Boolean Whether or not set the assets to be collateral
    true: Set to be collateral
    false: Set to be non-collateral
    ccyList Array of strings Currency list, e.g. ["BTC","ETH"]

    Get collateral assets

    Rate Limit: 5 requests per 2 seconds

    Rate limit rule: User ID

    HTTP Request

    GET /api/v5/account/collateral-assets

    Request Example

    GET /api/v5/account/collateral-assets
    

    Request Parameters

    Parameters Types Required Description
    ccy String No Single currency or multiple currencies (no more than 20) separated with comma, e.g. "BTC" or "BTC,ETH".
    collateralEnabled Boolean No Whether or not to be a collateral asset

    Response Example

    {
        "code":"0",
        "msg":"",
        "data" :[
              {
                "ccy":"BTC",
                "collateralEnabled": true
              },
              {
                "ccy":"ETH",
                "collateralEnabled": false
              }
        ]  
    }
    

    Response Parameters

    Parameter Type Description
    ccy String Currency, e.g. BTC
    collateralEnabled Boolean Whether or not to be a collateral asset

    Reset MMP Status

    You can unfreeze by this endpoint once MMP is triggered.

    Only applicable to Option in Portfolio Margin mode, and MMP privilege is required.

    Rate Limit: 5 requests per 2 seconds

    Rate limit rule: User ID

    HTTP Request

    POST /api/v5/account/mmp-reset

    Request Example

    POST /api/v5/account/mmp-reset
    body
    {
        "instType":"OPTION",
        "instFamily":"BTC-USD"
    }
    

    Request Parameters

    Parameter Type Required Description
    instType String No Instrument type
    OPTION
    The default is `OPTION
    instFamily String Yes Instrument family

    Response Example

    {
        "code":"0",
        "msg":"",
        "data":[
            {
                "result":true
            }
        ]
    }
    

    Response Parameters

    Parameter Type Description
    result Boolean Result of the request true, false

    Set MMP

    This endpoint is used to set MMP configure

    Only applicable to Option in Portfolio Margin mode, and MMP privilege is required.

    Rate Limit: 2 requests per 10 seconds

    Rate limit rule: User ID

    HTTP Request

    POST /api/v5/account/mmp-config

    Request Example

    POST /api/v5/account/mmp-config
    body
    {
        "instFamily":"BTC-USD",
        "timeInterval":"5000",
        "frozenInterval":"2000",
        "qtyLimit": "100"
    }
    
    

    Request Parameters

    Parameter Type Required Description
    instFamily String Yes Instrument family
    timeInterval String Yes Time window (ms). MMP interval where monitoring is done
    "0" means disable MMP
    frozenInterval String Yes Frozen period (ms).
    "0" means the trade will remain frozen until you request "Reset MMP Status" to unfrozen
    qtyLimit String Yes Trade qty limit in number of contracts
    Must be > 0

    Response Example

    {
      "code": "0",
      "msg": "",
      "data": [
        {
            "frozenInterval":"2000",
            "instFamily":"BTC-USD",
            "qtyLimit": "100",
            "timeInterval":"5000"
        }
      ]
    }
    

    Response Parameters

    Parameter Type Description
    instFamily String Instrument family
    timeInterval String Time window (ms). MMP interval where monitoring is done
    frozenInterval String Frozen period (ms).
    qtyLimit String Trade qty limit in number of contracts

    GET MMP Config

    This endpoint is used to get MMP configure information

    Only applicable to Option in Portfolio Margin mode, and MMP privilege is required.

    Rate Limit: 5 requests per 2 seconds

    Rate limit rule: User ID

    HTTP Request

    GET /api/v5/account/mmp-config

    Request Example

    GET /api/v5/account/mmp-config?instFamily=BTC-USD
    
    

    Request Parameters

    Parameter Type Required Description
    instFamily String No Instrument Family

    Response Example

    {
      "code": "0",
      "data": [
        {
          "frozenInterval": "2000",
          "instFamily": "ETH-USD",
          "mmpFrozen": true,
          "mmpFrozenUntil": "1000",
          "qtyLimit": "10",
          "timeInterval": "5000"
        }
      ],
      "msg": ""
    }
    

    Response Parameters

    Parameter Type Description
    instFamily String Instrument Family
    mmpFrozen Boolean Whether MMP is currently triggered. true or false
    mmpFrozenUntil String If frozenInterval is configured and mmpFrozen = True, it is the time interval (in ms) when MMP is no longer triggered, otherwise "".
    timeInterval String Time window (ms). MMP interval where monitoring is done
    frozenInterval String Frozen period (ms). If it is "0", the trade will remain frozen until manually reset and mmpFrozenUntil will be "".
    qtyLimit String Trade qty limit in number of contracts

    Move positions

    Only applicable to users with a trading level greater than or equal to VIP6, and can only be called through the API Key of the master account. Users can check their trading level through the fee details table on the My trading fees page.

    To move positions between different accounts under the same master account. Each source account can trigger up to fifteen move position requests every 24 hours. There is no limitation to the destination account to receive positions. Refer to the "Things to note" part for more details.

    Rate limit: 1 request per second

    Rate limit rule: Master account User ID

    HTTP Request

    POST /api/v5/account/move-positions

    Request example

    {
       "fromAcct":"0",
       "toAcct":"test",
       "legs":[
          {
             "from":{
                "posId":"2065471111340792832",
                "side":"sell",
                "sz":"1"
             },
             "to":{
                "posSide":"net",
                "tdMode":"cross"
             }
          },
          {
             "from":{
                "posId":"2063111180412153856",
                "side":"sell",
                "sz":"1"
             },
             "to":{
                "posSide":"net",
                "tdMode":"cross"
             }
          }
       ],
       "clientId":"test"
    }
    

    Request parameters

    Parameter Type Required Description
    fromAcct String Yes Source account name. If it's a master account, it should be "0"
    toAcct String Yes Destination account name. If it's a master account, it should be "0"
    legs Array of Objects Yes An array of objects containing details of each position to be moved
    > from Object yes Details of the position in the source account
    >> posId String Yes Position ID in the source account
    >> sz String Yes Number of contracts.
    >> side String Yes Trade side from the perspective of source account
    buy
    sell
    > to Object Yes Details of the configuration of the destination account
    >> tdMode String No Trading mode in the destination account.
    cross
    isolated
    If not provided, tdMode will take the default values as shown below:
    Buy options in Futures mode/Multi-currency margin mode: isolated
    Other cases: cross
    >> posSide String No Position side
    net
    long
    short
    This parameter is not mandatory if the destination sub-account is in net mode. If you pass it through, the only valid value is net.It can only be long or short if the destination sub-account is in long/short mode. If not specified, destination account in long/short mode always open new positions.
    >> ccy String No Margin currency in destination accountOnly applicable to cross margin positions in Futures mode.
    clientId String Yes Client-supplied ID. A combination of case-sensitive alphanumerics, all numbers, or all letters of up to 32 characters.

    Response example

    {
        "code": "0",
        "msg": "",
        "data": [
            {
                "clientId": "test",
                "blockTdId": "2065832911119076864",
                "state": "filled",
                "ts": "1734069018526",
                "fromAcct": "0",
                "toAcct": "test",
                "legs": [
                    {
                        "from": {
                            "posId": "2065471111340792832",
                            "instId": "BTC-USD-SWAP",
                            "px": "100042.7",
                            "side": "sell",
                            "sz": "1",
                            "sCode": "0",
                            "sMsg": ""
                        },
                        "to": {
                            "instId": "BTC-USD-SWAP",
                            "px": "100042.7",
                            "side": "buy",
                            "sz": "1",
                            "tdMode": "cross",
                            "posSide": "net",
                            "ccy": "",
                            "sCode": "0",
                            "sMsg": ""
                        }
                    },
                    {
                        "from": {
                            "posId": "2063111180412153856",
                            "instId": "BTC-USDT-SWAP",
                            "px": "100008.1",
                            "side": "sell",
                            "sz": "1",
                            "sCode": "0",
                            "sMsg": ""
                        },
                        "to": {
                            "instId": "BTC-USDT-SWAP",
                            "px": "100008.1",
                            "side": "buy",
                            "sz": "1",
                            "tdMode": "cross",
                            "posSide": "net",
                            "ccy": "",
                            "sCode": "0",
                            "sMsg": ""
                        }
                    }
                ]
            }
        ]
    }
    
    

    Response example:failure

    // The destination account position mode (net/longShort) is not matched with the posSide field
    {
        "code": "51000",
        "msg": "Incorrect type of posSide (leg with Instrument Id [BTC-USD-SWAP])",
        "data": []
    }
    
    // The BTC amount in the destination account is not enough to open the position.
    {
        "code": "51008",
        "msg": "Order failed. Insufficient BTC margin in account",
        "data": []
    }
    
    // TradeFi positions are not supported.
    {
        "code": "70004",
        "msg": "Invalid instrument ID XAG-USDT-SWAP",
        "data": []
    }
    
    

    Response parameters

    Parameter Type Description
    code String The result code, 0 means success
    msg String The error message, empty if the code is 0
    blockTdId String Block trade ID
    clientId String Client-supplied ID
    state String Status of the order filled, failed
    fromAcct String Source account name
    toAcct String Destination account name
    legs Array An array of objects containing details of each position to be moved
    > from Object Object describing the "from" leg
    >> instId String Instrument ID
    >> posId String Position ID
    >> px String Transfer price, typically a 60-minute TWAP of the mark price
    >> side String Direction of the leg in the source account
    buy
    sell
    >> sz String Number of Contracts
    >> sCode String The code of the event execution result, 0 means success
    >> sMsg String Rejection message if the request is unsuccessful
    > to Object Object describing the "to" leg
    >> instId String Instrument ID
    >> side String Trade side of the trade in the destination account
    >> posSide String Position side of the trade in the destination account
    >> tdMode String Trade mode
    >> px String Transfer price, typically a 60-minute TWAP of the mark price
    >> ccy String Margin currency
    >> sCode String The code of the event execution result, 0 means success
    >> sMsg String Rejection message if the request is unsuccessful
    ts String Unix timestamp in milliseconds indicating when the transfer request was processed

    Things to note

    1. Only applicable to users with a trading level greater than or equal to VIP6, and can only be called through the API Key of the master account.
    2. The source and destination accounts for move positions must be accounts under the same master account and they must be different.
    3. For source account, a maximum of fifteen move position requests can be triggered within a 24-hour period. There is no limitation to the destination account to receive positions. Only successful requests are counted toward this limit.
    4. The maximum number of legs per move position request is 30.
    5. No move position fee will be charged at this time.
    6. Moving positions is not supported in margin trading now.
    7. TradeFi positions are not supported.
    8. The move position price is determined by the TWAP (Time-Weighted Average Price) of the mark price over the past 60 minutes, using the closing mark price per minute. If the symbol is newly listed and a 60-minute TWAP is unavailable, the move position will be rejected with error code 70065
    9. The move position will share the same price limit as those in the order book. The move position will fail if the 60-minute mark price TWAP is outside of the price limit.
    10. For the source account, move positions must be conducted in a reduce-only manner. You must choose the opposite side of your current position and specify a size equal to or smaller than your existing position size. The system will also process move position requests in a best-effort reduce-only manner.
    11. The side field of source account leg (from) should be sell if you are holding a long position while the side of destination account leg (to) should be buy, vice versa for a short position.
    12. The posSide field of destination account (to) should be net if it's in one-way mode; long/short if it's in hedge mode. If in hedge mode, you need to specify long/short to decide whether to close current positions or open reverse positions. Otherwise, it will always open new positions.
      1. Open long: buy and open long (side: buy; posSide: long)
      2. Open short: sell and open short (side: sell; posSide: short)
      3. Close long: sell and close long (side: sell; posSide: long)
      4. Close short: buy and close short (side: buy; posSide: short)
    13. Historical records of move positions can be fetched from the Get move positions history endpoint but only for pending or successful requests.
    14. Move positions operation counting example.
    Transfer done within the day Account A count (total) Account B count (total) Account C count (total) Account D count (total)
    Account A to Account B 1 0 0 0
    Account B to Account C 1 1 0 0
    Account B to Account D 1 2 0 0

    Get move positions history

    Only applicable to users with a trading level greater than or equal to VIP6, and can only be called through the API Key of the master account. Users can check their trading level through the fee details table on the My trading fees page.

    Retrieve move position details in the last 3 days.

    Rate limit: 2 requests per 2 seconds

    Rate limit rule: Master account UserID

    HTTP Request

    GET /api/v5/account/move-positions-history

    Request example

    Get /api/v5/account/move-positions-history
    
    

    Request parameters

    Parameter Type Required Description
    blockTdId String No BlockTdId generated by the system
    clientId String No Client-supplied ID. A combination of case-sensitive alphanumerics, all numbers, or all letters of up to 32 characters.
    beginTs String No Filter with a begin timestamp. Unix timestamp format in milliseconds (inclusive)
    endTs String No Filter with an end timestamp. Unix timestamp format in milliseconds (inclusive)
    limit String No Number of results per request. The maximum and default are both 100
    state String No Positions transfer state, filled pending

    Response example

    {
        "code": "0",
        "msg": "",
        "data": [
            {
                "clientId": "test",
                "blockTdId": "2066393411110139648",
                "state": "filled",
                "ts": "1734085725000",
                "fromAcct": "0",
                "toAcct": "test",
                "legs": [
                    {
                        "from": {
                            "posId": "2065477911110792832",
                            "instId": "BTC-USD-SWAP",
                            "px": "100123.8",
                            "side": "sell",
                            "sz": "1"
                        },
                        "to": {
                            "instId": "BTC-USD-SWAP",
                            "px": "100123.8",
                            "side": "buy",
                            "sz": "1",
                            "tdMode": "cross",
                            "posSide": "net",
                            "ccy": ""
                        }
                    },
                    {
                        "from": {
                            "posId": "2063533111112153856",
                            "instId": "BTC-USDT-SWAP",
                            "px": "100078.7",
                            "side": "sell",
                            "sz": "1"
                        },
                        "to": {
                            "instId": "BTC-USDT-SWAP",
                            "px": "100078.7",
                            "side": "buy",
                            "sz": "1",
                            "tdMode": "cross",
                            "posSide": "net",
                            "ccy": ""
                        }
                    }
                ]
            }
       ]
    }
    
    

    Response parameters

    Parameter Type Description
    clientId String Client-supplied ID. A combination of case-sensitive alphanumerics, all numbers, or all letters of up to 32 characters.
    blockTdId String Block trade ID.
    state String Position transfer state, filled pending
    ts String Unix timestamp in milliseconds indicating when the transfer request was processed
    fromAcct String Source account name
    toAcct String Destination account name
    legs Array An array of objects containing details of each position to be moved
    > from Object Object describing the "from" leg
    >> instId String Instrument ID
    >> posId String Position ID
    >> px String Transfer price, typically a 60-minute TWAP of the mark price
    >> side String Direction of the leg in the source account
    buy
    sell
    >> sz String Number of Contracts
    > to Object Object describing the "to" leg
    >> instId String Instrument ID
    >> px String Transfer price, typically a 60-minute TWAP of the mark price
    >> side String Trade side from the perspective of destination account
    buy
    sell
    >> sz String Number of contracts.
    >> tdMode String Trading mode in the destination account
    cross
    isolated
    >> posSide String Position side
    net
    long
    short
    >> ccy String Margin currency in destination account
    Only applicable to cross margin positions in Futures mode.