Skip to main content

futu_core/
proto_id.rs

1//! FutuOpenD API 协议 ID 常量
2//!
3//! 对应 C++ 中 `FTAPI_Define_ProtoID.h` 的定义。客户端与 OpenD 网关之间的
4//! 通信协议标识。
5//!
6//! **Stable API** — 所有常量均为稳定 ABI,外部 binary 可依赖。新增常量不算
7//! breaking;修改已有常量值 = breaking(C++ 对齐约束下不应发生)。
8
9// ========== 连接管理 ==========
10pub const INIT_CONNECT: u32 = 1001;
11pub const GET_GLOBAL_STATE: u32 = 1002;
12pub const NOTIFY: u32 = 1003;
13pub const KEEP_ALIVE: u32 = 1004;
14
15// ========== 额度查询 ==========
16pub const GET_USED_QUOTA: u32 = 1010;
17
18// ========== 行情协议 ==========
19pub const QOT_SUB: u32 = 3001;
20pub const QOT_REG_QOT_PUSH: u32 = 3002;
21pub const QOT_GET_SUB_INFO: u32 = 3003;
22pub const QOT_GET_BASIC_QOT: u32 = 3004;
23pub const QOT_UPDATE_BASIC_QOT: u32 = 3005;
24pub const QOT_GET_KL: u32 = 3006;
25pub const QOT_UPDATE_KL: u32 = 3007;
26pub const QOT_GET_RT: u32 = 3008;
27pub const QOT_UPDATE_RT: u32 = 3009;
28pub const QOT_GET_TICKER: u32 = 3010;
29pub const QOT_UPDATE_TICKER: u32 = 3011;
30pub const QOT_GET_ORDER_BOOK: u32 = 3012;
31pub const QOT_UPDATE_ORDER_BOOK: u32 = 3013;
32pub const QOT_GET_BROKER: u32 = 3014;
33pub const QOT_UPDATE_BROKER: u32 = 3015;
34pub const QOT_GET_ORDER_DETAIL: u32 = 3016;
35pub const QOT_UPDATE_ORDER_DETAIL: u32 = 3017;
36
37pub const QOT_GET_HISTORY_KL: u32 = 3100;
38pub const QOT_GET_HISTORY_KL_POINTS: u32 = 3101;
39pub const QOT_REQUEST_HISTORY_KL: u32 = 3103;
40
41pub const QOT_GET_TRADE_DATE: u32 = 3200;
42pub const QOT_GET_SUSPEND: u32 = 3201;
43pub const QOT_GET_STATIC_INFO: u32 = 3202;
44pub const QOT_GET_SECURITY_SNAPSHOT: u32 = 3203;
45pub const QOT_GET_PLATE_SET: u32 = 3204;
46pub const QOT_GET_PLATE_SECURITY: u32 = 3205;
47pub const QOT_GET_REFERENCE: u32 = 3206;
48pub const QOT_GET_OWNER_PLATE: u32 = 3207;
49pub const QOT_GET_HOLDING_CHANGE_LIST: u32 = 3208;
50pub const QOT_GET_OPTION_CHAIN: u32 = 3209;
51pub const QOT_GET_REHAB: u32 = 3702;
52
53// 新版 API
54pub const QOT_GET_WARRANT: u32 = 3210;
55pub const QOT_GET_CAPITAL_FLOW: u32 = 3211;
56pub const QOT_GET_CAPITAL_DISTRIBUTION: u32 = 3212;
57pub const QOT_GET_USER_SECURITY: u32 = 3213;
58pub const QOT_MODIFY_USER_SECURITY: u32 = 3214;
59pub const QOT_STOCK_FILTER: u32 = 3215;
60pub const QOT_GET_CODE_CHANGE: u32 = 3216;
61pub const QOT_GET_IPO_LIST: u32 = 3217;
62pub const QOT_GET_FUTURE_INFO: u32 = 3218;
63pub const QOT_REQUEST_TRADE_DATE: u32 = 3219;
64pub const QOT_SET_PRICE_REMINDER: u32 = 3220;
65pub const QOT_GET_PRICE_REMINDER: u32 = 3221;
66pub const QOT_GET_USER_SECURITY_GROUP: u32 = 3222;
67pub const QOT_GET_MARKET_STATE: u32 = 3223;
68pub const QOT_GET_OPTION_EXPIRATION_DATE: u32 = 3224;
69// Futu OpenAPI 10.6 QOT fundamental data / screen APIs.
70pub const QOT_GET_FINANCIALS_EARNINGS_PRICE_MOVE: u32 = 3225;
71pub const QOT_GET_FINANCIALS_EARNINGS_PRICE_HISTORY: u32 = 3226;
72pub const QOT_GET_FINANCIALS_STATEMENTS: u32 = 3227;
73pub const QOT_GET_FINANCIALS_REVENUE_BREAKDOWN: u32 = 3228;
74pub const QOT_GET_RESEARCH_ANALYST_CONSENSUS: u32 = 3229;
75pub const QOT_GET_RESEARCH_RATING_SUMMARY: u32 = 3230;
76pub const QOT_GET_RESEARCH_MORNINGSTAR_REPORT: u32 = 3231;
77pub const QOT_GET_VALUATION_DETAIL: u32 = 3232;
78pub const QOT_GET_VALUATION_PLATE_STOCK_LIST: u32 = 3233;
79pub const QOT_GET_CORPORATE_ACTIONS_DIVIDENDS: u32 = 3234;
80pub const QOT_GET_CORPORATE_ACTIONS_BUYBACKS: u32 = 3235;
81pub const QOT_GET_CORPORATE_ACTIONS_STOCK_SPLITS: u32 = 3236;
82pub const QOT_GET_SHAREHOLDERS_OVERVIEW: u32 = 3237;
83pub const QOT_GET_SHAREHOLDERS_HOLDING_CHANGES: u32 = 3238;
84pub const QOT_GET_SHAREHOLDERS_HOLDER_DETAIL: u32 = 3239;
85pub const QOT_GET_SHAREHOLDERS_INSTITUTIONAL: u32 = 3240;
86pub const QOT_GET_INSIDER_HOLDER_LIST: u32 = 3241;
87pub const QOT_GET_INSIDER_TRADE_LIST: u32 = 3242;
88pub const QOT_GET_COMPANY_PROFILE: u32 = 3243;
89pub const QOT_GET_COMPANY_EXECUTIVES: u32 = 3244;
90pub const QOT_GET_COMPANY_EXECUTIVE_BACKGROUND: u32 = 3245;
91pub const QOT_GET_COMPANY_OPERATIONAL_EFFICIENCY: u32 = 3246;
92pub const QOT_GET_TOP_TEN_BUY_SELL_BROKERS: u32 = 3247;
93pub const QOT_GET_DAILY_SHORT_VOLUME: u32 = 3248;
94pub const QOT_GET_SHORT_INTEREST: u32 = 3249;
95pub const QOT_GET_OPTION_VOLATILITY: u32 = 3250;
96pub const QOT_GET_OPTION_EXERCISE_PROBABILITY: u32 = 3251;
97pub const QOT_STOCK_SCREEN: u32 = 3252;
98pub const QOT_OPTION_SCREEN: u32 = 3253;
99pub const QOT_WARRANT_SCREEN: u32 = 3254;
100pub const QOT_GET_OPTION_QUOTE: u32 = 3255;
101pub const QOT_GET_OPTION_STRATEGY: u32 = 3256;
102pub const QOT_GET_OPTION_STRATEGY_ANALYSIS: u32 = 3257;
103pub const QOT_GET_OPTION_STRATEGY_SPREAD: u32 = 3258;
104/// Indicator public FTAPI lifecycle.
105///
106/// Ref: owned C++ source `APIServerCS_Define_ProtoID.h:140-142`. These are
107/// wire ABI identities, not server-configurable values; replace only when the
108/// upstream public FTAPI protocol changes.
109pub const QOT_GET_INDICATOR_LIST: u32 = 3259;
110pub const QOT_REQUEST_INDICATOR_CALC: u32 = 3260;
111pub const QOT_PUSH_INDICATOR_CALC: u32 = 3261;
112/// Search quote/news. Ref: C++ `APIServerCS_Define_ProtoID.h:144-145`.
113pub const QOT_GET_SEARCH_QUOTE: u32 = 3262;
114pub const QOT_GET_SEARCH_NEWS: u32 = 3263;
115pub const QOT_GET_OPTION_MARKET_STATISTIC: u32 = 3301;
116pub const QOT_GET_OPTION_UNDERLYING_RANK: u32 = 3305;
117pub const QOT_GET_OPTION_RANK: u32 = 3306;
118pub const QOT_GET_OPTION_EVENT: u32 = 3307;
119pub const QOT_GET_OPTION_EVENT_ALERT: u32 = 3308;
120pub const QOT_SET_OPTION_EVENT_ALERT: u32 = 3309;
121pub const QOT_GET_OPTION_ZERO_DTE_SCREENER: u32 = 3311;
122pub const QOT_GET_OPTION_ZERO_DTE_CONTRACT: u32 = 3312;
123pub const QOT_GET_OPTION_EARNINGS_SCREENER: u32 = 3313;
124pub const QOT_GET_OPTION_SELLER_SCREENER: u32 = 3314;
125pub const QOT_GET_OPTION_UNDERLYING_HIS_STATISTIC: u32 = 3302;
126pub const QOT_GET_OPTION_UNDERLYING_OVERVIEW: u32 = 3303;
127pub const QOT_GET_OPTION_UNDERLYING_HIS_VOLATILITY: u32 = 3304;
128// Futu OpenAPI 10.7+ QOT calendar, macro, rank, and hot-list APIs.
129// Ref: C++ feature/2606 `APIServerCS_Define_ProtoID.h` lists public QOT
130// 3401-3433. Rust stages them incrementally, with each shipped subset wired
131// through EndpointSpec/REST/MCP/CLI guards before release.
132pub const QOT_GET_EARNINGS_CALENDAR: u32 = 3401;
133pub const QOT_GET_MACRO_INDICATOR_LIST: u32 = 3402;
134pub const QOT_GET_MACRO_INDICATOR_HISTORY: u32 = 3403;
135pub const QOT_GET_FED_WATCH_TARGET_RATE: u32 = 3404;
136pub const QOT_GET_FED_WATCH_DOT_PLOT: u32 = 3405;
137pub const QOT_GET_EARNINGS_BEAT_RANK: u32 = 3406;
138pub const QOT_GET_DIVIDEND_RANK: u32 = 3407;
139pub const QOT_GET_DIVIDEND_CALENDAR: u32 = 3408;
140pub const QOT_GET_ECONOMIC_CALENDAR: u32 = 3409;
141pub const QOT_GET_US_PRE_MARKET_RANK: u32 = 3410;
142pub const QOT_GET_US_AFTER_HOURS_RANK: u32 = 3411;
143pub const QOT_GET_US_OVERNIGHT_RANK: u32 = 3412;
144pub const QOT_GET_TOP_MOVERS_RANK: u32 = 3413;
145pub const QOT_GET_HOT_LIST: u32 = 3414;
146pub const QOT_GET_SHORT_SELLING_RANK: u32 = 3415;
147pub const QOT_GET_PERIOD_CHANGE_RANK: u32 = 3416;
148pub const QOT_GET_HIGH_DIVIDEND_SOE_RANK: u32 = 3417;
149pub const QOT_GET_INSTITUTION_LIST: u32 = 3418;
150pub const QOT_GET_INSTITUTION_PROFILE: u32 = 3419;
151pub const QOT_GET_INSTITUTION_DISTRIBUTION: u32 = 3420;
152pub const QOT_GET_INSTITUTION_HOLDING_CHANGE: u32 = 3421;
153pub const QOT_GET_INSTITUTION_HOLDING_LIST: u32 = 3422;
154pub const QOT_GET_ARK_FUND_HOLDING: u32 = 3423;
155pub const QOT_GET_ARK_STOCK_DYNAMIC: u32 = 3424;
156pub const QOT_GET_ARK_ACTIVE_TRANSACTION: u32 = 3425;
157pub const QOT_GET_RATING_CHANGE: u32 = 3426;
158pub const QOT_GET_INDUSTRIAL_CHAIN_LIST: u32 = 3427;
159pub const QOT_GET_INDUSTRIAL_CHAIN_DETAIL: u32 = 3428;
160pub const QOT_GET_INDUSTRIAL_CHAIN_BY_PLATE: u32 = 3429;
161pub const QOT_GET_INDUSTRIAL_PLATE_INFO: u32 = 3430;
162pub const QOT_GET_INDUSTRIAL_PLATE_STOCK: u32 = 3431;
163pub const QOT_GET_HEAT_MAP_DATA: u32 = 3432;
164pub const QOT_GET_RISE_FALL_DISTRIBUTION: u32 = 3433;
165// Futu OpenAPI 10.9.6918 Event Contract public ABI.
166// Ref: C++ release/2607 APIServerCS_Define_ProtoID.h and
167// IAPIServer.cpp:132-146,302-316.
168pub const QOT_GET_EVENT_CONTRACT_CATEGORY: u32 = 3434;
169pub const QOT_FILTER_COMPETITION: u32 = 3435;
170pub const QOT_GET_EVENT_CONTRACT_SERIES_LIST: u32 = 3436;
171pub const QOT_GET_EVENT_CONTRACT_EVENT_LIST: u32 = 3437;
172pub const QOT_GET_EVENT_CONTRACT: u32 = 3438;
173pub const QOT_GET_EVENT_CONTRACT_MILESTONE_LIST: u32 = 3439;
174pub const QOT_GET_EVENT_CONTRACT_SNAPSHOT: u32 = 3445;
175pub const QOT_GET_EVENT_CONTRACT_ORDER_BOOK: u32 = 3446;
176pub const QOT_GET_EVENT_CONTRACT_KLINE: u32 = 3447;
177pub const QOT_GET_EVENT_CONTRACT_TICKER: u32 = 3448;
178pub const QOT_UPDATE_EVENT_CONTRACT_ORDER_BOOK: u32 = 3450;
179pub const QOT_UPDATE_EVENT_CONTRACT_KLINE: u32 = 3451;
180pub const QOT_UPDATE_EVENT_CONTRACT_TICKER: u32 = 3452;
181pub const QOT_GET_EVENT_CONTRACT_COMBO_LIST: u32 = 3453;
182pub const QOT_GET_EVENT_CONTRACT_COMBO_RFQ: u32 = 3454;
183pub const QOT_SUB_EVENT_CONTRACT: u32 = 3455;
184pub const QOT_REQUEST_HISTORY_EVENT_CONTRACT_KL: u32 = 3456;
185pub const QOT_GET_TECHNICAL_UNUSUAL: u32 = 3801;
186pub const QOT_GET_FINANCIAL_UNUSUAL: u32 = 3802;
187pub const QOT_GET_DERIVATIVE_UNUSUAL: u32 = 3803;
188pub const QOT_UPDATE_PRICE_REMINDER: u32 = 3019;
189/// C++ `FTAPI_ProtoID_Qot_UpdateOptionEvent`.
190/// Ref: `APIServerCS_Define_ProtoID.h:156`.
191pub const QOT_UPDATE_OPTION_EVENT: u32 = 3310;
192pub const QOT_REQUEST_HISTORY_KL_QUOTA: u32 = 3104;
193pub const QOT_REQUEST_REHAB: u32 = 3105;
194
195// 其他
196pub const VERIFICATION: u32 = 1006;
197pub const GET_USER_INFO: u32 = 1005;
198pub const GET_DELAY_STATISTICS: u32 = 1007;
199pub const TEST_CMD: u32 = 1008;
200pub const REMOTE_CMD: u32 = 1009;
201
202// NN/MM token enablement and binding-state query, useful for unlock-trade diagnostics.
203pub const GET_TOKEN_STATE: u32 = 1326;
204
205// Risk-free-rate query for option pricing; returns HK / US / JP rates.
206pub const QOT_GET_RISK_FREE_RATE: u32 = 20231;
207
208// Mobile/moomoo financial calendar view query; internal/extension backend
209// command used by legacy Rust-only financial-calendar surfaces. Public
210// OpenAPI earnings calendar is QOT_GET_EARNINGS_CALENDAR (3401).
211pub const QOT_GET_FINANCIAL_CALENDAR_VIEW_INTERNAL: u32 = 20025;
212// Mobile/moomoo target-stock financial calendar search.
213// Rust OpenD read-only extension; backend/platform CMD20426.
214pub const QOT_SEARCH_TARGET_FINANCIAL_CALENDAR: u32 = 20426;
215
216// Spread-table query for quote price increments.
217pub const QOT_GET_SPREAD_TABLE: u32 = 6503;
218
219// Ticker-statistic summary query.
220pub const QOT_GET_TICKER_STATISTIC: u32 = 6365;
221// Ticker-statistic detail query; returns statistic rows plus pagination metadata.
222pub const QOT_GET_TICKER_STATISTIC_DETAIL: u32 = 6366;
223
224// ========== 交易协议 ==========
225pub const TRD_GET_ACC_LIST: u32 = 2001;
226pub const TRD_UNLOCK_TRADE: u32 = 2005;
227pub const TRD_SUB_ACC_PUSH: u32 = 2008;
228
229/// Rust-daemon local public proto_id for CLI/raw TCP account-push unsubscribe.
230///
231/// C++/backend only defines `TRD_SUB_ACC_PUSH` (2008) with `acc_id_list`; it has
232/// no sub/unsub discriminator. Rust therefore needs a daemon-local routing id
233/// for account-push unsubscribe. This low-bit id is intentionally public-reachable
234/// for `futucli unsub-acc-push`; it must not be forwarded to backend.
235pub const TRD_UNSUB_ACC_PUSH_LOCAL: u32 = 0x7FFF_0000 | TRD_SUB_ACC_PUSH;
236
237/// Daemon-internal proto_id for `/api/unsub-acc-push`.
238///
239/// **不是真 backend cmd_id** — backend `Trd_SubAccPush` proto 只有
240/// `acc_id_list`, 没有 sub/unsub 区分. daemon 用此 internal proto_id 路由到
241/// `UnsubAccPushHandler` (调 `unsubscribe_trd_acc` 真撤订阅), 不发 backend.
242///
243/// **0x80000000 标记 bit**: 内部合成 ID, 不与真 backend cmd_id 冲突. 真
244/// backend 看到此 ID 会 reject (但不会到达 backend, daemon-local handler
245/// 直接处理). REST `/api/unsub-acc-push` routes to this daemon-local handler.
246pub const TRD_UNSUB_ACC_PUSH_INTERNAL: u32 = 0x8000_0000 | 2008;
247
248// 交易新版 API
249pub const TRD_GET_MARGIN_RATIO: u32 = 2223;
250pub const TRD_GET_ORDER_FEE: u32 = 2225;
251pub const TRD_FLOW_SUMMARY: u32 = 2226;
252
253// Cash log, cash detail, and business-group query endpoints.
254pub const TRD_GET_CASH_LOG: u32 = 22701; // mobile clt_cmd 3000
255pub const TRD_GET_CASH_DETAIL: u32 = 22702; // mobile clt_cmd 3001
256pub const TRD_GET_BIZ_GROUP: u32 = 22703; // mobile clt_cmd 3002
257
258// Margin-account information per market.
259pub const TRD_GET_MARGIN_INFO: u32 = 22704;
260// Backend NN command IDs for per-market margin-info routing.
261
262// Account compliance flags for product access, risk assessment, and opt-in status.
263pub const TRD_GET_ACCOUNT_FLAG: u32 = 22705; // FTAPI client→daemon
264
265// Bond holdings and bond trade-preparation endpoints.
266// Only HK / US / SG bond accounts normally return data; other accounts may return empty.
267pub const TRD_GET_BOND_TOTAL_ASSET: u32 = 22706; // 账户债券总持仓
268pub const TRD_GET_BOND_SINGLE_ASSET: u32 = 22707; // 单只债券持仓
269pub const TRD_GET_BOND_POSITION_LIST: u32 = 22708; // 账户债券持仓列表
270pub const TRD_GET_BOND_ANSWER_STATE: u32 = 22709; // 是否需要答题
271pub const TRD_GET_BOND_TRADE_REMINDER: u32 = 22710; // 交易提醒 (是否可买/复杂/高风险等)
272// daemon→backend NN cmd_id (mobile clt_cmd_* 同号)
273
274pub const TRD_GET_FUNDS: u32 = 2101;
275pub const TRD_GET_POSITION_LIST: u32 = 2102;
276pub const TRD_GET_MAX_TRD_QTYS: u32 = 2111;
277pub const TRD_GET_COMBO_MAX_TRD_QTYS: u32 = 2112;
278pub const TRD_GET_ORDER_LIST: u32 = 2201;
279pub const TRD_PLACE_ORDER: u32 = 2202;
280pub const TRD_MODIFY_ORDER: u32 = 2205;
281pub const TRD_UPDATE_ORDER: u32 = 2208;
282pub const TRD_GET_ORDER_FILL_LIST: u32 = 2211;
283pub const TRD_UPDATE_ORDER_FILL: u32 = 2218;
284pub const TRD_GET_HISTORY_ORDER_LIST: u32 = 2221;
285pub const TRD_GET_HISTORY_ORDER_FILL_LIST: u32 = 2222;
286pub const TRD_PLACE_COMBO_ORDER: u32 = 2227;
287pub const TRD_RECONFIRM_ORDER: u32 = 2237;
288pub const TRD_NOTIFY: u32 = 2240;
289
290/// **Stable API** — 判断协议 ID 是否为推送类型。
291///
292/// 跨 futu-net / futu-server 共享判定,避免两处独立 match 漂移。
293#[must_use]
294pub fn is_push_proto(proto_id: u32) -> bool {
295    matches!(
296        proto_id,
297        NOTIFY
298            | QOT_UPDATE_BASIC_QOT
299            | QOT_UPDATE_KL
300            | QOT_UPDATE_RT
301            | QOT_UPDATE_TICKER
302            | QOT_UPDATE_ORDER_BOOK
303            | QOT_UPDATE_BROKER
304            | QOT_UPDATE_ORDER_DETAIL
305            | QOT_UPDATE_PRICE_REMINDER
306            | QOT_UPDATE_OPTION_EVENT
307            | QOT_PUSH_INDICATOR_CALC
308            | TRD_UPDATE_ORDER
309            | TRD_UPDATE_ORDER_FILL
310            | TRD_NOTIFY
311    )
312}
313
314#[cfg(test)]
315mod tests;