1use anyhow::{Result, anyhow};
2
3use crate::types::{QotMarket, Security};
4
5pub use futu_core::qot_symbol::{MAX_SYMBOL_CODE_LEN, MAX_SYMBOL_LEN};
6
7#[derive(Debug, Clone, PartialEq, Eq)]
8pub struct ParsedSymbol {
9 pub market: QotMarket,
10 pub code: String,
11}
12
13impl ParsedSymbol {
14 pub fn market_i32(&self) -> i32 {
15 self.market as i32
16 }
17
18 pub fn into_security(self) -> Security {
19 Security::new(self.market, self.code)
20 }
21}
22
23pub fn parse_symbol_parts(s: &str) -> Result<ParsedSymbol> {
24 let parsed =
25 futu_core::qot_symbol::parse_qot_symbol_parts(s).map_err(|err| anyhow!("{err}"))?;
26 Ok(ParsedSymbol {
27 market: QotMarket::from_i32(parsed.market),
28 code: parsed.code,
29 })
30}
31
32pub fn validate_full_symbol_len(s: &str) -> Result<()> {
33 futu_core::qot_symbol::validate_full_symbol_len(s).map_err(|err| anyhow!("{err}"))
34}
35
36pub fn validate_symbol_code_len(code: &str) -> Result<()> {
37 futu_core::qot_symbol::validate_symbol_code_len(code).map_err(|err| anyhow!("{err}"))
38}
39
40pub fn parse_symbol(s: &str) -> Result<Security> {
41 Ok(parse_symbol_parts(s)?.into_security())
42}
43
44pub fn format_symbol(sec: &Security) -> String {
45 futu_core::qot_symbol::format_qot_symbol(sec.market as i32, &sec.code)
46}
47
48#[cfg(test)]
49mod tests;