Trang này chỉ dành cho mục đích thông tin. Một số dịch vụ và tính năng có thể không khả dụng ở khu vực pháp lý của bạn.

API trading on OKX — Capabilities and benefits of API v5 upgrade

An overview of API trading and OKX’s latest API interface

Typically, trading requires the use of an exchange platform for screening stocks or digital assets like Bitcoin. A trader finds an asset to trade, observes the price quote, chart and the order book, and then places a market, limit or stop order via the interface. 

This, in itself, is a major advancement over the stock trading systems of the past but is still not the most efficient process, particularly for high-frequency trading. The needs of advanced traders today are met by automated or algorithmic trading systems, which allow traders to program their strategies and set them to execute and adapt to market conditions without continuous human input.

API, or an application programming interface, is at the core of such automated trading systems and is essentially a set of programming code that allows software platforms to share data and communicate effectively in real-time.

Algo trading firms and professional traders are the main users of API trading, while retail traders can also make use of API connections for their portfolio-management apps or trading via third-party software.

In order to meet the needs of its users, OKX offers advanced API functionality and continues to upgrade it. In this article, we will provide a brief introduction to API trading on OKX as well as an overview of the new OKX API v5 upgrade.

API trading basics

There are three essential tools when it comes to API trading:

  • API keys
  • API documentation
  • Connection interfaces

API keys are unique identifiers that authenticate traders and developers who access the exchange’s API. In simple terms, API keys, consisting of a public key and a secret key, work much like a username and password combination. 

The API documentation contains technical information on how to use and integrate an API — essentially acting as a reference manual for developers and traders alike.

There are two main types of APIs — REST and WebSocket. REST stands for Representational State Transfer and is the most common web service that supports a variety of formats under HTTP — such as JSON and XML. WebSocket is a new HTML5 protocol that enables efficient data transmission between client and server. This is particularly useful for developers intending to program and connect scripts, bots or other software with an exchange.

API trading on OKX

OKX offers three categories of API trading: account, trading and market trends. In the account and trading modules, users can place orders, enquire about order status and account information. In addition, OKX users can access historical price data of trading pairs via the publicly available market data API.

OKX supports both REST and WebSocket API for its users in API v3, and traders can use the API for five trading products, including spot, margin, futures, perpetual swaps and options.

While API v3 is accessible to both retail and institutional traders, in a bid to continue improving user experience, OKX has been working on an upgrade to its API system to improve capital efficiency, error-reporting mechanisms and much more.

OKX API v5

To offer a more seamless trading experience for users, OKX has launched its new API v5, which is currently available for all Unified Account users. Being a significant upgrade from v3 (v4 was skipped because “4” is considered an unlucky number in various East Asian regions), v5 makes key improvements in the following areas:

  1. Enhanced efficiency in capital allocation
  2. Simultaneous support multiple trading products
  3. Order operation in both REST and WebSocket API
  4. A unified JSON format for error reporting
  5. More flexible WebSocket subscription and pushing in regular intervals

In this article, we compare the functionality of both API v3 and v5 and how API trading is improved in the new version. 

Functional upgrades in v5

The functionality upgrades of API v5 apply to all API users. These pertain to account fund usage, support for multiple business lines and more.

Account funds usage

In API v3, there is a corresponding account for each business line. This means that users need to transfer their funds from one trading product to another. The frequent transfer of funds is time-consuming and reduces capital efficiency for users. Moreover, the fund transfer between different trading product accounts is limited to once per second.

Traders can leverage greater capital efficiency when using API v5. Similar to OKX’s Unified Account, traders using API v5 will be able to utilize their funds in one account. In addition, the profits and losses of various positions in v5 are also consolidated according to the user’s account mode — thereby improving capital efficiency.

Unified API across products

Unlike API v3, the endpoints in API v5, such as those for placing orders and retrieving positions, are unified across products. The same request and response data models are used across all instrument types in the same API, which means we no longer need to model each of the product APIs separately.

