1#![allow(clippy::unnecessary_wraps)]
2
3use crypto_market_type::MarketType;
4mod exchanges;
5
6pub fn normalize_currency(currency: &str, exchange: &str) -> String {
13 match exchange {
14 "bitfinex" => exchanges::bitfinex::normalize_currency(currency),
15 "bitmex" => exchanges::bitmex::normalize_currency(currency),
16 "kraken" => exchanges::kraken::normalize_currency(currency),
17 "kucoin" => exchanges::kucoin::normalize_currency(currency),
18 _ => currency.to_uppercase(),
19 }
20}
21
22pub fn normalize_pair(symbol: &str, exchange: &str) -> Option<String> {
41 match exchange {
42 "binance" => exchanges::binance::normalize_pair(symbol),
43 "bitfinex" => exchanges::bitfinex::normalize_pair(symbol),
44 "bitget" => exchanges::bitget::normalize_pair(symbol),
45 "bithumb" => Some(symbol.replace('-', "/")),
46 "bitmex" => exchanges::bitmex::normalize_pair(symbol),
47 "bitstamp" => exchanges::bitstamp::normalize_pair(symbol),
48 "bitz" => Some(symbol.replace('_', "/").to_uppercase()),
49 "bybit" => exchanges::bybit::normalize_pair(symbol),
50 "coinbase_pro" => Some(symbol.replace('-', "/")),
51 "deribit" => exchanges::deribit::normalize_pair(symbol),
52 "dydx" => exchanges::dydx::normalize_pair(symbol),
53 "ftx" => exchanges::ftx::normalize_pair(symbol),
54 "gate" => {
55 let (base, quote) = {
56 let v: Vec<&str> = symbol.split('_').collect();
57 (v[0].to_string(), v[1].to_string())
58 };
59
60 Some(format!("{base}/{quote}"))
61 }
62 "huobi" => exchanges::huobi::normalize_pair(symbol),
63 "kraken" => exchanges::kraken::normalize_pair(symbol),
64 "kucoin" => exchanges::kucoin::normalize_pair(symbol),
65 "mxc" | "mexc" => Some(symbol.replace('_', "/")),
66 "okex" | "okx" => {
67 let v: Vec<&str> = symbol.split('-').collect();
68 Some(format!("{}/{}", v[0], v[1]))
69 }
70 "Poloniex" => Some(symbol.replace('_', "/")),
71 "Upbit" => Some(symbol.replace('-', "/")),
72 "zb" => exchanges::zb::normalize_pair(symbol),
73 "zbg" => exchanges::zbg::normalize_pair(symbol),
74 _ => panic!("Unknown exchange {exchange}"),
75 }
76}
77
78pub fn get_market_type(symbol: &str, exchange: &str, is_spot: Option<bool>) -> MarketType {
87 match exchange {
88 "binance" => exchanges::binance::get_market_type(symbol, is_spot),
89 "bitfinex" => exchanges::bitfinex::get_market_type(symbol),
90 "bitget" => exchanges::bitget::get_market_type(symbol),
91 "bithumb" => MarketType::Spot,
92 "bitmex" => exchanges::bitmex::get_market_type(symbol),
93 "bitstamp" => MarketType::Spot,
94 "bybit" => exchanges::bybit::get_market_type(symbol),
95 "coinbase_pro" => MarketType::Spot,
96 "deribit" => exchanges::deribit::get_market_type(symbol),
97 "dydx" => MarketType::LinearSwap,
98 "ftx" => exchanges::ftx::get_market_type(symbol),
99 "gate" => exchanges::gate::get_market_type(symbol, is_spot),
100 "huobi" => exchanges::huobi::get_market_type(symbol),
101 "kraken" => exchanges::kraken::get_market_type(symbol),
102 "kucoin" => exchanges::kucoin::get_market_type(symbol),
103 "mxc" | "mexc" => exchanges::mexc::get_market_type(symbol, is_spot),
104 "okex" | "okx" => exchanges::okx::get_market_type(symbol),
105 "zb" => exchanges::zb::get_market_type(symbol),
106 "zbg" => exchanges::zbg::get_market_type(symbol),
107 _ => MarketType::Unknown,
108 }
109}