use digdigdig3::core::types::{AccountType, ExchangeId};
use digdigdig3::core::websocket::KlineInterval;
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub enum Kind {
Trade,
AggTrade,
Kline(KlineInterval),
Ticker,
Orderbook,
MarkPrice,
FundingRate,
OpenInterest,
Liquidation,
}
impl Kind {
pub fn slug(&self) -> String {
match self {
Kind::Trade => "trades".to_string(),
Kind::AggTrade => "agg_trades".to_string(),
Kind::Kline(iv) => format!("klines_{}", iv.as_str()),
Kind::Ticker => "tickers".to_string(),
Kind::Orderbook => "orderbook_snapshots".to_string(),
Kind::MarkPrice => "mark_price".to_string(),
Kind::FundingRate => "funding_rate".to_string(),
Kind::OpenInterest => "open_interest".to_string(),
Kind::Liquidation => "liquidations".to_string(),
}
}
}
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub struct SeriesKey {
pub exchange: ExchangeId,
pub account_type: AccountType,
pub symbol: String,
pub kind: Kind,
}
impl SeriesKey {
pub fn new(
exchange: ExchangeId,
account_type: AccountType,
symbol: impl Into<String>,
kind: Kind,
) -> Self {
Self {
exchange,
account_type,
symbol: symbol.into(),
kind,
}
}
pub fn account_label(&self) -> &'static str {
match self.account_type {
AccountType::Spot => "spot",
AccountType::Margin => "margin",
AccountType::FuturesCross => "futures_cross",
AccountType::FuturesIsolated => "futures_isolated",
AccountType::Earn => "earn",
AccountType::Lending => "lending",
AccountType::Options => "options",
AccountType::Convert => "convert",
}
}
pub fn exchange_label(&self) -> String {
format!("{:?}", self.exchange).to_lowercase()
}
}