Order operations

Order operations include placing new orders, order amendments and order cancellations. While only the REST API in v3 supports order operations, the new API v5 allows both REST and WebSocket APIs to support order operations.

Scenario-based upgrades

Scenario-based upgrades refer to upgrades in a specific function or format. This includes order mode upgrades and format upgrades of time function and REST response function.

Order placement mode

API v3 supports only opening and closing positions — and if users hold both long and short positions in the same derivative contract, these positions are viewed separately and cannot be offset against each other.

In conjunction with Unified Accounts, API v5 includes a new net mode for users. This means that various long and short positions in the same trading pair or instrument can be offset against each other, and users can view the net positions.

WebSocket subscription function

The subscription function enables users to fetch data. Compared to API v3, API v5 enables users to subscribe to multiple trading pairs simultaneously.

Moreover, API v5  pushes in regular intervals for Account and Position channels, which is more user-friendly for risk management.

Format of REST response

Response refers to the data returned to users when they attempt to retrieve information. There are two REST response formats in API v3 — normal return format and error reporting format. These two formats are incompatible in the same interface, causing inconvenience to users. On the contrary, API v5 follows a unified JSON format for REST response.

Private liquidation order

In API v3, users cannot view the status of private liquidation orders directly. They need to do so by connecting endpoints from the REST API.

The order channel of API v5 supports private liquidation orders. Users can view the status directly, and the “Category” field indicates whether the order is a partial or a full liquidation one.

Number of opened contracts

When users in API v3 want to view the number of opened contracts, they need to send requests to the WebSocket account channel to view it.

Reading the number of opened contracts is more straightforward in API v5, as users can obtain such information through the “Get maximum number of contracts” interface in the REST API.

Sub-account module

API v5 offers this module to support:

  • Management of API Keys for sub-accounts, including creation, deletion and resetting functionalities.
  • Querying account balances of sub-accounts.
  • Fund transfers between two sub-accounts directly.

Format of time

API v3 adopts the ISO8601 time format, referring to the UTC time zones. However, this time format may not be compatible across all programming languages. This requires additional functionality for time zone conversion.

API v5 adopts a more universal time format: the Unix Epoch, which does not take time zones into account. API v5 also has relevant resources in the library, allowing easy time format conversion for developers.

Market order of spot trading

When spot trading with API v5, users can choose the unit of size when placing market orders according to their needs. In contrast, API v3 users can only use the quote currency as the buying market order unit and the base currency as the selling market order unit.

The launch of API v5

As of March 31, API v5 is available to all Unified Account users. Since API v3 will be discontinued shortly after v5 has been fully rolled out, we encourage users to upgrade their API to v5 for better functionalities and a more seamless trading experience.

For more technical details regarding the new API v5, please refer to our guide here.


Follow OKX

Telegram API community: t.me/OKXAPI
Telegram: t.me/OKXOfficial_English
Twitter: twitter.com/OKX
Facebook: facebook.com/okxofficial
LinkedIn: linkedin.com/company/okxofficial
Reddit: reddit.com/r/OKX/
Instagram: instagram.com/okx_official

Tuyên bố miễn trừ trách nhiệm
Nội dung này chỉ nhằm mục đích cung cấp thông tin và có thể sẽ bao gồm các sản phẩm không được cung cấp ở khu vực của bạn. Nội dung này không nhằm mục đích cung cấp (i) lời khuyên hay đề xuất đầu tư, (ii) lời đề nghị hoặc chào mời mua, bán hoặc nắm giữ crypto/tài sản kỹ thuật số hoặc (iii) lời khuyên về tài chính, kế toán, pháp lý hoặc thuế. Tài sản kỹ thuật số/crypto, bao gồm cả stablecoin, có độ rủi ro cao và khả năng biến động mạnh. Bạn nên cân nhắc kỹ theo điều kiện tài chính của mình xem việc giao dịch hoặc nắm giữ tài sản kỹ thuật số có phù hợp hay không. Vui lòng tham khảo ý kiến của chuyên gia pháp lý/thuế/đầu tư để được giải đáp câu hỏi về tình hình cụ thể của bản thân. Thông tin (bao gồm dữ liệu thị trường và thông tin thống kê, nếu có) xuất hiện trong bài đăng này chỉ nhằm mục đích tham khảo thông tin chung. Mặc dù đã hết sức cẩn trọng trong quá trình chuẩn bị dữ liệu và biểu đồ này, chúng tôi không chịu trách nhiệm/trách nhiệm pháp lý đối với các sai sót hoặc thiếu sót được trình bày ở đây.

