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