Skip to main content

moomoo API

Introduction

moomoo API is an open-source project for quantitative investment using moomoo API, providing market data and trading interfaces via Python and Json/Protobuf protocols.


Installation

pip install moomoo-api
Note: This API supports Python 2.7/Python 3.x.

Quick Start


# Import moomoo-api
import moomoo as ft

# Create a quote context object
quote_ctx = ft.OpenQuoteContext(host="127.0.0.1", port=11111)

# Context control
quote_ctx.start()              # Start asynchronous data reception
quote_ctx.set_handler(ft.TickerHandlerBase())  # Set callback handler for async data processing (subclass to customize)

# Low-frequency data interfaces
market = ft.Market.HK
code = 'HK.00123'
code_list = [code]
plate = 'HK.BK1107'
print(quote_ctx.get_stock_basicinfo(market, stock_type=ft.SecurityType.STOCK))   # Get stock basic info
print(quote_ctx.get_market_snapshot(code_list))                              # Get market snapshot
print(quote_ctx.get_plate_list(market, ft.Plate.ALL))                         # Get sub-plate list
print(quote_ctx.get_plate_stock(plate))                         # Get stocks under a plate

# High-frequency data interfaces
quote_ctx.subscribe(code, [ft.SubType.QUOTE, ft.SubType.TICKER, ft.SubType.K_DAY, ft.SubType.ORDER_BOOK, ft.SubType.RT_DATA, ft.SubType.BROKER])
print(quote_ctx.get_stock_quote(code))  # Get quote
print(quote_ctx.get_rt_ticker(code))   # Get ticker
print(quote_ctx.get_cur_kline(code, num=100, ktype=ft.KLType.K_DAY))   # Get current K-line
print(quote_ctx.get_order_book(code))       # Get order book
print(quote_ctx.get_rt_data(code))          # Get real-time data
print(quote_ctx.get_broker_queue(code))     # Get broker queue

# Stop asynchronous data reception
quote_ctx.stop()

# Close the context
quote_ctx.close()

# Create an HK trade context object
trade_hk_ctx = ft.OpenSecTradeContext(host="127.0.0.1", port=11111)

# Trading interfaces
print(trade_hk_ctx.unlock_trade(password='123456'))                # Unlock trading
print(trade_hk_ctx.accinfo_query(trd_env=ft.TrdEnv.SIMULATE))      # Query account info
print(trade_hk_ctx.place_order(price=1.1, qty=2000, code=code, trd_side=ft.TrdSide.BUY, order_type=ft.OrderType.NORMAL, trd_env=ft.TrdEnv.SIMULATE))  # Place order
print(trade_hk_ctx.order_list_query(trd_env=ft.TrdEnv.SIMULATE))      # Query order list
print(trade_hk_ctx.position_list_query(trd_env=ft.TrdEnv.SIMULATE))    # Query position list

trade_hk_ctx.close()


Example Strategies

  • Example strategy files are located at: (moomoo-api install directory)/py-moomoo-api/examples. You can refer to these examples to learn how to use the API.

Debug Switch and Push Logs

  • The set_futu_debug_model function can enable or disable debug-level logging.
  • When enabled, it records info-level logs along with all ticker, order book, and broker push records for troubleshooting. Log files are stored in %appdata%(%HOME%)\com.moomoonn.FutuOpenD\Log.
  • Analysis scripts for ticker, order book, and broker push records are available in moomoo/tools/analysis. Contact us to obtain raw exchange data for comparison (beta feature).

Project Structure

moomoo/
├── common/              # Core module (networking, constants, Protobuf, etc.)
│   └── pb/              # Protobuf definitions and generated files
├── quote/               # Market data module
├── trade/               # Trading module
├── tools/               # Utility tools
│   └── analysis/        # Push log analysis scripts
└── examples/            # Example code

Prerequisites

  • Before running Python scripts, you must first start the moomoo OpenD gateway client.

API and moomoo OpenD Gateway Architecture


Usage

  • Feel free to submit questions via Issues and we will respond promptly.
  • Please read the API documentation carefully when using a new version. Most questions can be answered there.
  • Suggestions and feature requests are welcome. We will do our best to meet your needs.

Metadata

Release files for moomoo-api 10.12.7208

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for moomoo-api 10.12.7208
File Size Uploaded Provenance Actions
moomoo_api-10.12.7208.tar.gz 6.4 MB Without provenance Details for moomoo_api-10.12.7208.tar.gz

Release files / moomoo_api-10.12.7208.tar.gz

Download URL moomoo_api-10.12.7208.tar.gz
Size 6.4 MB
Tags Source
SHA-256 checksum
How to use checksums
fbbb737f71e0906473bf1e85c4106b091818ddf22983886148768e32b6e97adb
BLAKE2b-256 checksum
How to use checksums
e604ef6db7b1bc7ee70ae0beca2336feef1170f6b0b7269b05cd3280872af034
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.13.2

Security for moomoo-api 10.12.7208

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

10.12.7208 This release

1 release file No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page