© 2025 OKX. Bài viết này có thể được sao chép hoặc phân phối toàn bộ, hoặc trích dẫn các đoạn không quá 100 từ, miễn là không sử dụng cho mục đích thương mại. Mọi bản sao hoặc phân phối toàn bộ bài viết phải ghi rõ: “Bài viết này thuộc bản quyền © 2025 OKX và được sử dụng có sự cho phép.” Nếu trích dẫn, vui lòng ghi tên bài viết và nguồn tham khảo, ví dụ: “Tên bài viết, [tên tác giả nếu có], © 2025 OKX.” Một số nội dung có thể được tạo ra hoặc hỗ trợ bởi công cụ trí tuệ nhân tạo (AI). Không được chỉnh sửa, chuyển thể hoặc sử dụng sai mục đích bài viết.

Bài viết liên quan

Xem thêm
Generic charts thumbnail
Strategies

The 8 best indicators for crypto trading in 2025

Cryptocurrency trading involves buying and selling digital assets like Bitcoin, Ethereum and other cryptocurrencies. Traders can use exchange platforms or brokers to take advantage of price fluctuations. Unlike traditional markets, cryptocurrency trading is decentralized and operates 24/7, allowing for global transactions anytime.
23 thg 7, 2025
Trung cấp
560
endereço de carteira blockhain
Security
Self-custody

Self-custody made simple: how to store your crypto yourself

Cryptocurrencies empower us to take charge of our assets, yet this power requires responsible choices. You have many options for managing your digital assets: trusting an exchange, opting for custodial services, or embracing self-custody. In this article, we navigate the landscape of self-custody, providing insights into practical methods for securing and managing your crypto assets independently.
23 thg 7, 2025
Người mới bắt đầu
48
Yield farming and staking
Strategies

Crypto index funds explained

If you're new to crypto trading and find the act of picking individual coins and tokens for your long-term holdings daunting, you're not alone. That's where crypto index funds come in. These funds essentially simplify the entire crypto trading process by allowing you to gain exposure to the crypto markets by tracking a specific crypto index. This, in turn, allows traders to enjoy the performance of a specific crypto market segment without the hassle of picking and managing positions individually.
23 thg 7, 2025
Trung cấp
3
Private keys
DeFi
OKC

How to bridge assets from BSC to OKC on MetaMask

A guide to bridge assets from Binance Smart Chain to OKC on MetaMask OKX users can now easily bridge their assets from Binance Smart Chain to OKC using MetaMask. This allows them to move and use suppo
23 thg 7, 2025
Crypto adoption generic thumbnail
P2P

How P2P trading opens financial doors for the unbanked in developing countries

Unlocking financial frontiers In a world accustomed to financial exclusivity, the challenges of approximately 1.7 billion adults lacking traditional bank access, as indicated by the World Bank, can often go unnoticed. This isn’t just a minor hiccup; it’s a colossal barrier to economic self-reliance.
23 thg 7, 2025
8
Introducing the Peak Sniper trading bot
Trading

Eliminating FUD with Peak Sniper: The trading bot for crypto market exits

In fighting FUD (fear, uncertainty and doubt), the Peak Sniper trading bot could be your new best friend. In this article. we'll introduce trading bots and provide an overview of Peak Sniper, its adva
23 thg 7, 2025
Xem thêm