QuantConnect / QuantConnect/Lean

Feature Request: Add Moomoo as a Supported Brokerage

Open
#9,625 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
C#
Stars
21.7k
Forks
5.3k
Avg merge
2d 22h
Merged PRs (30d)
34

Description

Expected Behavior

LEAN should support Moomoo as a native brokerage integration, allowing users to:

  • Connect to Moomoo accounts (including paper trading and live accounts)
  • Place, modify, and cancel orders for US equities, ETFs, options, HK stocks, and SG stocks
  • Retrieve real-time account information, positions, and order status via WebSocket streaming
  • Access market data through Moomoo's OpenAPI (where licensed and available)
  • Utilize Moomoo's competitive zero-commission fee structure for US stocks/ETFs
  • Leverage Moomoo's OpenD local gateway infrastructure for reliable low-latency connectivity
  • Support pre-market and after-hours trading where available

The integration should include:

  1. MoomooBrokerageModel - Order type and security type validation
  2. MoomooFeeModel - Fee structure based on Moomoo's published commissions
  3. BrokerageName.Moomoo enum value

Actual Behavior

Currently, LEAN does not support Moomoo as a brokerage. Users who wish to trade with Moomoo through algorithmic strategies must:

  • Build custom integrations outside the LEAN ecosystem
  • Use third-party middleware solutions (e.g., MCP servers) that are not officially supported
  • Write their own order management and market data handling logic from scratch

This creates significant barriers for Moomoo users who want to leverage LEAN's robust backtesting and live trading capabilities.


Potential Solution

Implement a complete Moomoo brokerage integration for LEAN with the following architecture:

1. LEAN Core Changes (Models Layer) - PR to Lean:

Lean/
├── Common/
│   └── BrokerageName.Moomoo enum
├── Algorithm.Framework/
│   └── MoomooBrokerageModel (order/security type validation)
└── Algorithm/
    └── MoomooFeeModel (fee calculation)

2. Brokerage Implementation - Separate Repository:

QC-Moomoo-Brokerage/
├── MoomooBrokerage.cs                    # Main brokerage implementation
├── MoomooRestApiClient.cs               # REST API for orders/account/positions
├── MoomooWebSocketClient.cs             # WebSocket for real-time updates
├── MoomooAuthentication.cs              # Token-based auth with auto-refresh
├── MoomooSymbolMapper.cs                # Symbol mapping (US/HK/SG/A-shares)
├── MoomooOrderConverter.cs              # Order type conversion
├── MoomooFeeModel.cs                    # Fee calculation logic
├── MoomooBrokerageModel.cs              # Order type/security validation
└── Tests/
    ├── MoomooBrokerageTests.cs          # 80+ unit tests
    ├── MoomooFeeModelTests.cs           # 20+ fee calculation tests
    └── IntegrationTests/                # Live paper trading tests

3. Supported Features:

Feature Supported
Market Orders
Limit Orders
Stop Orders
Stop-Limit Orders
Order Modifications
Order Cancellation
Partial Fill Handling
WebSocket Reconnection (Exponential Backoff)
Multiple Sub-Accounts
Paper & Live Environments
US Equities/ETFs
US Options
HK Stocks
SG Stocks
Futures ✅ (region-dependent)
Historical Data ✅ (if licensed)
Streaming Market Data ✅ (if licensed)

4. Fee Structure (Based on Moomoo Published Commissions):

Asset Class Commission
US Stocks/ETFs $0.00 commission + regulatory fees (~$0.01-$0.03/share)
US Options $0.65 per contract
HK Stocks 0.03% of trade value (min HK$15) + platform fee HK$15
SG Stocks 0.03% of trade value (min S$10) + platform fee S$1
A-Share Connect 0.03% of trade value (min RMB 5)

5. Authentication Flow:

  • Support for both production and paper trading environments
  • Connection to local OpenD gateway with encrypted communication

6. Implementation Details:

  • Use Moomoo's official Python/OpenAPI as reference for protocol specifications
  • The OpenD gateway architecture (local daemon) is similar to Interactive Brokers' TWS/IB Gateway, making it suitable for LEAN integration
  • WebSocket client with automatic reconnection and exponential backoff
  • Comprehensive error handling and logging

Why This Matters

Moomoo's growing market presence:

  • Over 20 million users globally
  • Strong presence in US, Canada, Australia, Japan, Hong Kong, Singapore, and Malaysia
  • Recently launched "API Skills" facility for AI-powered trading in Australia and New Zealand

Community demand:

  • Many QuantConnect users in Asia-Pacific regions are actively requesting Moomoo support
  • Moomoo's zero-commission US stock trading makes it attractive for retail algorithmic traders
  • Existing third-party integration efforts (e.g., Moomoo MCP servers) demonstrate community interest

Technical feasibility:

  • Moomoo provides comprehensive OpenAPI documentation
  • Official Python SDK available (moomoo-api on PyPI)
  • Similar architecture to existing brokerages (Interactive Brokers, Tradovate)
  • OpenD gateway architecture is well-suited for LEAN's brokerage model

Additional Resources

Checklist

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the proposed Lean paths for BrokerageName.Moomoo, MoomooBrokerageModel, and MoomooFeeModel, then review the separate QC-Moomoo-Brokerage file layout and Moomoo OpenAPI documentation. The intended work includes brokerage, authentication, symbol, order, and WebSocket components plus the listed unit and integration tests. Done means the requested environments, instruments, order flows, and fee behavior are covered.

Written by the indexing model from the issue text.

Assessment

Tech stack
csharp, python
Domain
backend-api-design, fintech-quant
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.