개발자 포털
Theme

Exchange OS Open API Conventions#

Welcome to the Exchange OS Open API.

This API aggregates perp and spot markets and provides external developers with unified REST, WebSocket, and trading-signature interfaces. Business lines are not distinguished by URL paths; they are routed through request parameters or assetId:

  • Write endpoints specify the market type through marketType.
  • Account and trading read endpoints usually derive the market type from assetId.
  • Market-instrument query endpoints can be filtered using marketType.

Base Path#

text
/api/v5/exchangeos/

Full URL:

text
https://{host}/api/v5/exchangeos/{endpoint}

Examples:

http
POST /api/v5/exchangeos/trade/place-order
GET /api/v5/exchangeos/market/instruments

Environment#

EnvironmentBase URL
Productionhttps://www.okx.com

Identifier Conventions#

IdentifierDescription
assetIdComposite asset ID of type String. Its encoding includes the market type: assetId % 100 == 1 indicates Spot, and assetId % 100 == 2 indicates perp. Account and trading read endpoints routed by assetId do not require a separate marketType.
tokenIdToken ID of type String. The collateral token USDS has tokenId of "0". Account endpoints consistently use tokenId to identify tokens.
oidOn-chain order ID as a decimal String. Regular orders are usually assigned by the matching engine. System orders, such as liquidation, ADL, or settlement orders, may use virtual oid values.
clientOrderIdUser-defined order ID in the format 0x{region}{env}{30hex}, for a total of 34 characters. Required for regular order placement. Trigger and TPSL orders must not include it. It can be used for cancellation, modification, and asynchronous result matching.

Units#

Order sizes for both perp and spot are denominated in Base Token units. Contract lots are not used.

Response Format#

All REST endpoints use the following response envelope:

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

Write Endpoint Authentication#

All write endpoints must include the following request headers:

HeaderDescription
OK-ACCESS-KEYAPI Key.
OK-ACCESS-SIGNRequest signature: Base64(HMAC-SHA256(timestamp + method + requestPath + body, SecretKey)).
OK-ACCESS-TIMESTAMPUTC timestamp.
OK-ACCESS-PASSPHRASEPassphrase set when creating the API Key.

Write Operation Signing Model#

All write operations, including order placement, cancellation, modification, leverage adjustment, margin adjustment, position-mode switching, and account transfers, use EIP-712 Action signatures.

Request body structure:

json
{
  "action": {},
  "nonce": 1704067200000,
  "user": "0x...",
  "vaultAddress": "0x...",
  "signature": {
    "Ecdsa": {
      "r": "0x...",
      "s": "0x...",
      "v": 1
    }
  },
  "expiresAfter": 1704067260000
}
FieldTypeRequiredDescription
actionObjectYesBusiness action object and the EIP-712 signing object. All business parameters are contained in action.
nonceLongYesCurrent timestamp in milliseconds, used for signing and replay protection.
userStringNoBusiness-account address. When not explicitly provided, it is resolved according to the signing principal or endpoint rules.
vaultAddressStringNoSub-account address. Omit when operating on the master account; provide the sub-account address when operating on a sub-account.
signatureObjectYesECDSA signature of the complete action by the Agent. r and s are hexadecimal strings, and v is 0 or 1.
expiresAfterLongNoAction expiration time. Requests are rejected after this time. Required for cancel-all-after heartbeat requests.

Signing flow:

  1. Construct the complete canonical action.
  2. Generate nonce using the current timestamp in milliseconds.
  3. Sign action with EIP-712 using the ECDSA private key of an authorized Agent.
  4. Submit the signed request to the relevant endpoint with the OK-ACCESS-* headers.

The server does not construct or modify action on behalf of clients. Any field change after signing causes signature validation to fail.

Sub-account Queries#

The following read endpoints support the optional vaultAddress parameter:

  • Omit vaultAddress: Query master-account data.
  • Provide vaultAddress: Query the specified sub-account data.

The gateway verifies that the address belongs to the authenticated user.

Applicable endpoints:

text
/account/balance
/account/positions
/account/max-size
/account/leverage-info
/account/position-tiers
/account/bills
/trade/order
/trade/orders-pending
/trade/orders-history
/trade/fills

The following endpoints always operate at the master-account level and do not support vaultAddress:

text
/account/detail
/account/trade-fee

Rate Limit Overview#

Trade Endpoints

Rate-limit scope: per user.

EndpointRate Limit
POST /trade/noop50 RPS
POST /trade/place-order50 RPS
POST /trade/cancel-order50 RPS
POST /trade/modify-order50 RPS
POST /trade/cancel-all-after1 RPS
GET /trade/transaction30 RPS
GET /trade/order30 RPS
GET /trade/orders-pending30 RPS
GET /trade/orders-history20 RPS
GET /trade/fills30 RPS

Account Endpoints

Rate-limit scope: per user.

EndpointRate Limit
POST /account/account-transfer10 RPS
GET /account/balance10 RPS
GET /account/positions10 RPS
GET /account/max-size10 RPS
GET /account/position-tiers5 RPS
POST /account/set-leverage10 RPS
POST /account/set-margin-mode10 RPS
POST /account/adjust-isolated-margin10 RPS
POST /account/set-position-mode5 RPS
GET /account/leverage-info5 RPS
GET /account/trade-fee3 RPS
GET /account/bills5 RPS
GET /account/detail3 RPS
POST /account/create-sub-account3 RPS
GET /account/limits10 RPS

Market Endpoints

Rate-limit scope: per IP.

EndpointRate Limit
GET /market/instruments10 RPS
GET /market/tickers10 RPS
GET /market/order-book10 RPS
GET /market/candles20 RPS
GET /market/mark-prices10 RPS
GET /market/position-tiers10 RPS
GET /market/funding-rate-history5 RPS
GET /market/funding-rate10 RPS
GET /market/open-interest10 RPS
GET /market/price-limit10 RPS
GET /market/index-tickers10 RPS
GET /market/token-info10 RPS
GET /market/security-fund5 RPS