# LongPort OpenAPI Documentation LongPort OpenAPI provides programmatic quote trading interfaces for investors with research and development capabilities and assists them to build trading or quote strategy analysis tools based on their own investment strategies. The functions fall into the following categories: - **Trading** - Create, amend, cancel orders, query today's/past orders and transaction details, etc. - **Quotes** - Real-time quotes, acquisition of historical quotes, etc. - **Portfolio** - Real-time query of the account assets, positions, funds - **Real-time subscription** - Provides real-time quotes and push notifications for order status changes ## Interface Type LongPort provides diversified access methods such as HTTP / WebSockets interfaces for accessing the underlying services and SDK (Python / C++, etc.) encapsulated in the upper layer, allowing flexible choices. ## How to Enable OpenAPI 1. Log in to the [LongPort App](https://longportapp.com/download) to complete the account opening process; 2. Log in to the [longportapp.com](https://longportapp.com) and enter the developer platform, complete the developer verification (OpenAPI permission application), and obtain a token. ## Quote Coverage
Market Symbol
HK Market Securities (including equities, ETFs, Warrants, CBBCs)
Hang Seng Index
US Market Securities (including stocks, ETFs)
Nasdsaq Index
OPRA Options
CN Market Securities (including stocks, ETFs)
Index
## Trading Supported trading functions include: | Market | Stock and ETF | Warrant & CBBC | Options | | --------- | ------------- | -------------- | ------- | | HK Market | ✓ | ✓ | | | US Market | ✓ | ✓ | ✓ | ## Rate Limit {#rate-limit} | Category | Limitation | | --------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | Quote API | | | Trade API | | :::success The [OpenAPI SDK](https://open.longportapp.com/sdk) has done effective frequency control internally: - Quote: The methods under `QuoteContext` will be actively controlled by the SDK according to the server's rate limit. When the request is too fast, the SDK will automatically delay the request. Therefore, you do not need to implement the frequency control details separately. - Trade: The methods under `TradeContext` are not limited by the SDK. Due to the special nature of the trading order placement scenario, this is left to the user to handle. ::: ## Pricing {#pricing} LongPort does not charge any additional fees for activating or using interface services. You only need to open a LongPort Integrated A/C and get OpenAPI service permissions to use it for free. For actual transaction fees, please contact the brokerage firm where you have opened your securities account. ## Other The OpenAPI services are provided by LongPort and the applicable affiliates (subject to the agreement). openapi-trade.longportapp.com ## SDK - [Introduction](https://open.longportapp.com/docs.md) ## Docs - [Error Codes](https://open.longportapp.com/docs/error-codes.md) - [Get Socket OTP (One time password)](https://open.longportapp.com/docs/socket-token-api.md) - [llm](https://open.longportapp.com/docs/llm.md) - [Getting Started](https://open.longportapp.com/docs/getting-started.md) - [Overview](https://open.longportapp.com/docs/how-to-access-api.md) - [Refresh Token](https://open.longportapp.com/docs/refresh-token-api.md) ## Socket - [Data Commands](https://open.longportapp.com/docs/socket/biz-command.md) - [Subscribe Real-Time Trading Data](https://open.longportapp.com/docs/socket/subscribe_trade.md) - [Endpoints](https://open.longportapp.com/docs/socket/hosts.md) - [Subscribe Real-Time Market Data](https://open.longportapp.com/docs/socket/subscribe_quote.md) - [Control commands](https://open.longportapp.com/docs/socket/control-command.md) - [Access differences between WebSocket and TCP](https://open.longportapp.com/docs/socket/diff_ws_tcp.md) ## Protocol - [Protocol Overview](https://open.longportapp.com/docs/socket/protocol/overview.md) - [Communication Model](https://open.longportapp.com/docs/socket/protocol/connect.md) - [Parse Request Packet](https://open.longportapp.com/docs/socket/protocol/request.md) - [Parse Handshake](https://open.longportapp.com/docs/socket/protocol/handshake.md) - [Parse Push Packet](https://open.longportapp.com/docs/socket/protocol/push.md) - [Parse Response Packet](https://open.longportapp.com/docs/socket/protocol/response.md) - [Parse Header of Packet](https://open.longportapp.com/docs/socket/protocol/header.md) ## Trade - [Trade Push](https://open.longportapp.com/docs/trade/trade-push.md) - [Overview](https://open.longportapp.com/docs/trade/trade-overview.md) - [Definition](https://open.longportapp.com/docs/trade/trade-definition.md) ## Asset - [Get Cash Flow](https://open.longportapp.com/docs/trade/asset/cashflow.md) - [Get Fund Positions](https://open.longportapp.com/docs/trade/asset/fund.md) - [Get Margin Ratio](https://open.longportapp.com/docs/trade/asset/margin_ratio.md) - [Get Stock Positions](https://open.longportapp.com/docs/trade/asset/stock.md) - [Get Account Balance](https://open.longportapp.com/docs/trade/asset/account.md) ## Order - [Get Today Order](https://open.longportapp.com/docs/trade/order/today_orders.md) - [Replace Order](https://open.longportapp.com/docs/trade/order/replace.md) - [Estimate Maximum Purchase Quantity](https://open.longportapp.com/docs/trade/order/estimate_available_buy_limit.md) - [Order Details](https://open.longportapp.com/docs/trade/order/order_detail.md) - [Withdraw Order](https://open.longportapp.com/docs/trade/order/withdraw.md) - [Get History Order](https://open.longportapp.com/docs/trade/order/history_orders.md) - [Submit Order](https://open.longportapp.com/docs/trade/order/submit.md) ## Execution - [Get History Executions](https://open.longportapp.com/docs/trade/execution/history_executions.md) - [Get Today Executions](https://open.longportapp.com/docs/trade/execution/today_executions.md) ## Qa - [Quote Releated](https://open.longportapp.com/docs/qa/broker.md) - [General](https://open.longportapp.com/docs/qa/general.md) - [Trade](https://open.longportapp.com/docs/qa/trade.md) ## Quote - [Overview](https://open.longportapp.com/docs/quote/overview.md) - [Definition](https://open.longportapp.com/docs/quote/objects.md) ## Push - [Push Real-time Brokers](https://open.longportapp.com/docs/quote/push/broker.md) - [Push Real-time Depth](https://open.longportapp.com/docs/quote/push/depth.md) - [Push Real-time Quote](https://open.longportapp.com/docs/quote/push/quote.md) - [Push Real-time Trades](https://open.longportapp.com/docs/quote/push/trade.md) ## Pull - [Security Capital Distribution](https://open.longportapp.com/docs/quote/pull/capital-distribution.md) - [Security Candlesticks](https://open.longportapp.com/docs/quote/pull/candlestick.md) - [Basic Information of Securities](https://open.longportapp.com/docs/quote/pull/static.md) - [Current Market Temperature](https://open.longportapp.com/docs/quote/pull/market_temperature.md) - [Warrant Issuer IDs](https://open.longportapp.com/docs/quote/pull/issuer.md) - [Option Chain By Date](https://open.longportapp.com/docs/quote/pull/optionchain-date-strike.md) - [Security Capital Flow Intraday](https://open.longportapp.com/docs/quote/pull/capital-flow-intraday.md) - [Real-time Quotes of Warrant](https://open.longportapp.com/docs/quote/pull/warrant-quote.md) - [Option Chain Expiry Date List](https://open.longportapp.com/docs/quote/pull/optionchain-date.md) - [Broker IDs](https://open.longportapp.com/docs/quote/pull/broker-ids.md) - [Security Brokers](https://open.longportapp.com/docs/quote/pull/brokers.md) - [Calculate Indexes Of Securities](https://open.longportapp.com/docs/quote/pull/calc-index.md) - [Warrant Filter](https://open.longportapp.com/docs/quote/pull/warrant-filter.md) - [Historical Market Temperature](https://open.longportapp.com/docs/quote/pull/history_market_temperature.md) - [Security History Candlesticks](https://open.longportapp.com/docs/quote/pull/history-candlestick.md) - [Security Depth](https://open.longportapp.com/docs/quote/pull/depth.md) - [Real-time Quotes Of Securities](https://open.longportapp.com/docs/quote/pull/quote.md) - [Market Trading Days](https://open.longportapp.com/docs/quote/pull/trade-day.md) - [Real-time Quotes of Option](https://open.longportapp.com/docs/quote/pull/option-quote.md) - [Security Intraday](https://open.longportapp.com/docs/quote/pull/intraday.md) - [Security Trades](https://open.longportapp.com/docs/quote/pull/trade.md) - [Trading Session of The Day](https://open.longportapp.com/docs/quote/pull/trade-session.md) ## Individual - [Watchlist Group](https://open.longportapp.com/docs/quote/individual/watchlist_groups.md) - [Delete Watchlist Group](https://open.longportapp.com/docs/quote/individual/watchlist_delete_group.md) - [Update Watchlist Group](https://open.longportapp.com/docs/quote/individual/watchlist_update_group.md) - [Create Watchlist Group](https://open.longportapp.com/docs/quote/individual/watchlist_create_group.md) ## Security - [Retrieve the List of Securities](https://open.longportapp.com/docs/quote/security/security_list.md) ## Subscribe - [Subscription Information](https://open.longportapp.com/docs/quote/subscribe/subscription.md) - [Subscribe Quote](https://open.longportapp.com/docs/quote/subscribe/subscribe.md) - [Unsubscribe Quote](https://open.longportapp.com/docs/quote/subscribe/unsubscribe.md)