Skip to main content

nautilus-futu

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

特性

  • 独立安装包 — 不依赖 NautilusTrader 主仓库,自主控制版本发布
  • Rust 协议层 — 用 Rust 实现 Futu OpenD TCP 二进制协议(含 RSA/AES 加密),高性能低延迟
  • 无 protobuf 冲突 — 不依赖 futu-api Python 包,Rust 侧用 prost 处理 protobuf
  • 完整交易生命周期 — 下单 / 改单 / 撤单 / 条件单,订单与成交推送映射为 Nautilus 事件,支持对账
  • 行情 — 真实买卖一档报价(来自盘口)、逐笔成交、L2 盘口、K 线推送(完成 K 线 / 可选修订)、分页历史 K 线
  • 连接管理 — 行情与交易共用一条 TCP 连接,断线检测、自动重连并恢复订阅,请求超时保护

支持市场

市场 行情 交易 备注
港股 (HKEX) ✅ ✅ 正股 / ETF / 窝轮 / 牛熊 / 期权
美股 (NYSE / NASDAQ) ✅ ✅ 支持盘前盘后成交
沪深 (SSE / SZSE) ✅ ✅ 交易需开通沪深港通(TrdMarket_HKCC),结算币种 CNH
新加坡 (SGX) ✅ — 期货行情

前置条件

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

快速上手

集成 NautilusTrader

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

config = TradingNodeConfig(
    data_clients={
        "FUTU": FutuDataClientConfig(
            host="127.0.0.1",
            port=11111,
            instrument_provider=InstrumentProviderConfig(load_ids=frozenset({"00700.HKEX", "AAPL.NYSE"})),
        ),
    },
    exec_clients={
        "FUTU": FutuExecClientConfig(
            host="127.0.0.1",
            port=11111,          # 与 data client 相同 → 共用一条 TCP 连接
            trd_env=0,           # 0=模拟, 1=真实
            trd_market=1,        # 默认交易市场:1=港股, 2=美股, 4=沪深港通
            account_type="CASH", # 或 "MARGIN"
            unlock_pwd_md5="",   # 真实交易需要填写
        ),
    },
)

node = TradingNode(config=config)
node.add_data_client_factory("FUTU", FutuLiveDataClientFactory)
node.add_exec_client_factory("FUTU", FutuLiveExecClientFactory)
node.build()
node.run()

品种 ID 使用交易所作为 venue(00700.HKEX、AAPL.NYSE、600519.SSE), 适配器默认把这些 venue 路由到 FUTU 客户端,并把 FUTU 账户注册为所有 venue 的账户, 无需额外配置 routing。

策略中可用的操作

self.subscribe_quote_ticks(instrument_id)        # 买卖一档(来自盘口推送)
self.subscribe_trade_ticks(instrument_id)        # 逐笔成交
self.subscribe_order_book_deltas(instrument_id)  # L2 盘口(最多 10 档)
self.subscribe_bars(BarType.from_str("00700.HKEX-1-MINUTE-LAST-EXTERNAL"))
self.request_bars(bar_type, start=..., end=...)  # 历史 K 线(自动分页)

self.submit_order(self.order_factory.limit(...))            # 限价
self.submit_order(self.order_factory.market(...))           # 市价
self.submit_order(self.order_factory.stop_limit(...))       # 止损限价
self.submit_order(self.order_factory.trailing_stop_market(...))  # 跟踪止损
self.modify_order(order, price=...)
self.cancel_all_orders(instrument_id)

支持的订单类型:LIMIT、MARKET、STOP_MARKET、STOP_LIMIT、MARKET_IF_TOUCHED、 LIMIT_IF_TOUCHED、TRAILING_STOP_MARKET、TRAILING_STOP_LIMIT;有效期 DAY / GTC。 美股盘前盘后成交通过 FutuExecClientConfig.fill_outside_rth 或订单 tag FUTU_RTH:1 开启。

直接使用 Rust 客户端

from nautilus_futu._rust import PyFutuClient

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

quotes = client.get_security_snapshot([(1, "00700")])   # 含 bid/ask
bars = client.get_history_kl(1, "00700", rehab_type=1, kl_type=2,
                             begin_time="2025-01-01", end_time="2025-12-31")  # 自动分页

channel = client.start_push([3013])                       # 盘口推送
client.subscribe([(1, "00700")], [2], True)
msg = client.poll_push(channel, 1000)                     # 断线时抛 ConnectionError
client.disconnect()

配置说明

配置项 说明
rsa_key_path 与 OpenD 共用的 RSA 私钥(PEM),设置后握手 RSA 加密、后续 AES 加密
request_timeout 单个请求等待 OpenD 应答的秒数,默认 15
reconnect / reconnect_interval 断线自动重连及间隔
handle_revised_bars 为 True 时把未完成 K 线的每次更新以 is_revision=True 推送
order_book_depth 盘口档位上限(港股/美股 10,A 股 5)
account_type CASH 或 MARGIN,需与富途账户类型一致
set_specific_venue 把 FUTU 账户注册为所有 venue 的账户(同节点跑其它适配器时关闭)
account_refresh_interval 定时刷新资金秒数(0 关闭;订单/成交推送后总会刷新)

品种加载:InstrumentProviderConfig(load_all=True, filters={...}) 支持 {"venues": ["HKEX"]}、{"markets": [1, 11]}、{"plates": [(1, "HK.BK1001")]}、 {"option_chains": [{"instrument_id": "00700.HKEX", "begin": "2026-10-01", "end": "2026-12-31"}]}。

注意事项

  • 港股 tick 随价格档位变化,品种精度固定为 0.001;下单前可用 nautilus_futu.parsing.instruments.hk_tick_size(price) 取当前档位 tick。
  • Futu 的人民币币种为 CNH,沪深品种与资金均使用 CNH。
  • 历史 K 线受富途 30 天额度限制,request_bars 无 limit 时按时间范围全部拉取。
  • 成交手续费不在成交推送中,OrderFilled.commission 为 0,可用 PyFutuClient.get_order_fee 查询。

项目结构

nautilus-futu/
├── crates/futu/           # Rust 核心
│   ├── proto/             # Futu OpenD .proto 文件
│   └── src/
│       ├── protocol/      # TCP 协议:包头、编解码、RSA/AES
│       ├── client/        # 连接、握手、心跳、消息分发、超时
│       ├── quote/         # 行情:订阅、快照、历史K线(分页)
│       ├── trade/         # 交易:账户、下单、查询
│       ├── generated/     # Protobuf 生成的 Rust 类型
│       └── python/        # PyO3 绑定(含 poll_push_async)
├── nautilus_futu/         # Python NautilusTrader 适配器
│   ├── connection.py      # 共享连接管理(引用计数、重连代数)
│   ├── data.py            # FutuLiveDataClient
│   ├── execution.py       # FutuLiveExecutionClient
│   ├── providers.py       # FutuInstrumentProvider
│   ├── parsing/           # 数据类型转换
│   └── _rust.pyi          # Rust 扩展类型存根
├── tests/python/          # 单元测试 + 假 OpenD 端到端测试
└── examples/

开发

# 创建并激活虚拟环境
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 测试 / lint
cargo test
cargo clippy --all-targets -- -D warnings

# Python 测试 / lint
pytest tests/python -v
ruff check nautilus_futu tests

# 从 proto 重新生成 Rust 类型(需要 protoc)
cargo build --features regenerate-protos

Metadata

Release files for nautilus-futu 0.5.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for nautilus-futu 0.5.0
File Size Uploaded
nautilus_futu-0.5.0.tar.gz 169.1 kB Details

Built distributions (wheels)

Table of built distributions (wheels) for nautilus-futu 0.5.0
File
nautilus_futu-0.5.0-cp313-cp313-win_amd64.whl CPython 3.13 CPython 3.13 Windows x86-64 Details
nautilus_futu-0.5.0-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl CPython 3.13 CPython 3.13 Linux glibc 2.17+ x86-64 Details
nautilus_futu-0.5.0-cp313-cp313-manylinux_2_17_aarch64.manylinux2014_aarch64.whl CPython 3.13 CPython 3.13 Linux glibc 2.17+ ARM64 Details
nautilus_futu-0.5.0-cp313-cp313-macosx_11_0_arm64.whl CPython 3.13 CPython 3.13 macOS 11.0+ ARM64 Details
nautilus_futu-0.5.0-cp313-cp313-macosx_10_12_x86_64.whl CPython 3.13 CPython 3.13 macOS 10.12+ x86-64 Details
nautilus_futu-0.5.0-cp312-cp312-win_amd64.whl CPython 3.12 CPython 3.12 Windows x86-64 Details
nautilus_futu-0.5.0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl CPython 3.12 CPython 3.12 Linux glibc 2.17+ x86-64 Details
nautilus_futu-0.5.0-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl CPython 3.12 CPython 3.12 Linux glibc 2.17+ ARM64 Details
nautilus_futu-0.5.0-cp312-cp312-macosx_11_0_arm64.whl CPython 3.12 CPython 3.12 macOS 11.0+ ARM64 Details
nautilus_futu-0.5.0-cp312-cp312-macosx_10_12_x86_64.whl CPython 3.12 CPython 3.12 macOS 10.12+ x86-64 Details

Total release size: 13.5 MB

Release files / nautilus_futu-0.5.0.tar.gz

Download URL nautilus_futu-0.5.0.tar.gz
Size 169.1 kB
Tags Source
SHA-256 checksum
How to use checksums
4f83f44823449cb89d7db60be10e72d3950ffe9e5ab529fb1982459189bbd148
BLAKE2b-256 checksum
How to use checksums
3a0e28c680ee7c7d95067ba807e10b3f9334b8bbcb50763dd997ac65e92403b4
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 12, 2026.

Transparency log

Release files / nautilus_futu-0.5.0-cp313-cp313-win_amd64.whl

Download URL nautilus_futu-0.5.0-cp313-cp313-win_amd64.whl
Size 1.3 MB
Tags CPython 3.13 Windows x86-64
SHA-256 checksum
How to use checksums
e4f35eaa9480012e0574cd4ac35f230bf19116fd7a375363e6bccdc58a5b2ac5
BLAKE2b-256 checksum
How to use checksums
317d12e3ecf2b470be1990ab4517bf99169e2b7dffb72c448e067ee972af84bd
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 12, 2026.

Transparency log

Release files / nautilus_futu-0.5.0-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl

Download URL nautilus_futu-0.5.0-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Size 1.4 MB
Tags CPython 3.13 Linux glibc 2.17+ x86-64
SHA-256 checksum
How to use checksums
4d6c8535bd50c29b8387e6dac3d432338a129f75b980756fac27d5f8d92740b7
BLAKE2b-256 checksum
How to use checksums
7ee782709ecb8768c345f10cfe7beca3ba09f2ed28e7ced8a959a252af5e2ef4
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 12, 2026.

Transparency log

Release files / nautilus_futu-0.5.0-cp313-cp313-manylinux_2_17_aarch64.manylinux2014_aarch64.whl

Download URL nautilus_futu-0.5.0-cp313-cp313-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Size 1.4 MB
Tags CPython 3.13 Linux glibc 2.17+ ARM64
SHA-256 checksum
How to use checksums
a3a7874c93c706a0a6d52af8a3e1129a2221fc7dd904d4c11f57641c7ec5c8ce
BLAKE2b-256 checksum
How to use checksums
423d2b9701d989744056c2a63f57ee1342a880ef433974101910b90dc3bfc7f3
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 12, 2026.

Transparency log

Release files / nautilus_futu-0.5.0-cp313-cp313-macosx_11_0_arm64.whl

Download URL nautilus_futu-0.5.0-cp313-cp313-macosx_11_0_arm64.whl
Size 1.3 MB
Tags CPython 3.13 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
e337e49589349d2650c6f752c9149c835e4901eec57cbbbeec140feca839249f
BLAKE2b-256 checksum
How to use checksums
3b8e9a0226671599ab518eb3cbb7984f5b1063df5fde0332ece49f6238f5b972
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 12, 2026.

Transparency log

Release files / nautilus_futu-0.5.0-cp313-cp313-macosx_10_12_x86_64.whl

Download URL nautilus_futu-0.5.0-cp313-cp313-macosx_10_12_x86_64.whl
Size 1.3 MB
Tags CPython 3.13 macOS 10.12+ x86-64
SHA-256 checksum
How to use checksums
364255de7bccfe4287d44e55f81ea5bb9f303c653bac39bd478d56812c976484
BLAKE2b-256 checksum
How to use checksums
775915c204937504e9b1e6d896fce897a19469a50dfabe2331a1eb69354c9557
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 12, 2026.

Transparency log

Release files / nautilus_futu-0.5.0-cp312-cp312-win_amd64.whl

Download URL nautilus_futu-0.5.0-cp312-cp312-win_amd64.whl
Size 1.3 MB
Tags CPython 3.12 Windows x86-64
SHA-256 checksum
How to use checksums
28b9e545ab46b69b6a1ff2af86cec14bab991b6973a54af333ed72014e469df6
BLAKE2b-256 checksum
How to use checksums
6b73fe6e2926fcf87866bde6b6fe1d2ee575b2336d545b7719ae0c7eb0d0ae75
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 12, 2026.

Transparency log

Release files / nautilus_futu-0.5.0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl

Download URL nautilus_futu-0.5.0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Size 1.4 MB
Tags CPython 3.12 Linux glibc 2.17+ x86-64
SHA-256 checksum
How to use checksums
cfe640f8569f6690608405e2e61d798e3b677ad77f775fed37439e60dc781d37
BLAKE2b-256 checksum
How to use checksums
fe443d031df579c90c70247749c04679b54698e41b2e3494e6d376e489cca0f2
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 12, 2026.

Transparency log

Release files / nautilus_futu-0.5.0-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl

Download URL nautilus_futu-0.5.0-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Size 1.4 MB
Tags CPython 3.12 Linux glibc 2.17+ ARM64
SHA-256 checksum
How to use checksums
4a05323d4935a8ff3df8fbffa240ade7b46ed8a83be18fbf116cf223fde4f30b
BLAKE2b-256 checksum
How to use checksums
cc1c288247f4ccc09efbb37d41f34616a72cc489deb6e61abfcf8647979f6958
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 12, 2026.

Transparency log

Release files / nautilus_futu-0.5.0-cp312-cp312-macosx_11_0_arm64.whl

Download URL nautilus_futu-0.5.0-cp312-cp312-macosx_11_0_arm64.whl
Size 1.3 MB
Tags CPython 3.12 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
1e1dba417e2a6a442875aaaf55d82a702df6c93eab726d301ace9b03057077da
BLAKE2b-256 checksum
How to use checksums
00ffb0ded5f6bae9da1bdce088081bd2363349563ac8b2aeb45cc24a90ac6bc6
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 12, 2026.

Transparency log

Release files / nautilus_futu-0.5.0-cp312-cp312-macosx_10_12_x86_64.whl

Download URL nautilus_futu-0.5.0-cp312-cp312-macosx_10_12_x86_64.whl
Size 1.3 MB
Tags CPython 3.12 macOS 10.12+ x86-64
SHA-256 checksum
How to use checksums
8d64b300e6321e569e28f9a9bf4aa414c276793ebbee15836807ff41f1f4a56a
BLAKE2b-256 checksum
How to use checksums
db0449c48f24347a3c8839b4a6af58b9570d96a5c2e908495d1c30161ffa136b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 12, 2026.

Transparency log

Release history Release notifications | RSS feed

0.5.1

11 release files

This release

0.5.0 This release

11 release files

0.4.2

11 release files

0.4.1

11 release files

0.4.0

11 release files

0.3.8

11 release files

0.3.7

11 release files

0.3.6

11 release files

0.3.5

11 release files

0.3.4

11 release files

0.3.3

11 release files

0.3.2

11 release files

0.3.1

11 release files

0.3.0

11 release files

0.2.3

11 release files

0.2.2

11 release files

0.2.1

11 release files

0.2.0

10 release files

0.1.0

10 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page