use serde::{Deserialize, Serialize};
#[derive(Debug, Clone, PartialEq, Eq, Hash, Serialize, Deserialize)]
pub struct KlineInterval(pub String);
impl KlineInterval {
pub fn new(s: impl Into<String>) -> Self {
Self(s.into())
}
pub fn as_str(&self) -> &str {
&self.0
}
}
impl std::fmt::Display for KlineInterval {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.write_str(&self.0)
}
}
#[derive(Debug, Clone, PartialEq, Eq, Hash, Serialize, Deserialize)]
pub enum StreamKind {
Ticker,
IndexPrice,
MarkPrice,
CompositeIndex,
Orderbook,
OrderbookDelta,
OrderbookL3,
Trade,
AggTrade,
BlockTrade,
Kline { interval: KlineInterval },
MarkPriceKline { interval: KlineInterval },
IndexPriceKline { interval: KlineInterval },
PremiumIndexKline { interval: KlineInterval },
FundingRate,
PredictedFunding,
FundingSettlement,
OpenInterest,
LongShortRatio,
InsuranceFund,
RiskLimit,
Basis,
Liquidation,
OptionGreeks,
VolatilityIndex,
HistoricalVolatility,
SettlementEvent,
AuctionEvent,
MarketWarning,
OrderUpdate,
BalanceUpdate,
PositionUpdate,
}
impl StreamKind {
pub fn is_private(&self) -> bool {
matches!(self, Self::OrderUpdate | Self::BalanceUpdate | Self::PositionUpdate)
}
pub fn is_kline(&self) -> bool {
matches!(
self,
Self::Kline { .. }
| Self::MarkPriceKline { .. }
| Self::IndexPriceKline { .. }
| Self::PremiumIndexKline { .. }
)
}
}