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=2,          # 日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.2.tar.gz (139.8 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.2-cp313-cp313-win_amd64.whl (1.0 MB view details)

Uploaded CPython 3.13Windows x86-64

nautilus_futu-0.4.2-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (1.2 MB view details)

Uploaded CPython 3.13manylinux: glibc 2.17+ x86-64

nautilus_futu-0.4.2-cp313-cp313-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (1.2 MB view details)

Uploaded CPython 3.13manylinux: glibc 2.17+ ARM64

nautilus_futu-0.4.2-cp313-cp313-macosx_11_0_arm64.whl (1.1 MB view details)

Uploaded CPython 3.13macOS 11.0+ ARM64

nautilus_futu-0.4.2-cp313-cp313-macosx_10_12_x86_64.whl (1.1 MB view details)

Uploaded CPython 3.13macOS 10.12+ x86-64

nautilus_futu-0.4.2-cp312-cp312-win_amd64.whl (1.0 MB view details)

Uploaded CPython 3.12Windows x86-64

nautilus_futu-0.4.2-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (1.2 MB view details)

Uploaded CPython 3.12manylinux: glibc 2.17+ x86-64

nautilus_futu-0.4.2-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (1.2 MB view details)

Uploaded CPython 3.12manylinux: glibc 2.17+ ARM64

nautilus_futu-0.4.2-cp312-cp312-macosx_11_0_arm64.whl (1.1 MB view details)

Uploaded CPython 3.12macOS 11.0+ ARM64

nautilus_futu-0.4.2-cp312-cp312-macosx_10_12_x86_64.whl (1.1 MB view details)

Uploaded CPython 3.12macOS 10.12+ x86-64

File details

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

File metadata

  • Download URL: nautilus_futu-0.4.2.tar.gz
  • Upload date:
  • Size: 139.8 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.2.tar.gz
Algorithm Hash digest
SHA256 6bddcc2f2ea4ab60d01a81bcafacb20621cfdb1d932dc94b5f22a0bcf0cf4ae6
MD5 90e6a75a84ae27603f0af13ddfdb300e
BLAKE2b-256 a1236ca345e39b706f6a5c09538e617cce3f45710737f7e16c6dfe8529c91907

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for nautilus_futu-0.4.2-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 6fa8c58296554b7c69fba237d7b4fc38e044fd8845d544f57c75982c8be35bed
MD5 7be675102d2411a5179d6c6a07087d46
BLAKE2b-256 e29c5803e401a0af2de9911ed5721f6e12b3916076e0afd275c357f7560a3358

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for nautilus_futu-0.4.2-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 a47febd811030d3dc63cd823431c338c09a8a2468f1dd62d682ec00c3097c0f4
MD5 73ba47cec5644b057abacbde46bb4094
BLAKE2b-256 73befe25d2384dc48477698e55e88fc293577b89877f80e491622e4ba9f87790

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for nautilus_futu-0.4.2-cp313-cp313-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 e055d4c98c15de213a8c42174e0f85dde9a120d76bc346bfdebaa2aedd999462
MD5 6b2bcf12638f2b811365aacb19b09462
BLAKE2b-256 78c3c0104609c65e4827fe1825b3aa4e73c0cb18300f035aba46afc9f2236a79

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for nautilus_futu-0.4.2-cp313-cp313-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 828b11d8d885a87cc3281593b67dda6b0e17cfdedec9f26c3142cc8f81890b26
MD5 23a0ed6d08d86c55c6f2cfe8cb29bdd4
BLAKE2b-256 030037496213cef6be1668200596e5e0494cb9b6c02cc3464a90281950a2573c

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for nautilus_futu-0.4.2-cp313-cp313-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 473adc3a12f6c248780f535b862ff0f363c25597fb16e562450e6e82d09a3a42
MD5 d1491be0e4475ea9f2080dec99a4e8ea
BLAKE2b-256 a6f3b9086383add6e8ab3846e0c835896ce9eab700d7112c2eb1713dbe18fc57

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for nautilus_futu-0.4.2-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 741b6afd204c54b07405504010cc9187404bdc0766b553bedbd1ff6ee907128f
MD5 a5659e9ecf9306f66ee773fb52d2dc8b
BLAKE2b-256 571dd402b357de9c3f50cded88a5cc72f8d27f113682093cecf2ac456b95f811

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for nautilus_futu-0.4.2-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 971f002b254b168ebb1ae107c882cf040e9d1fd4d019308c2133d17e4552f26f
MD5 cf83b4973982fad561c210368d50459d
BLAKE2b-256 d3d74216301ad966718409520f667cf5b6aad4e2794ef597cc601636e2383cd8

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for nautilus_futu-0.4.2-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 ae42cd837981fff724c60b19108ee59e4c4398962145083400577924ddb60865
MD5 5729295a29d09aa62947776141f7b862
BLAKE2b-256 a1b0873f86ad8b9f13b51a06ab0961c926335c81a91280df6c95465ce8f8828e

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for nautilus_futu-0.4.2-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 9046588848c0a4bcb513102459fec1f4bbbf50e9ff36d1cd9e61bc5afa69a424
MD5 44b0519b0538cc5abd60a38ad3b68479
BLAKE2b-256 267b2a735934f22b6d7b7130948cecbe2e8b3a176a925627e0ccc61dbc90f5cf

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for nautilus_futu-0.4.2-cp312-cp312-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 dc0085c213a49ccf4800622596aa3a27deb01e42c0e89ce48b912b620e17f9fc
MD5 94a20b431f35593ccf6fcfb637bcbfd9
BLAKE2b-256 08ed7c340ed88ac2af3c3bfcae9e788472bb4ee238e6b981052a7788ed74c397

See more details on using hashes here.

Provenance

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