use super::{Hyperliquid, HyperliquidSpot};
use crate::{
Identifier,
subscription::{Subscription, book::OrderBooksL2, trade::PublicTrades},
};
use serde::Serialize;
use serde_json::{Value, json};
#[derive(Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash, Debug, Serialize)]
pub enum HyperliquidChannel {
Trades,
L2Book,
}
impl HyperliquidChannel {
pub fn subscription_payload(&self, coin: &str) -> Value {
match self {
Self::Trades => json!({
"type": "trades",
"coin": coin
}),
Self::L2Book => json!({
"type": "l2Book",
"coin": coin
}),
}
}
}
impl<Instrument> Identifier<HyperliquidChannel>
for Subscription<Hyperliquid, Instrument, PublicTrades>
{
fn id(&self) -> HyperliquidChannel {
HyperliquidChannel::Trades
}
}
impl<Instrument> Identifier<HyperliquidChannel>
for Subscription<Hyperliquid, Instrument, OrderBooksL2>
{
fn id(&self) -> HyperliquidChannel {
HyperliquidChannel::L2Book
}
}
impl<Instrument> Identifier<HyperliquidChannel>
for Subscription<HyperliquidSpot, Instrument, PublicTrades>
{
fn id(&self) -> HyperliquidChannel {
HyperliquidChannel::Trades
}
}
impl<Instrument> Identifier<HyperliquidChannel>
for Subscription<HyperliquidSpot, Instrument, OrderBooksL2>
{
fn id(&self) -> HyperliquidChannel {
HyperliquidChannel::L2Book
}
}
impl AsRef<str> for HyperliquidChannel {
fn as_ref(&self) -> &str {
match self {
Self::Trades => "trades",
Self::L2Book => "l2Book",
}
}
}