longportapp/openapi logo

longportapp/openapi

Free

LongPort OpenAPI 提供实时股市数据,通过 MCP 为 AI 提供分析和交易能力。

FreeFree tier
Type
Open Source

About longportapp/openapi

LongPort OpenAPI SDK provides programmatic access to real-time stock quotes and trading capabilities for investors. It supports multiple programming languages (Rust, Python, Node.js, Java, C, C++, Go) and includes an MCP server for AI integration. Features include order management (create, amend, cancel, query), real-time and historical quotes, portfolio tracking (assets, positions, funds), real-time subscription push notifications, and various context types for financial data (quotes, trades, fundamentals, calendar, alerts, etc.). The SDK is open source and free, with detailed documentation and troubleshooting guides.

Key Features

Trading: create, amend, cancel orders; query today's and past orders, transaction details
Quotes: real-time and historical quote data acquisition
Portfolio: real-time query of account assets, positions, and funds
Real-time subscription: push notifications for quotes and order status changes
MCP server with multiple context types (QuoteContext, TradeContext, AssetContext, ContentContext, FundamentalContext, MarketContext, CalendarContext, PortfolioContext, AlertContext, DCAContext, SharelistContext)
Multi-language SDK support: Rust, Python, Node.js, Java, C, C++, Go

Pros & Cons

Pros
  • Open source and free to use
  • Comprehensive multi-language SDK support (7+ languages)
  • Real-time data and trading capabilities with subscription push
  • MCP server enables seamless AI agent integration
  • Well-documented with troubleshooting guides and examples
Cons
  • Requires a LongPort account and valid API credentials (app key, secret, access token)
  • Limited to markets supported by LongPort brokerage
  • Authentication and networking setup may require careful configuration (environment variables, permissions, firewall)

Best For

Building algorithmic trading strategies with programmatic order managementReal-time market data monitoring and analysis for informed decisionsPortfolio management and tracking across multiple assetsDeveloping AI agents or chatbots that interact with financial markets via MCPAutomated trading systems with push notifications for order status changes

FAQ

Why are environment variables not taking effect?
On macOS/Linux, export only affects the current shell session. On Windows, setx requires opening a new terminal/session to take effect.
How to fix authentication errors (401/403)?
Verify that LONGPORT_APP_KEY, LONGPORT_APP_SECRET, and LONGPORT_ACCESS_TOKEN are correct and not expired. Ensure your OpenAPI app has the required permissions.
What to do about network/connection errors?
Check firewall/proxy rules for HTTPS/WSS. If using a custom endpoint, set LONGPORT_HTTP_URL, LONGPORT_QUOTE_WS_URL, and LONGPORT_TRADE_WS_URL.
Why does quote subscription exit immediately?
Keep the process running (event loop, sleep, or blocking receive loop) to receive push events; otherwise you will not see them.