binance_async/websocket/
spot.rs1use crate::{
2 error::BinanceError::{self, *},
3 models::Product,
4 websocket::ParseMessage,
5};
6use fehler::{throw, throws};
7use serde::Serialize;
8use serde_json::from_str;
9
10use super::AggregateTrade;
11
12#[derive(Debug, Clone, Serialize)]
13#[non_exhaustive]
14pub enum WebsocketMessage {
15 AggregateTrade(AggregateTrade),
16}
17
18impl ParseMessage for WebsocketMessage {
19 const PRODUCT: Product = Product::Spot;
20
21 #[throws(BinanceError)]
22 fn parse(stream: &str, data: &str) -> Self {
23 if stream.ends_with("@aggTrade") {
24 let value: AggregateTrade = from_str(data)?;
25 Self::AggregateTrade(value)
26 } else if stream.contains("@markPrice") {
27 throw!(StreamNotImplemented(stream.into()))
28 } else if stream.starts_with("!markPrice@arr") {
29 throw!(StreamNotImplemented(stream.into()))
30 } else if stream.contains("@kline_") {
31 throw!(StreamNotImplemented(stream.into()))
32 } else if stream.contains("@continuousKline_") {
33 throw!(StreamNotImplemented(stream.into()))
34 } else if stream.ends_with("@miniTicker") {
35 throw!(StreamNotImplemented(stream.into()))
36 } else if stream == "!miniTicker@arr" {
37 throw!(StreamNotImplemented(stream.into()))
38 } else if stream.ends_with("@ticker") {
39 throw!(StreamNotImplemented(stream.into()))
40 } else if stream == "!ticker@arr" {
41 throw!(StreamNotImplemented(stream.into()))
42 } else if stream.ends_with("@bookTicker") {
43 throw!(StreamNotImplemented(stream.into()))
44 } else if stream == "!bookTicker" {
45 throw!(StreamNotImplemented(stream.into()))
46 } else if stream.ends_with("@forceOrder") {
47 throw!(StreamNotImplemented(stream.into()))
48 } else if stream == "!forceOrder@arr" {
49 throw!(StreamNotImplemented(stream.into()))
50 } else if stream.ends_with("@depth") || stream.contains("@depth@") {
51 throw!(StreamNotImplemented(stream.into()))
52 } else if stream.contains("@depth") {
53 throw!(StreamNotImplemented(stream.into()))
54 } else if stream.ends_with("@compositeIndex") {
55 throw!(StreamNotImplemented(stream.into()))
56 } else if stream == "!contractInfo" {
57 throw!(StreamNotImplemented(stream.into()))
58 } else {
59 throw!(UnknownStream(stream.into()))
60 }
61 }
62}