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.

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

moomoo_api-10.10.7008.tar.gz (6.4 MB view details)

Uploaded Source

File details

Details for the file moomoo_api-10.10.7008.tar.gz.

File metadata

  • Download URL: moomoo_api-10.10.7008.tar.gz
  • Upload date:
  • Size: 6.4 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.2

File hashes

Hashes for moomoo_api-10.10.7008.tar.gz
Algorithm Hash digest
SHA256 2c721a9b8daeb141f77408300056a7b398ff252ac06d35bad6dd3b21489185c7
MD5 a69e56ae1001e3d1c0de4895152039d9
BLAKE2b-256 fd9041bac41995adf406840c44873589e0eb8bc715c86f096ba4efe7bd1f3f97

See more details on using hashes here.

Release history Release notifications | RSS feed

This release

10.10.7008 This release

1 file

10.9.6908

1 file

10.8.6808

1 file

10.7.6708

1 file

10.6.6608

1 file

10.5.6508

1 file

10.4.6408

1 file

10.4.4608

1 file

10.3.6308

1 file

10.2.6218

1 file

10.2.6208

1 file

10.1.6108

1 file

10.0.6008

1 file

9.6.5608

1 file

9.5.5508

1 file

9.4.5408

1 file

9.3.5308

1 file

9.2.5208

1 file

9.1.5108

1 file

9.0.5008

1 file

8.8.4808

1 file

8.7.4708

1 file

8.6.4608

1 file

8.5.4508

1 file

8.4.4408

1 file

8.2.4208

1 file

8.1.4108

1 file

8.0.4008

1 file

7.7.3908

1 file

7.6.3808

1 file

7.5.3708

1 file

7.4.3610

1 file

7.4.3608

1 file

7.3.3508

1 file

7.2.3408

1 file

5.11.2307

1 file

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