Skip to main content

futu_core/
qot_endpoint_market.rs

1//! Endpoint-local QOT market subsets shared by StockFilter and IPO endpoints.
2//!
3//! These endpoints accept `Qot_Common.QotMarket`, but C++ first maps the input
4//! through endpoint-local `*_APIToNN` helpers and rejects unsupported markets.
5//! Keep this contract separate from generic symbol parsing so AU/CA/FX/CC do
6//! not leak into StockFilter/IPO request paths.
7
8pub const QOT_STOCK_FILTER_MARKET_VALID_VALUES: &str =
9    "HK=1, HK_FUTURE=2, US=11, CN/SH=21, SZ=22, SG=31, JP=41, MY=61";
10
11pub const QOT_IPO_MARKET_VALID_VALUES: &str = QOT_STOCK_FILTER_MARKET_VALID_VALUES;
12
13#[must_use]
14pub fn is_stock_filter_market(value: i32) -> bool {
15    is_common_stock_filter_ipo_market(value)
16}
17
18#[must_use]
19pub fn is_ipo_market(value: i32) -> bool {
20    is_common_stock_filter_ipo_market(value)
21}
22
23#[must_use]
24pub fn stock_filter_market_from_str_alias(raw: &str) -> Option<i32> {
25    market_from_str_alias(raw).filter(|value| is_stock_filter_market(*value))
26}
27
28#[must_use]
29pub fn ipo_market_from_str_alias(raw: &str) -> Option<i32> {
30    market_from_str_alias(raw).filter(|value| is_ipo_market(*value))
31}
32
33fn is_common_stock_filter_ipo_market(value: i32) -> bool {
34    matches!(value, 1 | 2 | 11 | 21 | 22 | 31 | 41 | 61)
35}
36
37fn market_from_str_alias(raw: &str) -> Option<i32> {
38    let trimmed = raw.trim();
39    let value = if let Ok(value) = trimmed.parse::<i32>() {
40        value
41    } else {
42        crate::qot_symbol::qot_market_from_str_alias(trimmed)?
43    };
44    Some(value)
45}