futu_trd/currency/
labels.rs1use super::{currency_id, security_firm_id};
2
3pub fn broker_label(security_firm: Option<i32>) -> &'static str {
5 match security_firm {
6 Some(security_firm_id::FUTU_HK) => "Futu HK",
7 Some(security_firm_id::FUTU_US) => "Moomoo US",
8 Some(security_firm_id::FUTU_SG) => "Moomoo SG",
9 Some(security_firm_id::FUTU_AU) => "Moomoo AU",
10 Some(security_firm_id::FUTU_CA) => "Moomoo CA",
11 Some(security_firm_id::FUTU_MY) => "Moomoo MY",
12 Some(security_firm_id::FUTU_JP) => "Moomoo JP",
13 _ => "unknown broker",
14 }
15}
16
17pub fn default_currency_by_security_firm(security_firm: Option<i32>) -> Option<i32> {
32 match security_firm? {
33 security_firm_id::FUTU_HK => Some(currency_id::HKD),
34 security_firm_id::FUTU_US => Some(currency_id::USD),
35 security_firm_id::FUTU_SG => Some(currency_id::SGD),
36 security_firm_id::FUTU_AU => Some(currency_id::AUD),
37 security_firm_id::FUTU_CA => Some(currency_id::CAD),
38 security_firm_id::FUTU_MY => Some(currency_id::MYR),
39 security_firm_id::FUTU_JP => Some(currency_id::JPY),
40 _ => None,
41 }
42}
43
44pub fn currency_label(c: i32) -> &'static str {
46 match c {
47 currency_id::HKD => "HKD",
48 currency_id::USD => "USD",
49 currency_id::CNH => "CNH",
50 currency_id::JPY => "JPY",
51 currency_id::SGD => "SGD",
52 currency_id::AUD => "AUD",
53 currency_id::CAD => "CAD",
54 currency_id::MYR => "MYR",
55 9 => "USDT", _ => "UNKNOWN",
57 }
58}
59
60pub fn parse_currency_label(s: &str) -> anyhow::Result<i32> {
66 match s.trim().to_ascii_uppercase().as_str() {
67 "HKD" => Ok(currency_id::HKD),
68 "USD" => Ok(currency_id::USD),
69 "CNH" | "CNY" | "RMB" => Ok(currency_id::CNH),
70 "JPY" => Ok(currency_id::JPY),
71 "SGD" => Ok(currency_id::SGD),
72 "AUD" => Ok(currency_id::AUD),
73 "CAD" => Ok(currency_id::CAD),
74 "MYR" => Ok(currency_id::MYR),
75 "USDT" => Ok(9),
76 _ => {
77 anyhow::bail!("invalid currency {s:?}: expected HKD|USD|CNH|JPY|SGD|AUD|CAD|MYR|USDT")
78 }
79 }
80}
81
82#[must_use]
89pub fn known_currency_label(c: Option<i32>) -> Option<&'static str> {
90 match c? {
91 currency_id::HKD => Some("HKD"),
92 currency_id::USD => Some("USD"),
93 currency_id::CNH => Some("CNH"),
94 currency_id::JPY => Some("JPY"),
95 currency_id::SGD => Some("SGD"),
96 currency_id::AUD => Some("AUD"),
97 currency_id::CAD => Some("CAD"),
98 currency_id::MYR => Some("MYR"),
99 9 => Some("USDT"),
100 _ => None,
101 }
102}
103
104pub fn unsupported_error_message(
113 requested: i32,
114 broker_label: &str,
115 supported_labels: &[&'static str],
116) -> String {
117 format!(
118 "InvalidCurrency: account at broker {broker} does not support currency {req}. \
119 supported currencies for this account: {sup}.",
120 broker = broker_label,
121 req = currency_label(requested),
122 sup = supported_labels.join(", "),
123 )
124}
125
126pub fn missing_currency_error_message(
130 broker_label: &str,
131 supported_labels: &[&'static str],
132) -> String {
133 format!(
134 "MissingCurrency: futures/universal account at broker {broker} requires \
135 the `currency` parameter. supported currencies for this account: {sup}.",
136 broker = broker_label,
137 sup = supported_labels.join(", "),
138 )
139}