commodity_exchange_zh/
lib.rs

1// #![allow(unused)]
2
3#[macro_use]
4extern crate log;
5
6#[macro_use]
7mod macros {
8    #[macro_export]
9    macro_rules! bail {
10        ($($t:tt)*) => { ::color_eyre::eyre::bail!($($t)*) };
11    }
12    #[macro_export]
13    macro_rules! eyre {
14        ($($t:tt)*) => { ::color_eyre::eyre::eyre!($($t)*) };
15    }
16    #[macro_export]
17    macro_rules! ensure {
18        ($($t:tt)*) => { ::color_eyre::eyre::ensure!($($t)*) };
19    }
20}
21
22/// 合并各个交易所数据到一个表
23pub mod ce;
24/// 郑州商品交易所
25pub mod czce;
26/// 大连商品交易所
27pub mod dce;
28
29/// 辅助
30pub mod util;
31
32pub use color_eyre::eyre::Result;
33pub type Str = compact_str::CompactString;
34
35#[allow(non_camel_case_types)]
36#[derive(Debug, Clone, Copy)]
37pub enum Exchange {
38    czce,
39    dce,
40}
41
42impl Exchange {
43    pub fn run(self, year: u16) -> Result<()> {
44        match self {
45            Exchange::czce => czce::run(year)?,
46            Exchange::dce => eprintln!("{:?}", util::init_data().links_dce),
47        }
48        Ok(())
49    }
50}
51
52impl std::str::FromStr for Exchange {
53    type Err = String;
54
55    fn from_str(s: &str) -> std::result::Result<Self, Self::Err> {
56        Ok(match s {
57            "czce" | "CZCE" | "郑州" => Exchange::czce,
58            "dce" | "DCE" | "大连" => Exchange::dce,
59            _ => return Err(format!("{s} 不是商品期货交易所,只支持 czce/dce")),
60        })
61    }
62}