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.2.2.tar.gz (102.5 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.2.2-cp313-cp313-win_amd64.whl (524.2 kB view details)

Uploaded CPython 3.13Windows x86-64

nautilus_futu-0.2.2-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (726.7 kB view details)

Uploaded CPython 3.13manylinux: glibc 2.17+ x86-64

nautilus_futu-0.2.2-cp313-cp313-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (708.6 kB view details)

Uploaded CPython 3.13manylinux: glibc 2.17+ ARM64

nautilus_futu-0.2.2-cp313-cp313-macosx_11_0_arm64.whl (635.3 kB view details)

Uploaded CPython 3.13macOS 11.0+ ARM64

nautilus_futu-0.2.2-cp313-cp313-macosx_10_12_x86_64.whl (651.3 kB view details)

Uploaded CPython 3.13macOS 10.12+ x86-64

nautilus_futu-0.2.2-cp312-cp312-win_amd64.whl (525.1 kB view details)

Uploaded CPython 3.12Windows x86-64

nautilus_futu-0.2.2-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (726.5 kB view details)

Uploaded CPython 3.12manylinux: glibc 2.17+ x86-64

nautilus_futu-0.2.2-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (709.4 kB view details)

Uploaded CPython 3.12manylinux: glibc 2.17+ ARM64

nautilus_futu-0.2.2-cp312-cp312-macosx_11_0_arm64.whl (635.4 kB view details)

Uploaded CPython 3.12macOS 11.0+ ARM64

nautilus_futu-0.2.2-cp312-cp312-macosx_10_12_x86_64.whl (651.8 kB view details)

Uploaded CPython 3.12macOS 10.12+ x86-64

File details

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

File metadata

  • Download URL: nautilus_futu-0.2.2.tar.gz
  • Upload date:
  • Size: 102.5 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.2.2.tar.gz
Algorithm Hash digest
SHA256 c98ed956a64fe7a7b6b28675dfe790c1913c0a95fd4727c04b3be32c20d9a827
MD5 7a671939694bdbac70bae8cf23187418
BLAKE2b-256 42b94cfa6fa1f4897ed132812c1ff484f8519e4a7022aaefc50db59d1cdb58a9

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for nautilus_futu-0.2.2-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 d7a48073475aa818bb65740ff4e027bea081a4f31d9fd3772c616ed9f120dced
MD5 75cf162906efde2b00f9c19786bf80df
BLAKE2b-256 559bf172355c1f3b96b4204b02a0e603c7380b529b233973ee59b145083b0097

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for nautilus_futu-0.2.2-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 1730142d9899790f0ab2a20e732eb12659b77b37985c3628cdd8451f48856b7d
MD5 e54ecbd786cacfc7e76283fd5bb61824
BLAKE2b-256 e0e0ea91c21b61360fcf3b0319c877dacbaefa4c7b9329faf2f7b64dba41e710

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for nautilus_futu-0.2.2-cp313-cp313-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 bbdde8497c3e608c420e7391f083ff985df730beee2f0cee3b3adff7789d1976
MD5 f53a3aaf8749e1e78d6719780b89fe27
BLAKE2b-256 f95d08c5ef3dfa1f3cbca8a85215d2f3f7a1cc329ee3527ac1236c31804fbf51

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for nautilus_futu-0.2.2-cp313-cp313-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 09d60052189b9e2a2c5d95dcaafa6a0028f8553439cb09ff238dec64cbfdba6a
MD5 a64b728917484c9bf46c1339345c0a73
BLAKE2b-256 b8107d1635f87aeea64215f42d5ecc7c235ab93c38f460e6cbbbba60359ac508

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for nautilus_futu-0.2.2-cp313-cp313-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 c016adc4af91220def6804036969e9439b2ce84dd117ccacfd70d0b04d9d3320
MD5 eb2df35a4fc23966a0877615eaecdb62
BLAKE2b-256 bc73ef556d6481eed42a9eb7ee481ac853165925870d2293f8044578184d2216

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for nautilus_futu-0.2.2-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 de91acd65924830efad065031c00211d35662c57cc70d02cb8bf28f68645334d
MD5 b2653cff0b20cdf0d0cd4f30b184d423
BLAKE2b-256 f6dd651cc90475bbfb65708f48af91571ea078f210f4720023e06d479fdf122f

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for nautilus_futu-0.2.2-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 34129fb732751d7405aca63d7f6578794a00b53a00b339ce2d2311e23413b6f5
MD5 867e82f9dbe44ab63d8b4db74d222b68
BLAKE2b-256 11ef696beaaa0eab413098ea0eabc37f4d5e8d0d13c752e9cbea72b8ab71cf29

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for nautilus_futu-0.2.2-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 df6808a0015b8fe1b21b7ac73cf17b8dd75113faeb345cb5a248187b770417c1
MD5 cca622e47189a74f0d9f4d3e8e226c5d
BLAKE2b-256 45a4554d57b5c64b55e2d9d5163c16a0da61d696acf3026401a3fdf963eaf10c

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for nautilus_futu-0.2.2-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 ca0d4e1abdbab2fc371c36458a5b990bac3b94fe309c6004b205042dc9dd63ce
MD5 9cba50a4a1e8fe3fd0f4c98c3f757e73
BLAKE2b-256 5f76470dc22f104bf07c2c90749ec7678a1545ebad27bd9eeae3db25bc97f4d3

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for nautilus_futu-0.2.2-cp312-cp312-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 7a5b902c3c22f876d2320af824575f20740cc57467ba9bd1a477ac9dc2e6ac78
MD5 9e0a2d577c581666733848a2bca9f359
BLAKE2b-256 eb1b009f0936489e46d2d2bf87d5a40c543e37331c31770ff7e5c0079b31146f

See more details on using hashes here.

Provenance

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