LongPort Developers Documentation

website·Indexed 34 days ago

https://open.longportapp.com/docs

Programmatic 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.

Tokens
214.8K
Snippets
1.1K
Records
1.7K
Agent score
65%

What's inside LongPort

  1. Overview of LongPort MCP

    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.
  2. 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.
  3. 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.
  4. 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.
  5. Understand the SharelistInfo schema

    The SharelistInfo object contains metadata about a specific sharelist, including its type, subscription status, and the list of stocks it contains.

    Sharelist Types (sharelist_type):

    • 0: Regular
    • 3: Official
    • 4: 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
    }
  6. Understand the OperatingItem schema

    The OperatingItem object 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
    }
  7. 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.
  8. Retrieve ETF asset allocation using the Fundamental API

    The Fundamental API allows developers to retrieve asset allocation data for ETFs. This requires initializing a FundamentalContext using an OAuth-based configuration. The etf_asset_allocation method 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)
  9. 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:
    • Python: longport.openapi.fundamental._fundamental_context
    • Node.js: fundamental#FundamentalContext
    • Go: fundamental.forecast_eps
    • Rust: longport::fundamental#_fundamental_context