deribit_websocket/message/
notification.rs1use crate::model::ws_types::JsonRpcNotification;
4
5#[derive(Debug, Clone)]
7pub struct NotificationHandler;
8
9impl NotificationHandler {
10 pub fn new() -> Self {
12 Self
13 }
14
15 pub fn parse_notification(&self, data: &str) -> Result<JsonRpcNotification, serde_json::Error> {
17 serde_json::from_str(data)
18 }
19
20 pub fn is_subscription_notification(&self, notification: &JsonRpcNotification) -> bool {
22 notification.method.starts_with("subscription")
23 }
24
25 pub fn extract_channel(&self, notification: &JsonRpcNotification) -> Option<String> {
27 if let Some(params) = ¬ification.params
28 && let Some(channel) = params.get("channel")
29 {
30 return channel.as_str().map(|s| s.to_string());
31 }
32 None
33 }
34
35 pub fn extract_data(&self, notification: &JsonRpcNotification) -> Option<serde_json::Value> {
37 if let Some(params) = ¬ification.params
38 && let Some(data) = params.get("data")
39 {
40 return Some(data.clone());
41 }
42 None
43 }
44}
45
46impl Default for NotificationHandler {
47 fn default() -> Self {
48 Self::new()
49 }
50}