use nautilus_network::websocket::WebSocketClient;
use serde::{Deserialize, Serialize};
use crate::common::enums::BinanceWsMethod;
pub use crate::spot::sbe::stream::{
BestBidAskStreamEvent, DepthDiffStreamEvent, DepthSnapshotStreamEvent, PriceLevel, Trade,
TradesStreamEvent,
};
#[derive(Debug, Clone)]
pub enum BinanceSpotWsMessage {
Trades(TradesStreamEvent),
BestBidAsk(BestBidAskStreamEvent),
DepthSnapshot(DepthSnapshotStreamEvent),
DepthDiff(DepthDiffStreamEvent),
RawBinary(Vec<u8>),
RawJson(serde_json::Value),
Error(BinanceWsErrorMsg),
Reconnected,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct BinanceWsErrorMsg {
pub code: i32,
pub msg: String,
}
#[allow(
missing_debug_implementations,
clippy::large_enum_variant,
reason = "Commands are ephemeral and immediately consumed"
)]
pub enum BinanceSpotWsStreamsCommand {
SetClient(WebSocketClient),
Disconnect,
Subscribe { streams: Vec<String> },
Unsubscribe { streams: Vec<String> },
}
#[derive(Debug, Clone, Serialize)]
pub struct BinanceWsSubscription {
pub method: BinanceWsMethod,
pub params: Vec<String>,
pub id: u64,
}
impl BinanceWsSubscription {
#[must_use]
pub fn subscribe(streams: Vec<String>, id: u64) -> Self {
Self {
method: BinanceWsMethod::Subscribe,
params: streams,
id,
}
}
#[must_use]
pub fn unsubscribe(streams: Vec<String>, id: u64) -> Self {
Self {
method: BinanceWsMethod::Unsubscribe,
params: streams,
id,
}
}
}
#[derive(Debug, Clone, Deserialize)]
pub struct BinanceWsResponse {
pub result: Option<serde_json::Value>,
pub id: u64,
}
#[derive(Debug, Clone, Deserialize)]
pub struct BinanceWsErrorResponse {
pub code: i32,
pub msg: String,
pub id: Option<u64>,
}