futu

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

What this is — read this first

这是什么——请先阅读此部分

🖥️ Local-gateway broker. Futu does not expose a public cloud API. Instead you run a gateway program called OpenD on a machine, log into it with your Futu account, and this CLI talks to OpenD over a local socket (default
127.0.0.1:11111
). Your Futu credentials live inside OpenD — they never reach this skill.
⚠️ This means it will NOT work from the Starchild container by default, because OpenD runs on your computer, and the container's
127.0.0.1
is the container itself (a different machine). Two ways to use it:
  1. Run locally — run OpenD + this script on your own computer where OpenD is logged in. (simplest)
  2. Bridge the network — run OpenD on a host the container can reach, then set
    FUTU_HOST
    /
    FUTU_PORT
    to point at it (you handle the network/firewall/security yourself — exposing OpenD beyond localhost is risky; bind it tightly).
If
status
reports the gateway is not reachable, this is why.
🖥️ 本地网关券商工具。Futu并未提供公开的云API,而是需要在设备上运行名为OpenD的网关程序,使用你的Futu账户登录后,本CLI工具通过本地套接字(默认地址
127.0.0.1:11111
)与OpenD通信。你的Futu凭证仅存储在OpenD中——绝不会传递到本skill。
⚠️ 这意味着默认情况下无法在Starchild容器中使用,因为OpenD运行在你的电脑上,而容器的
127.0.0.1
指向容器自身(属于不同设备)。有两种使用方式:
  1. 本地运行——在已登录OpenD的电脑上同时运行OpenD和本脚本。(最简单的方式)
  2. 桥接网络——在容器可访问的主机上运行OpenD,然后设置
    FUTU_HOST
    /
    FUTU_PORT
    指向该主机(需自行处理网络/防火墙/安全问题——将OpenD暴露到本地网络之外存在风险,请严格限制访问范围)。
如果
status
命令报告网关无法连接,原因通常如上所述。

Set up OpenD (one time)

配置OpenD(一次性操作)

  1. Download OpenD for your OS from the Futu OpenAPI page (富途牛牛 / moomoo → OpenAPI). It comes as a GUI app and a command-line build.
  2. You need a funded/opened Futu or moomoo account with OpenAPI permission enabled (apply in-app if needed).
  3. Launch OpenD and log in with your Futu credentials (+ phone/2FA). Confirm the API port it listens on (default
    11111
    ).
  4. Keep OpenD running while you use this skill. For paper trading, make sure your account has a 模拟 / paper (SIMULATE) sub-account.
  1. Futu OpenAPI页面(富途牛牛 / moomoo → OpenAPI)下载对应操作系统的OpenD。它包含GUI版本和命令行版本。
  2. 你需要一个已开通并启用OpenAPI权限的Futu或moomoo账户(如需可在APP内申请)。
  3. 启动OpenD并使用你的Futu凭证登录(需验证手机号/双因素认证)。确认其监听的API端口(默认
    11111
    )。
  4. 使用本skill期间需保持OpenD运行。若进行模拟交易,请确保你的账户拥有**模拟 / paper (SIMULATE)**子账户。

Configure (.env)

配置环境变量(.env)

No secret keys here — only gateway location + (for live) the trade-password MD5. Request via secure input.
VariableRequiredNotes
FUTU_HOST
noOpenD host, default
127.0.0.1
FUTU_PORT
noOpenD port, default
11111
FUTU_TRD_MARKET
notrade market filter:
HK
(default) /
US
/
CN
/
SG
FUTU_SECURITY_FIRM
no
FUTUSECURITIES
(default),
FUTUINC
,
FUTUSG
FUTU_ACC_ID
nopin a specific account id;
0
= auto-resolve by environment
FUTU_TRADE_PWD_MD5
live onlyMD5 of your Futu trade password (needed to unlock live orders)
Paper vs live is resolved from each account's
trd_env
(
SIMULATE
= paper,
REAL
= live);
--profile
picks which one and the CLI fails closed if it can't find a matching account.
无需密钥——仅需网关地址 + (实盘交易时)交易密码的MD5值。请通过安全输入方式设置。
变量名是否必填说明
FUTU_HOST
OpenD主机地址,默认
127.0.0.1
FUTU_PORT
OpenD端口,默认
11111
FUTU_TRD_MARKET
交易市场过滤:
HK
(默认)/
US
/
CN
/
SG
FUTU_SECURITY_FIRM
FUTUSECURITIES
(默认)、
FUTUINC
FUTUSG
FUTU_ACC_ID
指定特定账户ID;
0
= 根据环境自动解析
FUTU_TRADE_PWD_MD5
仅实盘需要你的Futu交易密码的MD5值(解锁实盘订单所需)
模拟交易与实盘交易由各账户的
trd_env
字段决定(
SIMULATE
= 模拟,
REAL
= 实盘);
--profile
参数用于选择交易环境,若CLI无法找到匹配账户则会终止运行。

