1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
use crate::{OrderBookMsg, TradeMsg};

use serde_json::{Result, Value};
use std::collections::HashMap;

use super::{gate_spot_20210916, gate_spot_current};

pub(super) fn parse_trade(msg: &str) -> Result<Vec<TradeMsg>> {
    let json_obj = serde_json::from_str::<HashMap<String, Value>>(msg)?;
    if json_obj.contains_key("params") {
        #[allow(deprecated)]
        gate_spot_20210916::parse_trade(msg)
    } else if json_obj.contains_key("result") {
        gate_spot_current::parse_trade(msg)
    } else {
        panic!("Unknown message format: {}", msg);
    }
}

pub(crate) fn parse_l2(msg: &str, timestamp: i64) -> Result<Vec<OrderBookMsg>> {
    let json_obj = serde_json::from_str::<HashMap<String, Value>>(msg)?;
    if json_obj.contains_key("params") {
        #[allow(deprecated)]
        gate_spot_20210916::parse_l2(msg, timestamp)
    } else if json_obj.contains_key("result") {
        gate_spot_current::parse_l2(msg)
    } else {
        panic!("Unknown message format: {}", msg);
    }
}