Moomoo OpenD data provider for HKSE/KLSE markets with capital flow analysis
Project description
moomoo-data
Moomoo OpenD data provider for HKSE/KLSE markets with capital flow analysis
A comprehensive Python library for accessing Moomoo OpenD API data, featuring:
-
📈 Real-time quotes for HKSE and KLSE stocks
-
📊 K-line data (daily, weekly, monthly, intraday)
-
💰 Capital flow analysis (super/big/mid/small order tracking)
-
🎯 Chip distribution analysis (triangular distribution model)
-
💾 Built-in caching (memory + SQLite)
-
⚡ Rate limiting with configurable limits
Installation
pip install moomoo-data
Optional dependencies
# Full installation with all features
pip install moomoo-data[all]
# SQLite caching (recommended for production)
pip install moomoo-data[cache]
Requirements
- Python 3.10+
- Moomoo OpenD gateway running locally (default:
127.0.0.1:11111) moomoo-apipackage (pip install moomoo-api)
Quick Start
from moomoo_data import get_stock_quote, get_daily_kline, get_capital_flow
# Get real-time quote
quote = get_stock_quote("0700.HK")
print(f"Price: {quote['最新价']}, Change: {quote['涨跌幅']}%")
# Get daily K-line
kline = get_daily_kline("0700.HK", count=100)
print(f"Retrieved {len(kline)} days of data")
# Get capital flow
flow = get_capital_flow("0700.HK")
print(f"Net inflow: {flow['net_inflow']}")
Configuration
Configure via environment variables or .env file:
# Moomoo OpenD connection
MOOMOO_HOST=127.0.0.1
MOOMOO_PORT=11111
MOOMOO_ENABLED=true
# Cache settings
MOOMOO_CACHE_PATH=~/.cache/moomoo-data/cache.db
MOOMOO_CACHE_ENABLED=true
# Rate limits (requests per 30 seconds)
MOOMOO_RATE_LIMIT_QUOTE=30
MOOMOO_RATE_LIMIT_KLINE=20
API Reference
Core Functions
| Function | Description | Returns |
|---|---|---|
get_stock_quote(ticker) |
Real-time stock quote | Dict with OHLCV + changes |
get_daily_kline(ticker, count) |
Daily K-line data | pandas DataFrame |
get_history_kline(ticker, start, end) |
Historical K-line | pandas DataFrame |
get_capital_flow(ticker) |
Capital flow by order size | Dict with inflow/outflow |
get_capital_distribution(ticker) |
Current capital distribution | Dict with super/big/mid/small |
analyze_chip_distribution(ticker) |
Chip distribution analysis | Dict with avg_cost, concentration |
Ticker Formats
Supported formats:
- FinGenius:
0700.HK,7088.KL - Moomoo:
HK.00700,MY.07088
The library automatically converts between formats.
Markets Supported
| Market | Ticker Suffix | Example |
|---|---|---|
| HKSE | .HK |
0700.HK (Tencent) |
| KLSE | .KL |
7088.KL (Yinson) |
| A-Share | 6-digit code | 600519 (Kweichow Moutai) |
Chip Analysis
The library includes a professional-grade chip distribution analyzer using:
- Triangular distribution: Spreads turnover across price range
- L-Curve decay: Models psychological selling behavior
- Dynamic bin sizing: Market-aware granularity
- NumPy vectorization: 100x faster than loops
from moomoo_data import analyze_chip_distribution
result = analyze_chip_distribution("0700.HK")
print(f"Average cost: {result['avg_cost']}")
print(f"Concentration (90%): {result['concentration_90']}%")
print(f"Profit ratio: {result['profit_ratio']}%")
Examples
See the examples/ directory for:
01_basic_quote.py- Real-time quotes02_kline_analysis.py- K-line data retrieval03_capital_flow.py- Capital flow analysis04_chip_distribution.py- Chip distribution visualization
Documentation
Full API documentation: GitHub
License
MIT License - see LICENSE file for details.
Contributing
Contributions welcome! Please:
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
Changelog
See CHANGELOG.md for version history.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file moomoo_data-0.2.0.tar.gz.
File metadata
- Download URL: moomoo_data-0.2.0.tar.gz
- Upload date:
- Size: 22.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.14.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
11e8836e79cc9139d20b189b2682fa182db256e566a19ff8dfae162814f2eb7f
|
|
| MD5 |
113f92c8a2983d305aa7599c8730c3b9
|
|
| BLAKE2b-256 |
77e85725c4b95380698d6964643e51a7b1e2c4e00f053748e06bb0c57d71046f
|
File details
Details for the file moomoo_data-0.2.0-py3-none-any.whl.
File metadata
- Download URL: moomoo_data-0.2.0-py3-none-any.whl
- Upload date:
- Size: 25.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.14.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
3094899a33f46542d3bb780a8d62facb2274bef50bc8201a0ceab2785ebe6188
|
|
| MD5 |
f348312cf11d5a8332ed145c23fb2851
|
|
| BLAKE2b-256 |
02867a16f62925ce5a06ccd80a044a4c2f2356d756f84596927fc07dc4a034f8
|