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.12
  • 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

# 创建并激活虚拟环境
python -m venv .venv
# Linux / macOS
source .venv/bin/activate
# Windows
.venv\Scripts\activate

# 安装开发依赖
pip install -r requirements-dev.txt

# 开发模式构建(自动编译 Rust 并安装 Python 包)
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.4.0.tar.gz (122.1 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.4.0-cp313-cp313-win_amd64.whl (712.6 kB view details)

Uploaded CPython 3.13Windows x86-64

nautilus_futu-0.4.0-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (912.5 kB view details)

Uploaded CPython 3.13manylinux: glibc 2.17+ x86-64

nautilus_futu-0.4.0-cp313-cp313-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (887.9 kB view details)

Uploaded CPython 3.13manylinux: glibc 2.17+ ARM64

nautilus_futu-0.4.0-cp313-cp313-macosx_11_0_arm64.whl (808.0 kB view details)

Uploaded CPython 3.13macOS 11.0+ ARM64

nautilus_futu-0.4.0-cp313-cp313-macosx_10_12_x86_64.whl (832.3 kB view details)

Uploaded CPython 3.13macOS 10.12+ x86-64

nautilus_futu-0.4.0-cp312-cp312-win_amd64.whl (713.4 kB view details)

Uploaded CPython 3.12Windows x86-64

nautilus_futu-0.4.0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (912.4 kB view details)

Uploaded CPython 3.12manylinux: glibc 2.17+ x86-64

nautilus_futu-0.4.0-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (888.7 kB view details)

Uploaded CPython 3.12manylinux: glibc 2.17+ ARM64

nautilus_futu-0.4.0-cp312-cp312-macosx_11_0_arm64.whl (808.0 kB view details)

Uploaded CPython 3.12macOS 11.0+ ARM64

nautilus_futu-0.4.0-cp312-cp312-macosx_10_12_x86_64.whl (832.6 kB view details)

Uploaded CPython 3.12macOS 10.12+ x86-64

File details

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

File metadata

  • Download URL: nautilus_futu-0.4.0.tar.gz
  • Upload date:
  • Size: 122.1 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.4.0.tar.gz
Algorithm Hash digest
SHA256 f2552db2f2f432078a0779ec96f5c513f8013e824635ca4181ff6b2e93be862e
MD5 3ae628cee22be73995827d943446065d
BLAKE2b-256 1033b2eca2812b223780cd047910e03ef99cb7ed78d63b90ee56b444da2171e1

See more details on using hashes here.

Provenance

The following attestation bundles were made for nautilus_futu-0.4.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.4.0-cp313-cp313-win_amd64.whl.

File metadata

File hashes

Hashes for nautilus_futu-0.4.0-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 9f72ec37980649e701b51499f03f951bbdd9cec311b335efd9f9f901e4b3f95b
MD5 35ffeddd5ac768885afe68861341c571
BLAKE2b-256 fc93b44cb50632889a91cd516fac047d596bc5c5f2135a1c8b58d6bc795f8ea1

See more details on using hashes here.

Provenance

The following attestation bundles were made for nautilus_futu-0.4.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.4.0-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for nautilus_futu-0.4.0-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 417b2342688fed69e2d457801130df57c28291e46c7e541cd8b6e822db4f6beb
MD5 1349035a469d72a0c4fe5adc0fb66029
BLAKE2b-256 517094bd8d7344ab33cb0a38f3ccc6d898302fd249e0432ebfb599329e7b4cc0

See more details on using hashes here.

Provenance

The following attestation bundles were made for nautilus_futu-0.4.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.4.0-cp313-cp313-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for nautilus_futu-0.4.0-cp313-cp313-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 4f901a0f2cfc39618f94f94f4de6704bcd73ef65cb75bd0a7f5b18caa77caef4
MD5 36f598de7ad7b72dcc1f0eeaedb494f5
BLAKE2b-256 3d9a567715e829b88c65bbf75b4786f6636192233960815af0a5f1e9a016b32c

See more details on using hashes here.

Provenance

The following attestation bundles were made for nautilus_futu-0.4.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.4.0-cp313-cp313-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for nautilus_futu-0.4.0-cp313-cp313-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 17c97c75309ffbf4dcfd5f5671f21309bc10b2c254e724e5eef37939674b4fec
MD5 f8c0b8b59f3157c2baf37b26817a0f20
BLAKE2b-256 05d25b1c715f3584b1c731cc7900883f794531b2cc5cc783acc8f92726b0b9db

See more details on using hashes here.

Provenance

The following attestation bundles were made for nautilus_futu-0.4.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.4.0-cp313-cp313-macosx_10_12_x86_64.whl.

File metadata

File hashes

Hashes for nautilus_futu-0.4.0-cp313-cp313-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 3d5f747ea65cdb3fd9155b072bf58e261a9f6dbfe3f9fcc3dc41ca8b11c4bfe8
MD5 7a05a897d331cbc433fcfa0bc42e1127
BLAKE2b-256 9c04631fbada25dbf2e155c373a1868e12a0296ef9fc05eb0cc38441238e7a0c

See more details on using hashes here.

Provenance

The following attestation bundles were made for nautilus_futu-0.4.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.4.0-cp312-cp312-win_amd64.whl.

File metadata

File hashes

Hashes for nautilus_futu-0.4.0-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 d0c962e5f2de30db7d9a6736debd469e5f9f18438acb2b062704f96a164d0259
MD5 38f6bc022ff6af8624a3ed7dc523a6c6
BLAKE2b-256 d51ca6c8c4e68e1a0e445f5e29d50c83197b92bf50de634cd9cbd41ccea0491e

See more details on using hashes here.

Provenance

The following attestation bundles were made for nautilus_futu-0.4.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.4.0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for nautilus_futu-0.4.0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 4487e89bec12ae591caec543578babe1dc34c26116b172865cec9230044d650b
MD5 18093bb9df626882d2a275719172bae4
BLAKE2b-256 15f0701f01dcd1cdbd093237736632d67bc1b2c97338921de9f7556b9d9b5edf

See more details on using hashes here.

Provenance

The following attestation bundles were made for nautilus_futu-0.4.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.4.0-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for nautilus_futu-0.4.0-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 2332f0c4b3d6883344e8286a7d7ec8419fe5a69a7f1b79be08585800e54b6e4d
MD5 e127190af7f67b126a83c5d788d8ff00
BLAKE2b-256 74096dfdfe1d16bcb0c653339ced145da61da87fd447614b7909174aee9c4237

See more details on using hashes here.

Provenance

The following attestation bundles were made for nautilus_futu-0.4.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.4.0-cp312-cp312-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for nautilus_futu-0.4.0-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 a3cddbea3418df857cc02e2bb6a42239d4a1ae4987d2a6762f0bd417d8933ba6
MD5 99cec46055bc6059f1651cce8f3438be
BLAKE2b-256 98c3f7493a3d7fc3859fdfdc8d08d784f823102d3e68443855484402dd2b7834

See more details on using hashes here.

Provenance

The following attestation bundles were made for nautilus_futu-0.4.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.4.0-cp312-cp312-macosx_10_12_x86_64.whl.

File metadata

File hashes

Hashes for nautilus_futu-0.4.0-cp312-cp312-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 a99b7c4819d885f681c15b320f8482cda3c20d64b9b14288a4262b996e7a1834
MD5 77f1141940cf91f09b8cc01156893722
BLAKE2b-256 e0f24a97c76f4fb12bb2524df7f3e3617ce905b89e4c171e892266eaefda00ce

See more details on using hashes here.

Provenance

The following attestation bundles were made for nautilus_futu-0.4.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