LongPort Developers Documentation
website·Indexed 34 days ago
https://open.longportapp.com/docsProgrammatic interfaces and OpenAPI SDKs for investors to build trading tools. Features support for Python, Node.js, Rust, and C++, along with LongPort Skill and Model Context Protocol (MCP) integration for AI assistants to access market data and trading capabilities.
What's inside LongPort
- LongPort provides a hosted HTTP MCP (Model Context Protocol) service that enables AI coding assistants and chat tools to access OpenAPI market data, account information, portfolio details, and trading capabilities. It uses OAuth for authentication, removing the need for manual API key management. The service exposes over 140 tools covering real-time market data, fundamentals, derivatives, account/portfolio management, trading, and automation.
Overview of LongPort Developers Platform
LongPort Developers provides programmatic interfaces for building trading and market analysis tools. The platform is organized into the following functional categories:
- Quote: Real-time/historical quotes, market depth, candlesticks, options/warrants, and subscriptions.
- Fundamental: Company profiles, financials, valuations, analyst ratings, and calendars.
- News & Contents: Market news, community topics, and sharelist management.
- Trade: Order creation, amendment, cancellation, and querying of executions and assets.
- Account: Portfolio analysis, price alerts, DCA plans, and watchlists.
- MCP: Model Context Protocol integration for AI assistant workflows.
Overview of LongPort Skill
LongPort Skill provides AI tools with reusable OpenAPI instructions, Model Context Protocol (MCP) connection guidance, symbol conventions, and safety checks. It is designed for AI clients that support Skill files or custom reusable instructions, enabling the AI to perform tasks such as retrieving quotes, managing portfolios, and executing trading tasks via LongPort MCP or OpenAPI.Overview of Stock Quote API endpoints
The Stock Quote API provides three primary methods for retrieving market data: Pull (request-response), Subscription (managing data streams), and Push (real-time updates).
Pull Endpoints:
- Basic security information, real-time quotes for securities, options, and warrants.
- Market depth, broker information, and broker IDs.
- Trade data, intraday data, and candlestick charts (including historical).
- Option chain expiry dates and info by date.
- Warrant issuer IDs and filtered warrants.
- Trading sessions and market trading days.
- Capital flow (intraday) and capital distribution.
- Calculated indexes for securities.
Subscription Endpoints:
- Manage quote subscriptions (Subscribe, Unsubscribe, and Get Subscription Information).
Push Endpoints:
- Real-time push updates for quotes, depth, brokers, and trades.
Retrieve top institutional and individual shareholders
The Fundamental API provides a mechanism to retrieve the top institutional and individual shareholders of a specific company.Understand the SharelistInfo schema
The
SharelistInfoobject contains metadata about a specific sharelist, including its type, subscription status, and the list of stocks it contains.Sharelist Types (
sharelist_type):0: Regular3: Official4: Industry
{ "id": 12345, // integer (Required) "name": "My Tech Stocks", // string "description": "Growth stocks", // string "cover": "http://...", // string "subscribers_count": 100, // integer "chg": "1.5%", // string (Day change %) "this_year_chg": "12.3%", // string (YTD change %) "subscribed": true, // boolean "sharelist_type": 0, // integer (0=regular, 3=official, 4=industry) "industry_code": "TECH", // string "stocks": [] // Array of SharelistStock objects }Specify security symbols in Fundamental API methods
When calling Fundamental API SDK methods, thesymbolparameter is required to identify the specific security. The symbol should be provided as a string, for example,TSLA.USfor Tesla.// Example of a symbol parameter value const symbol = 'TSLA.US';Understand the OperatingItem schema
TheOperatingItemobject represents a specific operating summary report. It includes metadata about the report period, management discussion, and links to the full report.interface OperatingItem { id: string; // Internal report ID report: string; // Report period code (e.g., 'af' for annual) title: string; // Report title txt: string; // Management discussion text latest: boolean; // Whether this is the most recent report web_url: string; // URL to the full report page financial: OperatingFinancial; // Key financial metrics }Use LongPort Fundamental API with Go
The Go SDK implementation for the Fundamental API is available under thefundamental.executivespackage.Understand LongPort Developers data authorization for HK users
LongPort provides programmatic interfaces (CLI tools, Model Context Protocol integrations, etc.) collectively known as 'LongPort Developers'. Users can integrate these with Third-Party AI Terminals (e.g., OpenClaw, Claude Code, Cursor). This authorization governs the sharing of account data with these terminals and establishes that instructions issued through these terminals are treated as the user's own instructions for securities transactions.Retrieve ETF asset allocation using the Fundamental API
The Fundamental API allows developers to retrieve asset allocation data for ETFs. This requires initializing aFundamentalContextusing an OAuth-based configuration. Theetf_asset_allocationmethod takes a ticker symbol (e.g., 'QQQ.US') as an argument.from longport.openapi import FundamentalContext, Config, OAuthBuilder # Initialize OAuth and Configuration oauth = OAuthBuilder("your-client-id").build(lambda url: print("Visit:", url)) config = Config.from_oauth(oauth) ctx = FundamentalContext(config) # Retrieve ETF asset allocation resp = ctx.etf_asset_allocation("QQQ.US") print(resp)Access Fundamental API SDKs
The LongPort Fundamental API is available across several language-specific SDKs. Use the following references to access the Fundamental Context and related functionality in your preferred language:SDK Reference Links
- Python:
longport.openapi.fundamental._fundamental_context - Node.js:
fundamental#FundamentalContext - Go:
fundamental.forecast_eps - Rust:
longport::fundamental#_fundamental_context
- Python: