Trading Account¶
The API endpoints of Trading 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
- ***Permission**: Read
| Parameter | Type | Required | Description |
|---|---|---|---|
| instType | String | Yes | Instrument type: SPOT, MARGIN, SWAP, FUTURES, OPTION |
| uly | String | No | Underlying. Required for FUTURES/SWAP/OPTION |
| instFamily | String | No | Instrument family. Required for OPTION |
| instId | String | No | Instrument ID |
Python Example:
import okx.Account as Account
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)
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
- ***Permission**: Read
| Parameter | Type | Required | Description |
|---|---|---|---|
| ccy | String | No | Currency, e.g. BTC or BTC,ETH |
Python Example:
import okx.Account as Account
accountAPI = Account.AccountAPI(apikey, secretkey, passphrase, False, flag)
result = accountAPI.get_account_balance()
print(result)
{
"code": "0",
"data": [{
"adjEq": "55415.624719833286",
"availEq": "55415.624719833286",
"totalEq": "55837.43556134779",
"details": [{
"availBal": "4834.317093622894",
"availEq": "4834.3170936228935",
"cashBal": "4850.435693622894",
"ccy": "USDT",
"eq": "4992.890093622894",
"eqUsd": "4991.542013297616",
"frozenBal": "158.573",
"interest": "0",
"liab": "0",
"upl": "-7.545600000000006"
}]
}],
"msg": ""
}
Get positions¶
Retrieve information on your positions.
- ***Rate Limit**: 10 requests per 2 seconds
- ***Rate limit rule**: User ID
- ***Permission**: Read
| Parameter | Type | Required | Description |
|---|---|---|---|
| instType | String | No | MARGIN, SWAP, FUTURES, OPTION |
| instId | String | No | Instrument ID, e.g. BTC-USDT-SWAP |
| posId | String | No | Position ID |
Python Example:
accountAPI = Account.AccountAPI(apikey, secretkey, passphrase, False, flag)
result = accountAPI.get_positions()
print(result)
Get positions history¶
Retrieve the updated position data for the last 3 months.
- ***Rate Limit**: 10 requests per 2 seconds
- ***Rate limit rule**: User ID
- ***Permission**: Read
| Parameter | Type | Required | Description |
|---|---|---|---|
| instType | String | No | MARGIN, SWAP, FUTURES, OPTION |
| instId | String | No | Instrument ID |
| mgnMode | String | No | cross, isolated |
| type | String | No | Close type: 1 Partially closed, 2 Fully closed, 3 Liquidation, 4 Partial liquidation, 5 ADL, 6 Auto-deleveraging |
| after | String | No | Pagination |
| before | String | No | Pagination |
| limit | String | No | Default 100, max 100 |
Get account and position risk¶
- ***Rate Limit**: 10 requests per 2 seconds
- ***Rate limit rule**: User ID
- ***Permission**: Read
Get bills details (last 7 days)¶
Retrieve the bills of the account. Pagination supported, sorted with most recent first.
- ***Rate Limit**: 5 requests per second
- ***Rate limit rule**: User ID
- ***Permission**: Read
Get bills details (last 3 months)¶
- ***Rate Limit**: 5 requests per 2 seconds
- ***Rate limit rule**: User ID
- ***Permission**: Read
Apply bills details (since 2021)¶
Get bills details (since 2021)¶
Get account configuration¶
Retrieve current account configuration.
- ***Rate Limit**: 5 requests per 2 seconds
- ***Rate limit rule**: User ID
- ***Permission**: Read
accountAPI = Account.AccountAPI(apikey, secretkey, passphrase, False, flag)
result = accountAPI.get_account_config()
print(result)
| Field | Description |
|---|---|
| acctLv | Account level: 1 Spot mode, 2 Futures mode, 3 Multi-currency margin, 4 Portfolio margin |
| posMode | Position mode: long_short_mode, net_mode |
| autoLoan | Auto-loan: true, false |
| greeksType | Greeks display: PA (price), BS (Black-Scholes) |
| uid | User ID |
| mainUid | Main account UID |
| level | Fee level, e.g. Lv1 |
Set position mode¶
- ***Rate Limit**: 5 requests per 2 seconds
- ***Permission**: Trade
| Parameter | Type | Required | Description |
|---|---|---|---|
| posMode | String | Yes | long_short_mode or net_mode |
Set leverage¶
- ***Rate limit**: 20 requests per 2 seconds
- ***Permission**: Trade
| Parameter | Type | Required | Description |
|---|---|---|---|
| instId | String | Conditional | Instrument ID |
| ccy | String | Conditional | Currency |
| lever | String | Yes | Leverage |
| mgnMode | String | Yes | cross or isolated |
| posSide | String | Conditional | long, short (required for isolated long/short mode) |
Get maximum order quantity¶
- ***Rate Limit**: 20 requests per 2 seconds
- ***Permission**: Read
Get maximum available balance/equity¶
Increase/decrease margin¶
Get leverage¶
- ***Rate Limit**: 20 requests per 2 seconds
- ***Permission**: Read
Get leverage estimated info¶
Get the maximum loan of instrument¶
Get fee rates¶
- ***Rate Limit**: 5 requests per 2 seconds
- ***Permission**: Read
| Parameter | Type | Required | Description |
|---|---|---|---|
| instType | String | Yes | SPOT, MARGIN, SWAP, FUTURES, OPTION |
| instId | String | No | Instrument ID |
| uly | String | No | Underlying |
| instFamily | String | No | Instrument family |
Get interest accrued data¶
Get interest rate¶
Set fee type¶
Set greeks (PA/BS)¶
Isolated margin trading settings¶
Get maximum withdrawals¶
Get account risk state¶
Only applicable to Portfolio margin account.
Get borrow interest and limit¶
Manual borrow / repay¶
Set auto repay¶
Get borrow/repay history¶
Position builder (new)¶
Position builder trend graph¶
Set risk offset amount¶
Get Greeks¶
Get PM position limitation¶
Activate option¶
Set auto loan¶
Only applicable to Multi-currency margin and Portfolio margin.
Preset account mode switch¶
Precheck account mode switch¶
Set account mode¶
Set collateral assets¶
Get collateral assets¶
Reset MMP Status¶
Set MMP¶
GET MMP Config¶
Move positions¶
Get move positions history¶
Set auto earn¶
Set settle currency¶
Set trading config¶
Precheck set delta neutral¶
WebSocket¶
Account channel¶
Retrieve account information. Data pushed on events (placing/canceling/execution).
- ***URL Path**:
/ws/v5/private(requires login) - ***Channel**:
account
Subscribe Example:
Python Example:import asyncio
from okx.websocket.WsPrivateAsync import WsPrivateAsync
def callbackFunc(message):
print(message)
async def main():
ws = WsPrivateAsync(
apiKey="YOUR_API_KEY",
passphrase="YOUR_PASSPHRASE",
secretKey="YOUR_SECRET_KEY",
url="wss://ws.okx.com:8443/ws/v5/private",
useServerTime=False
)
await ws.start()
args = [{"channel": "account", "ccy": "BTC"}]
await ws.subscribe(args, callback=callbackFunc)
await asyncio.sleep(10)
await ws.unsubscribe(args, callback=callbackFunc)
asyncio.run(main())
Positions channel¶
Retrieve position information. Data pushed on events.
- ***URL Path**:
/ws/v5/private - ***Channel**:
positions
Balance and position channel¶
- ***URL Path**:
/ws/v5/private - ***Channel**:
balance_and_position
Position risk warning¶
- ***URL Path**:
/ws/v5/private - ***Channel**:
liquidation-warning
Account greeks channel¶
- ***URL Path**:
/ws/v5/private - ***Channel**:
account-greeks