Skip to main content

Futu OpenD adapter for NautilusTrader

Project description

nautilus-futu

Futu OpenD adapter for NautilusTrader — 通过富途 OpenD 网关接入港股、美股、A股等市场的量化交易适配器。

特性

  • 独立安装包 — 不依赖 NautilusTrader 主仓库,自主控制版本发布
  • Rust 协议层 — 用 Rust 实现 Futu OpenD TCP 二进制协议,高性能低延迟
  • 无 protobuf 冲突 — 不依赖 futu-api Python 包,Rust 侧用 prost 处理 protobuf,彻底避免版本冲突
  • 完整功能覆盖 — 行情订阅、历史K线、下单/改单/撤单、账户资金/持仓查询

支持市场

市场 行情 交易
港股 (HK)
美股 (US)
A股 (CN)

前置条件

  • Python >= 3.10
  • Futu OpenD 网关运行中(默认 127.0.0.1:11111
  • Rust 工具链(从源码安装时需要)

安装

pip install nautilus-futu

从源码安装:

git clone https://github.com/loadstarCN/nautilus-futu.git
cd nautilus-futu
pip install .

快速上手

import asyncio
from nautilus_futu.config import FutuDataClientConfig, FutuExecClientConfig

async def main():
    # 导入 Rust 客户端
    from nautilus_futu._rust import PyFutuClient

    client = PyFutuClient()
    client.connect("127.0.0.1", 11111, "nautilus", 100)

    # 获取行情快照
    quotes = client.get_basic_qot([(1, "00700")])  # 腾讯控股
    for q in quotes:
        print(f"{q['code']}: {q['cur_price']}")

    # 获取历史K线
    bars = client.get_history_kl(
        market=1,
        code="00700",
        rehab_type=1,      # 前复权
        kl_type=1,          # 日K
        begin_time="2025-01-01",
        end_time="2025-12-31",
    )
    print(f"获取到 {len(bars)} 根K线")

    client.disconnect()

asyncio.run(main())

集成 NautilusTrader

from nautilus_trader.live.node import TradingNode
from nautilus_futu.config import FutuDataClientConfig, FutuExecClientConfig
from nautilus_futu.factories import FutuLiveDataClientFactory, FutuLiveExecClientFactory

node = TradingNode()

# 注册 Futu 适配器
node.add_data_client_factory("FUTU", FutuLiveDataClientFactory)
node.add_exec_client_factory("FUTU", FutuLiveExecClientFactory)

# 配置
data_config = FutuDataClientConfig(
    host="127.0.0.1",
    port=11111,
)
exec_config = FutuExecClientConfig(
    host="127.0.0.1",
    port=11111,
    trd_env=0,          # 0=模拟, 1=真实
    trd_market=1,       # 1=港股, 2=美股
    unlock_pwd_md5="",  # 真实交易需要填写
)

node.build()
node.run()

项目结构

nautilus-futu/
├── crates/futu/           # Rust 核心
│   ├── proto/             # Futu OpenD .proto 文件
│   └── src/
│       ├── protocol/      # TCP 协议:包头、编解码、加解密
│       ├── client/        # 连接管理、握手、心跳、消息分发
│       ├── quote/         # 行情:订阅、快照、历史K线
│       ├── trade/         # 交易:账户、下单、查询
│       ├── generated/     # Protobuf 生成的 Rust 类型
│       └── python/        # PyO3 绑定
├── nautilus_futu/          # Python NautilusTrader 适配器
│   ├── data.py            # FutuLiveDataClient
│   ├── execution.py       # FutuLiveExecutionClient
│   ├── providers.py       # FutuInstrumentProvider
│   └── parsing/           # 数据类型转换
├── tests/
└── examples/

开发

# 安装 Rust
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh

# 开发模式构建(自动编译 Rust 并安装 Python 包)
pip install maturin
maturin develop

# 运行 Rust 测试
cargo test

# 运行 Python 测试
pytest tests/python -v

架构

Python 应用 / NautilusTrader
        │
        ▼
nautilus_futu (Python 适配器层)
        │
        ▼ PyO3
nautilus_futu._rust (Rust 编译的扩展模块)
        │
        ▼ TCP + Protobuf + AES
Futu OpenD 网关
        │
        ▼
港股 / 美股 / A股 交易所

许可证

MIT

相关链接

Project details


Download files

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

Source Distribution

nautilus_futu-0.3.0.tar.gz (118.0 kB view details)

Uploaded Source

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

nautilus_futu-0.3.0-cp313-cp313-win_amd64.whl (691.2 kB view details)

Uploaded CPython 3.13Windows x86-64

nautilus_futu-0.3.0-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (890.6 kB view details)

Uploaded CPython 3.13manylinux: glibc 2.17+ x86-64

nautilus_futu-0.3.0-cp313-cp313-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (869.1 kB view details)

Uploaded CPython 3.13manylinux: glibc 2.17+ ARM64

nautilus_futu-0.3.0-cp313-cp313-macosx_11_0_arm64.whl (788.6 kB view details)

Uploaded CPython 3.13macOS 11.0+ ARM64

nautilus_futu-0.3.0-cp313-cp313-macosx_10_12_x86_64.whl (813.1 kB view details)

Uploaded CPython 3.13macOS 10.12+ x86-64

nautilus_futu-0.3.0-cp312-cp312-win_amd64.whl (692.2 kB view details)

Uploaded CPython 3.12Windows x86-64

nautilus_futu-0.3.0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (890.5 kB view details)

Uploaded CPython 3.12manylinux: glibc 2.17+ x86-64

nautilus_futu-0.3.0-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (869.7 kB view details)

Uploaded CPython 3.12manylinux: glibc 2.17+ ARM64

nautilus_futu-0.3.0-cp312-cp312-macosx_11_0_arm64.whl (788.6 kB view details)

Uploaded CPython 3.12macOS 11.0+ ARM64

nautilus_futu-0.3.0-cp312-cp312-macosx_10_12_x86_64.whl (813.6 kB view details)

Uploaded CPython 3.12macOS 10.12+ x86-64

File details

Details for the file nautilus_futu-0.3.0.tar.gz.

File metadata

  • Download URL: nautilus_futu-0.3.0.tar.gz
  • Upload date:
  • Size: 118.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for nautilus_futu-0.3.0.tar.gz
Algorithm Hash digest
SHA256 83cec47f0e2227ca7b5af0edfd239a4bf219b0148ebb444abffb1411ef20e2dc
MD5 10d9e7925b234ca4af26f7a828710ef3
BLAKE2b-256 13ef20bef438b5f3492681a71ba36324e5bccdcacc36c86e937dded1d14caa0d

See more details on using hashes here.

Provenance

The following attestation bundles were made for nautilus_futu-0.3.0.tar.gz:

Publisher: release.yml on loadstarCN/nautilus-futu

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file nautilus_futu-0.3.0-cp313-cp313-win_amd64.whl.

File metadata

File hashes

Hashes for nautilus_futu-0.3.0-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 b2a76c4df7398309053476fcbb0c463a0cb2c45276078f5e3917949e95a1ea81
MD5 81a2efd8b8eae3184c4cbacdcf200fad
BLAKE2b-256 6dc1ba93ed393d830755a5af1db26d53eccce3013efdae4d120785faad1d0e4b

See more details on using hashes here.

Provenance

The following attestation bundles were made for nautilus_futu-0.3.0-cp313-cp313-win_amd64.whl:

Publisher: release.yml on loadstarCN/nautilus-futu

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file nautilus_futu-0.3.0-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for nautilus_futu-0.3.0-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 92a1a5d6e6540e1c50d960590c4f27091308ed75087db5b0bb5c097a969f61a6
MD5 02b3a5908b11c7859a797ebc40714238
BLAKE2b-256 d0749a933bf1b0b23e9c607e0f71a103ac1125f85678da7765595a931aef1b82

See more details on using hashes here.

Provenance

The following attestation bundles were made for nautilus_futu-0.3.0-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl:

Publisher: release.yml on loadstarCN/nautilus-futu

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file nautilus_futu-0.3.0-cp313-cp313-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for nautilus_futu-0.3.0-cp313-cp313-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 6f7a9cc1cba9800c192f5e4bf37710a4d0ad3ae01a62ae8b5d2c0c092f7db833
MD5 ebd28460153fa70fe86506a8b79285c0
BLAKE2b-256 49f3def72f7dc1626654cffc0efd5a174ae95cf13fce47f33f1ac4b54557d10d

See more details on using hashes here.

Provenance

The following attestation bundles were made for nautilus_futu-0.3.0-cp313-cp313-manylinux_2_17_aarch64.manylinux2014_aarch64.whl:

Publisher: release.yml on loadstarCN/nautilus-futu

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file nautilus_futu-0.3.0-cp313-cp313-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for nautilus_futu-0.3.0-cp313-cp313-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 ece59ba9290d97f2d5dc117bbbefe58f44408ff7eb885d89f8d88fdca49aa802
MD5 b44e27a4917f067aa0fd3d03f1564bc0
BLAKE2b-256 e0885ab420198bd88223b11a1a03b1656a8d36e5fd8a08915bee1afb169d0a72

See more details on using hashes here.

Provenance

The following attestation bundles were made for nautilus_futu-0.3.0-cp313-cp313-macosx_11_0_arm64.whl:

Publisher: release.yml on loadstarCN/nautilus-futu

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file nautilus_futu-0.3.0-cp313-cp313-macosx_10_12_x86_64.whl.

File metadata

File hashes

Hashes for nautilus_futu-0.3.0-cp313-cp313-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 dc8e28bc25f4f8a0078627feeb80eeb0a01df352daaedb45eafa73abae6d89a9
MD5 e4899a6d7a12a8e6d88b7cfddfbf616c
BLAKE2b-256 4b41e13d06e3590fa50fcbac1f8f1c4f2e3b1ce3cfd90a2d80e0f4056b058175

See more details on using hashes here.

Provenance

The following attestation bundles were made for nautilus_futu-0.3.0-cp313-cp313-macosx_10_12_x86_64.whl:

Publisher: release.yml on loadstarCN/nautilus-futu

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file nautilus_futu-0.3.0-cp312-cp312-win_amd64.whl.

File metadata

File hashes

Hashes for nautilus_futu-0.3.0-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 282b635e125bea42999ae4751199f4df000be6a6d39fc3af79b9ade50abe88e7
MD5 712f93cf0153dd80a6d6f581ead7ef0b
BLAKE2b-256 3776c7e9ab6aaa16cdb2407a66584ed1d86e46af9cab4988f4707c5cd68b6ada

See more details on using hashes here.

Provenance

The following attestation bundles were made for nautilus_futu-0.3.0-cp312-cp312-win_amd64.whl:

Publisher: release.yml on loadstarCN/nautilus-futu

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file nautilus_futu-0.3.0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for nautilus_futu-0.3.0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 c96676b01496a977e7e454896cc453cc4ca33554e240dbe54d020e144deab2d6
MD5 fadbf5507ad42fe164873e0044c02f03
BLAKE2b-256 df62056bbc7f71a675f08c5f95f94bf316c6c37f6d7c5b04d057533ab3711e9b

See more details on using hashes here.

Provenance

The following attestation bundles were made for nautilus_futu-0.3.0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl:

Publisher: release.yml on loadstarCN/nautilus-futu

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file nautilus_futu-0.3.0-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for nautilus_futu-0.3.0-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 8624343b51ba633a5b9b44df63f45cd0ad79dcaec2ebd989b0524a946733acee
MD5 9578a6a749bef86e530cbadc4ba46656
BLAKE2b-256 afc9f4a35ef724f8748e2666ba09163ce9ddf03daea64b5313756d1a54c12ef3

See more details on using hashes here.

Provenance

The following attestation bundles were made for nautilus_futu-0.3.0-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl:

Publisher: release.yml on loadstarCN/nautilus-futu

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file nautilus_futu-0.3.0-cp312-cp312-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for nautilus_futu-0.3.0-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 64663e4fcd4f6bd0fdbf4e674fe307f89865c7e27661b861202e2abbd4d8b0cb
MD5 58a39f5787f49ef14c36e1ec8b96c210
BLAKE2b-256 51cf9c48fa07feffb3214a9886293b2d074462f0ab6914215a321a07f8467f09

See more details on using hashes here.

Provenance

The following attestation bundles were made for nautilus_futu-0.3.0-cp312-cp312-macosx_11_0_arm64.whl:

Publisher: release.yml on loadstarCN/nautilus-futu

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file nautilus_futu-0.3.0-cp312-cp312-macosx_10_12_x86_64.whl.

File metadata

File hashes

Hashes for nautilus_futu-0.3.0-cp312-cp312-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 ea9a49a19d359f366c683ec77451bec1f10067fb1e1b100bc8270b0c4065e938
MD5 db8916cbce652bcd28cdaed91fb0d13f
BLAKE2b-256 51fdebbc10aee08c3bee220140e8d79f7fad4d20c105b862991f4d48bf6820d4

See more details on using hashes here.

Provenance

The following attestation bundles were made for nautilus_futu-0.3.0-cp312-cp312-macosx_10_12_x86_64.whl:

Publisher: release.yml on loadstarCN/nautilus-futu

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page