use serde::{Deserialize, Serialize};
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub enum EndpointType {
Public,
User,
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum Channel {
Heartbeats,
Status,
Ticker {
product_ids: Vec<String>,
},
TickerBatch {
product_ids: Vec<String>,
},
Level2 {
product_ids: Vec<String>,
},
Candles {
product_ids: Vec<String>,
},
MarketTrades {
product_ids: Vec<String>,
},
User,
FuturesBalanceSummary,
}
impl Channel {
pub fn name(&self) -> &'static str {
match self {
Channel::Heartbeats => "heartbeats",
Channel::Status => "status",
Channel::Ticker { .. } => "ticker",
Channel::TickerBatch { .. } => "ticker_batch",
Channel::Level2 { .. } => "level2",
Channel::Candles { .. } => "candles",
Channel::MarketTrades { .. } => "market_trades",
Channel::User => "user",
Channel::FuturesBalanceSummary => "futures_balance_summary",
}
}
pub fn product_ids(&self) -> &[String] {
match self {
Channel::Ticker { product_ids }
| Channel::TickerBatch { product_ids }
| Channel::Level2 { product_ids }
| Channel::Candles { product_ids }
| Channel::MarketTrades { product_ids } => product_ids,
_ => &[],
}
}
pub fn endpoint_type(&self) -> EndpointType {
match self {
Channel::User | Channel::FuturesBalanceSummary => EndpointType::User,
_ => EndpointType::Public,
}
}
pub fn requires_auth(&self) -> bool {
matches!(self, Channel::User | Channel::FuturesBalanceSummary)
}
}
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq, Hash)]
#[serde(rename_all = "snake_case")]
pub enum ChannelName {
Heartbeats,
Status,
Ticker,
TickerBatch,
#[serde(alias = "l2_data")]
Level2,
Candles,
MarketTrades,
User,
FuturesBalanceSummary,
Subscriptions,
}
impl From<&Channel> for ChannelName {
fn from(channel: &Channel) -> Self {
match channel {
Channel::Heartbeats => ChannelName::Heartbeats,
Channel::Status => ChannelName::Status,
Channel::Ticker { .. } => ChannelName::Ticker,
Channel::TickerBatch { .. } => ChannelName::TickerBatch,
Channel::Level2 { .. } => ChannelName::Level2,
Channel::Candles { .. } => ChannelName::Candles,
Channel::MarketTrades { .. } => ChannelName::MarketTrades,
Channel::User => ChannelName::User,
Channel::FuturesBalanceSummary => ChannelName::FuturesBalanceSummary,
}
}
}