use std::borrow::Cow;
use std::collections::HashMap;
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub enum ChannelType {
Tickers,
Candle(String),
Books,
Trades,
Account,
Positions,
Orders,
AlgoOrders,
AdvancedAlgoOrders,
OrdersAlgo,
Balance,
PositionRisk,
BalanceAndPosition,
Greeks,
DepositInfo,
Status,
FundingRate,
IndexCandle(String),
IndexTickers,
MarkPriceCandle(String),
MarkPrice,
PriceLimit,
EstimatedPrice,
BooksLite,
Books50L,
BlockTickers,
Custom(String),
}
#[derive(Debug, Clone, Default)]
pub struct Args {
pub inst_id: Option<String>,
pub params: HashMap<String, String>,
}
impl Args {
pub fn new() -> Self {
Self {
inst_id: None,
params: HashMap::new(),
}
}
pub fn with_inst_id(mut self, inst_id: impl Into<String>) -> Self {
self.inst_id = Some(inst_id.into());
self
}
pub fn with_param(mut self, key: impl Into<String>, value: impl Into<String>) -> Self {
self.params.insert(key.into(), value.into());
self
}
}
impl ChannelType {
pub fn as_str(&self) -> Cow<'_, str> {
match self {
Self::Tickers => Cow::Borrowed("tickers"),
Self::Candle(interval) => Cow::Owned(format!("candle{}", interval)),
Self::Books => Cow::Borrowed("books"),
Self::Books50L => Cow::Borrowed("books-l2-tbt"),
Self::BooksLite => Cow::Borrowed("books5"),
Self::Trades => Cow::Borrowed("trades"),
Self::Account => Cow::Borrowed("account"),
Self::Positions => Cow::Borrowed("positions"),
Self::Orders => Cow::Borrowed("orders"),
Self::AlgoOrders => Cow::Borrowed("orders-algo"),
Self::AdvancedAlgoOrders => Cow::Borrowed("algo-advance"),
Self::OrdersAlgo => Cow::Borrowed("trades"),
Self::Balance => Cow::Borrowed("balance_and_position"),
Self::PositionRisk => Cow::Borrowed("positions-risk"),
Self::BalanceAndPosition => Cow::Borrowed("balance_and_position"),
Self::Greeks => Cow::Borrowed("greeks"),
Self::DepositInfo => Cow::Borrowed("deposit-info"),
Self::Status => Cow::Borrowed("status"),
Self::FundingRate => Cow::Borrowed("funding-rate"),
Self::IndexCandle(interval) => Cow::Borrowed(interval),
Self::IndexTickers => Cow::Borrowed("index-tickers"),
Self::MarkPriceCandle(interval) => Cow::Borrowed(interval),
Self::MarkPrice => Cow::Borrowed("mark-price"),
Self::PriceLimit => Cow::Borrowed("price-limit"),
Self::EstimatedPrice => Cow::Borrowed("estimated-price"),
Self::BlockTickers => Cow::Borrowed("block-tickers"),
Self::Custom(name) => Cow::Borrowed(name),
}
}
}