use crate::core::types::Symbol;
pub struct CryptoCompareEndpoints {
pub rest_base: &'static str,
pub ws_base: Option<&'static str>,
}
impl Default for CryptoCompareEndpoints {
fn default() -> Self {
Self {
rest_base: "https://min-api.cryptocompare.com",
ws_base: Some("wss://streamer.cryptocompare.com/v2"),
}
}
}
#[derive(Debug, Clone, Copy)]
pub enum CryptoCompareEndpoint {
Price,
PriceMulti,
PriceMultiFull,
DayAvg,
PriceHistorical,
HistoDay,
HistoHour,
HistoMinute,
HistoDayV2,
HistoHourV2,
HistoMinuteV2,
TopExchanges,
TopExchangesFull,
TopPairs,
TopVolumes,
TopMktCapFull,
TopTotalVolFull,
CoinList,
ExchangeList,
BlockchainList,
BlockchainHistoDay,
BlockchainLatest,
News,
NewsFeeds,
NewsCategories,
SocialLatest,
SocialHistoDay,
SocialHistoHour,
RateLimit,
RateLimitHour,
}
impl CryptoCompareEndpoint {
pub fn path(&self) -> &'static str {
match self {
Self::Price => "/data/price",
Self::PriceMulti => "/data/pricemulti",
Self::PriceMultiFull => "/data/pricemultifull",
Self::DayAvg => "/data/dayAvg",
Self::PriceHistorical => "/data/pricehistorical",
Self::HistoDay => "/data/histoday",
Self::HistoHour => "/data/histohour",
Self::HistoMinute => "/data/histominute",
Self::HistoDayV2 => "/data/v2/histoday",
Self::HistoHourV2 => "/data/v2/histohour",
Self::HistoMinuteV2 => "/data/v2/histominute",
Self::TopExchanges => "/data/top/exchanges",
Self::TopExchangesFull => "/data/top/exchanges/full",
Self::TopPairs => "/data/top/pairs",
Self::TopVolumes => "/data/top/volumes",
Self::TopMktCapFull => "/data/top/mktcapfull",
Self::TopTotalVolFull => "/data/top/totalvolfull",
Self::CoinList => "/data/all/coinlist",
Self::ExchangeList => "/data/all/exchanges",
Self::BlockchainList => "/data/blockchain/list",
Self::BlockchainHistoDay => "/data/blockchain/histo/day",
Self::BlockchainLatest => "/data/blockchain/latest",
Self::News => "/data/v2/news/",
Self::NewsFeeds => "/data/news/feeds",
Self::NewsCategories => "/data/news/categories",
Self::SocialLatest => "/data/social/coin/latest",
Self::SocialHistoDay => "/data/social/coin/histo/day",
Self::SocialHistoHour => "/data/social/coin/histo/hour",
Self::RateLimit => "/stats/rate/limit",
Self::RateLimitHour => "/stats/rate/hour/limit",
}
}
pub fn requires_api_key(&self) -> bool {
match self {
Self::News
| Self::SocialLatest
| Self::SocialHistoDay
| Self::SocialHistoHour
| Self::RateLimit
| Self::RateLimitHour => true,
_ => false,
}
}
}
pub fn format_symbol(symbol: &Symbol) -> (String, String) {
(
symbol.base.to_uppercase(),
symbol.quote.to_uppercase(),
)
}
pub fn map_interval_aggregate(interval: &str) -> (CryptoCompareEndpoint, u32) {
match interval {
"1m" => (CryptoCompareEndpoint::HistoMinuteV2, 1),
"3m" => (CryptoCompareEndpoint::HistoMinuteV2, 3),
"5m" => (CryptoCompareEndpoint::HistoMinuteV2, 5),
"15m" => (CryptoCompareEndpoint::HistoMinuteV2, 15),
"30m" => (CryptoCompareEndpoint::HistoMinuteV2, 30),
"1h" => (CryptoCompareEndpoint::HistoHourV2, 1),
"2h" => (CryptoCompareEndpoint::HistoHourV2, 2),
"4h" => (CryptoCompareEndpoint::HistoHourV2, 4),
"6h" => (CryptoCompareEndpoint::HistoHourV2, 6),
"8h" => (CryptoCompareEndpoint::HistoHourV2, 8),
"12h" => (CryptoCompareEndpoint::HistoHourV2, 12),
"1d" => (CryptoCompareEndpoint::HistoDayV2, 1),
"1w" => (CryptoCompareEndpoint::HistoDayV2, 7),
"1M" => (CryptoCompareEndpoint::HistoDayV2, 30),
_ => (CryptoCompareEndpoint::HistoHourV2, 1),
}
}