Usage

使用方法

pip install futu-api
(first run). JSON output. Default profile
paper
.
bash
python skills/futu/scripts/futu_cli.py status                 # checks OpenD reachability + resolves account
python skills/futu/scripts/futu_cli.py account
python skills/futu/scripts/futu_cli.py positions
python skills/futu/scripts/futu_cli.py orders [--executions]
python skills/futu/scripts/futu_cli.py quote --symbol HK.00700
python skills/futu/scripts/futu_cli.py history --symbol US.AAPL --period 1d --limit 90
首次运行需执行
pip install futu-api
。输出格式为JSON。默认配置文件为
paper
(模拟)。
bash
python skills/futu/scripts/futu_cli.py status                 # 检查OpenD可达性并解析账户
python skills/futu/scripts/futu_cli.py account
python skills/futu/scripts/futu_cli.py positions
python skills/futu/scripts/futu_cli.py orders [--executions]
python skills/futu/scripts/futu_cli.py quote --symbol HK.00700
python skills/futu/scripts/futu_cli.py history --symbol US.AAPL --period 1d --limit 90

place (paper SIMULATE): qty in whole shares; market or limit

下单(模拟SIMULATE):数量为整数股;市价单或限价单

python skills/futu/scripts/futu_cli.py place --symbol HK.00700 --side buy --qty 100 --type limit --limit-price 350 python skills/futu/scripts/futu_cli.py cancel --order-id <id>
python skills/futu/scripts/futu_cli.py place --symbol HK.00700 --side buy --qty 100 --type limit --limit-price 350 python skills/futu/scripts/futu_cli.py cancel --order-id <id>

live (REAL): needs FUTU_TRADE_PWD_MD5 in .env AND --confirm-live

实盘(REAL):需在.env中设置FUTU_TRADE_PWD_MD5并添加--confirm-live参数

python skills/futu/scripts/futu_cli.py --profile live --confirm-live place --symbol HK.00700 --side buy --qty 100

**Symbol format is mandatory:** `<MARKET>.<code>` — `HK.00700`, `US.AAPL`, `SH.600519`, `SZ.000001`. Periods: `1m 5m 15m 30m 1h 1d 1w 1M`.
python skills/futu/scripts/futu_cli.py --profile live --confirm-live place --symbol HK.00700 --side buy --qty 100

**股票代码格式为必填项**:`<市场代码>.<股票代码>` —— 例如`HK.00700`、`US.AAPL`、`SH.600519`、`SZ.000001`。周期选项:`1m 5m 15m 30m 1h 1d 1w 1M`。

Gotchas

注意事项

  • "OpenD gateway not reachable" = OpenD isn't running, not logged in, on a different machine, or a wrong host/port. Re-read the "What this is" section.
  • Futu requires whole-share
    --qty
    ; no notional orders.
  • Live orders need
    FUTU_TRADE_PWD_MD5
    (the MD5 hash of your trade password, not the password itself). The CLI unlocks the trade context only for live; paper is never unlocked.
  • HK/A-share board lots apply — odd-lot quantities may be rejected by the exchange.
  • “OpenD网关无法连接” = OpenD未运行、未登录、在不同设备上,或主机/端口设置错误。请重新阅读“这是什么”部分。
  • Futu要求数量为整数股;不支持按金额下单。
  • 实盘订单需要
    FUTU_TRADE_PWD_MD5
    (交易密码的MD5哈希值,而非密码本身)。CLI仅在实盘交易时解锁交易上下文;模拟交易无需解锁。
  • 港股/A股适用手数规则——零股数量可能会被交易所拒绝。