1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
//! Get all trading pairs of a cryptocurrency exchange.
//!
//! ## Example
//!
//! ```
//! use crypto_markets::{fetch_markets, MarketType};
//!
//! fn main() {
//!     let markets = fetch_markets("Binance", MarketType::Spot).unwrap();
//!     println!("{}", serde_json::to_string_pretty(&markets).unwrap())
//! }
//! ```

mod exchanges;
mod market;
mod utils;

pub use crate::market::{Market, MarketType};

/// Fetch trading markets of a cryptocurrency exchange.
///
/// # Arguments
///
/// * `exchange` - The exchange name
/// * `market_type` - The market type
///
/// # Example
///
/// ```
/// use crypto_markets::{fetch_markets,MarketType};
/// let markets = fetch_markets("Binance", MarketType::Spot).unwrap();
/// assert!(!markets.is_empty());
/// println!("{}", serde_json::to_string_pretty(&markets).unwrap())
/// ```
pub fn fetch_markets(
    exchange: &str,
    market_type: MarketType,
) -> Result<Vec<Market>, reqwest::Error> {
    match exchange {
        "Binance" => exchanges::binance::fetch_markets(market_type),
        "BitMEX" => exchanges::bitmex::fetch_markets(market_type),
        "Huobi" => exchanges::huobi::fetch_markets(market_type),
        "OKEx" => exchanges::okex::fetch_markets(market_type),
        _ => panic!("Unsupported exchange {}", exchange),
    }
}

pub const SUPPORTED_EXCHANGES: [&str; 4] = ["Binance", "BitMEX", "Huobi", "OKEx"];

#[cfg(test)]
mod tests {
    #[test]
    fn it_works() {
        assert_eq!(2 + 2, 4);
    }
}