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.3.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.3-cp313-cp313-win_amd64.whl (523.3 kB view details)

Uploaded CPython 3.13Windows x86-64

nautilus_futu-0.2.3-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (726.8 kB view details)

Uploaded CPython 3.13manylinux: glibc 2.17+ x86-64

nautilus_futu-0.2.3-cp313-cp313-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (710.3 kB view details)

Uploaded CPython 3.13manylinux: glibc 2.17+ ARM64

nautilus_futu-0.2.3-cp313-cp313-macosx_11_0_arm64.whl (635.6 kB view details)

Uploaded CPython 3.13macOS 11.0+ ARM64

nautilus_futu-0.2.3-cp313-cp313-macosx_10_12_x86_64.whl (650.2 kB view details)

Uploaded CPython 3.13macOS 10.12+ x86-64

nautilus_futu-0.2.3-cp312-cp312-win_amd64.whl (524.1 kB view details)

Uploaded CPython 3.12Windows x86-64

nautilus_futu-0.2.3-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (726.6 kB view details)

Uploaded CPython 3.12manylinux: glibc 2.17+ x86-64

nautilus_futu-0.2.3-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (711.0 kB view details)

Uploaded CPython 3.12manylinux: glibc 2.17+ ARM64

nautilus_futu-0.2.3-cp312-cp312-macosx_11_0_arm64.whl (635.7 kB view details)

Uploaded CPython 3.12macOS 11.0+ ARM64

nautilus_futu-0.2.3-cp312-cp312-macosx_10_12_x86_64.whl (650.4 kB view details)

Uploaded CPython 3.12macOS 10.12+ x86-64

File details

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

File metadata

  • Download URL: nautilus_futu-0.2.3.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.3.tar.gz
Algorithm Hash digest
SHA256 177b9a35f3e30f779d5b7dcfa569e36277daece246f4ada71287bc58ee441b5c
MD5 161ee94d2ad9bc4d8ee106f8fb4d0cca
BLAKE2b-256 634aa60c7fc12ba0ca4a668ba167e99695801af4afe440459fb0e75783bc2b7f

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for nautilus_futu-0.2.3-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 8fa3aee3d273cba0a7fc159070c2b33becc3726ed56b00cf0d8f9d309e1f3d83
MD5 7b19bfa7834bbe5da828ff51f5aa7675
BLAKE2b-256 804f53710f53a17afe2041ce41b83502c708fd9559b1af7aa5a9798fe07f5bcc

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for nautilus_futu-0.2.3-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 d48dcda5a1608e05f5677a09bb5616875bf7ec266bf67a57068e4ad68ab36f50
MD5 981cb946bf7113b118e07a8257221bac
BLAKE2b-256 502f67ac82b80051008e11d62dbf21e5faca58c27f07a8803d5cf32b265b02b4

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for nautilus_futu-0.2.3-cp313-cp313-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 8d7f0afc1d75a42799e0cd866e5b279479a2ace265b9a24708335fbb94f32d1d
MD5 bfc87b776cb57c9fec1fe455c27483f5
BLAKE2b-256 88435ffa2e896bed2220f4efadccd27e7537f5686e7dc56c45fc013dfda33d88

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for nautilus_futu-0.2.3-cp313-cp313-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 840ae388b544cda29f3c7e74206ffce5c0e8e82f71649c003d22f1e8a7242924
MD5 c5b6bdba0c9a2db4e9a0dbe4e881e253
BLAKE2b-256 95de244d577194bbc8ee3c8342780ac41eb9973b6e4cd4c0c24f5b77f3daf9a2

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for nautilus_futu-0.2.3-cp313-cp313-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 85df093d274419e5fffd9c0eca1519c26648933c8468a609a169712d615da2a5
MD5 7a2546b9f7d805e0ee8a0f376ec29b7a
BLAKE2b-256 e306c6c146ce4b1952c5d2df103539dea06e913ed232a4d62190899280cd3301

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for nautilus_futu-0.2.3-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 d49c8b4f10493b928b8f3ad2c68532419cf171c2a892a607230ce89eb632c1bc
MD5 e0e1b6c9b4a704a20f971c108e6fd196
BLAKE2b-256 b8d9be0724ec734d106eecd785992a3b85afead756121791e1bf8a128842cb0f

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for nautilus_futu-0.2.3-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 abad669addb8966701053135174be94ee420f4ebe1fdf048f804f03bd5ec0cf6
MD5 757293c5b01e4368bbda333464ff20a9
BLAKE2b-256 bbbc43c2523e4e93a91762aa9262a841c04f40d8fa2e8e30baccb1258e8024f0

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for nautilus_futu-0.2.3-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 6652d9ef09b909fe1eb816ef8785dff59823a0727829633677c2856a04306c95
MD5 592df19ba49142f84cbeb799deecfb3f
BLAKE2b-256 d3390ee2c3e7a770ffbdd3c2cb2d3e691388045281280365f40e7c7ec6059156

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for nautilus_futu-0.2.3-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 226a229ea837528148f821f4242de11c23c28b3e4561fcf5e04058efda785410
MD5 a821ed24d7ce2319d34c573a662ba953
BLAKE2b-256 477d0c76fc02172d20ee629796b8cff90b968c011f6785bcdeb7617c3f5720fc

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for nautilus_futu-0.2.3-cp312-cp312-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 b6d73db685bffa531a7a38262cdcff704d595bbe40aca95e05bd4bb0d7c398f3
MD5 2883de0bfcd6019053703068752f4f5d
BLAKE2b-256 70430a624101054d0a06fc93df4eaf4217b6cb518f1710e6bfc7c4410434f987

See more details on using hashes here.

Provenance

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