Bläddra i källkod

※※※SpecialTicker、SpecialDepth新增创建时间

gepangpang 1 år sedan
förälder
incheckning
f2cd6257a8

+ 3 - 1
standard/src/binance_handle.rs

@@ -21,14 +21,16 @@ pub fn format_special_ticker(data: serde_json::Value, label: String) -> SpecialD
     let aq = Decimal::from_str(data["A"].as_str().unwrap()).unwrap();
     let mp = (bp + ap) * dec!(0.5);
     let t = Decimal::from_str(&data["u"].to_string()).unwrap();
+    let create_at = data["E"].as_i64().unwrap() * 1000;
 
-    let ticker_info = SpecialTicker { sell: ap, buy: bp, mid_price: mp, t };
+    let ticker_info = SpecialTicker { sell: ap, buy: bp, mid_price: mp, t, create_at };
     let depth_info = vec![bp, bq, ap, aq];
     SpecialDepth {
         name: label,
         depth: depth_info,
         ticker: ticker_info,
         t,
+        create_at,
     }
 }
 

+ 2 - 1
standard/src/binance_spot_handle.rs

@@ -22,13 +22,14 @@ pub fn format_special_ticker(data: serde_json::Value, label: String) -> SpecialD
     let mp = (bp + ap) * dec!(0.5);
     let t = Decimal::from_str(&data["u"].to_string()).unwrap();
 
-    let ticker_info = SpecialTicker { sell: ap, buy: bp, mid_price: mp, t };
+    let ticker_info = SpecialTicker { sell: ap, buy: bp, mid_price: mp, t, create_at: Default::default() };
     let depth_info = vec![bp, bq, ap, aq];
     SpecialDepth {
         name: label,
         depth: depth_info,
         ticker: ticker_info,
         t,
+        create_at: Default::default(),
     }
 }
 

+ 2 - 1
standard/src/bitget_spot_handle.rs

@@ -122,12 +122,13 @@ pub fn format_special_ticker(data: serde_json::Value, label: String) -> SpecialD
     let mp = (bp + ap) * dec!(0.5);
     let t = Decimal::from_str(data["ts"].as_str().unwrap()).unwrap();
 
-    let ticker_info = SpecialTicker { sell: ap, buy: bp, mid_price: mp, t };
+    let ticker_info = SpecialTicker { sell: ap, buy: bp, mid_price: mp, t, create_at: Default::default() };
     let depth_info = vec![bp, bq, ap, aq];
     SpecialDepth {
         name: label,
         depth: depth_info,
         ticker: ticker_info,
         t,
+        create_at: Default::default(),
     }
 }

+ 3 - 1
standard/src/gate_handle.rs

@@ -137,19 +137,21 @@ pub fn format_special_ticker(data: serde_json::Value, label: String) -> SpecialD
     let depth_asks = format_depth_items(data["asks"].clone());
     let depth_bids = format_depth_items(data["bids"].clone());
     let t = Decimal::from_str(&data["t"].to_string()).unwrap();
+    let create_at = data["t"].as_i64().unwrap() * 1000;
 
     let ap = depth_asks[0].price;
     let bp = depth_bids[0].price;
     let aq = depth_asks[0].amount;
     let bq = depth_bids[0].amount;
     let mp = (bp + ap) * dec!(0.5);
-    let ticker_info = SpecialTicker { sell: ap, buy: bp, mid_price: mp, t };
+    let ticker_info = SpecialTicker { sell: ap, buy: bp, mid_price: mp, t, create_at };
     let depth_info = vec![bp, bq, ap, aq];
     SpecialDepth {
         name: label,
         depth: depth_info,
         ticker: ticker_info,
         t,
+        create_at,
     }
 }
 

+ 11 - 1
standard/src/handle_info.rs

@@ -134,41 +134,50 @@ impl HandleSwapInfo {
         let mut depth_asks: Vec<MarketOrder>;
         let mut depth_bids: Vec<MarketOrder>;
         let t: Decimal;
+        let create_at: i64;
         match exchange {
             ExchangeEnum::BinanceSpot => {
                 depth_asks = binance_handle::format_depth_items(res_data_json["asks"].clone());
                 depth_bids = binance_handle::format_depth_items(res_data_json["bids"].clone());
                 t = Decimal::from_str(&res_data_json["lastUpdateId"].to_string()).unwrap();
+                create_at = 0;
             }
             ExchangeEnum::BinanceSwap => {
                 depth_asks = binance_handle::format_depth_items(res_data_json["a"].clone());
                 depth_bids = binance_handle::format_depth_items(res_data_json["b"].clone());
                 t = Decimal::from_str(&res_data_json["u"].to_string()).unwrap();
+                create_at = res_data_json["E"].as_i64().unwrap() * 1000;
             }
             ExchangeEnum::GateSwap => {
                 depth_asks = gate_handle::format_depth_items(res_data_json["asks"].clone());
                 depth_bids = gate_handle::format_depth_items(res_data_json["bids"].clone());
+                // todo! 有id可以取 保证与py一致
                 t = Decimal::from_str(&res_data_json["t"].to_string()).unwrap();
+                create_at = res_data_json["t"].as_i64().unwrap() * 1000;
             }
             ExchangeEnum::KucoinSwap => {
                 depth_asks = kucoin_handle::format_depth_items(res_data_json["asks"].clone());
                 depth_bids = kucoin_handle::format_depth_items(res_data_json["bids"].clone());
                 t = Decimal::from_str(&res_data_json["sequence"].to_string()).unwrap();
+                create_at = res_data_json["ts"].as_i64().unwrap() * 1000;
             }
             ExchangeEnum::KucoinSpot => {
                 depth_asks = kucoin_spot_handle::format_depth_items(res_data_json["asks"].clone());
                 depth_bids = kucoin_spot_handle::format_depth_items(res_data_json["bids"].clone());
                 t = Decimal::from_str(&res_data_json["timestamp"].to_string()).unwrap();
+                create_at = 0;
             }
             ExchangeEnum::OkxSwap => {
                 depth_asks = okx_handle::format_depth_items(res_data_json[0]["asks"].clone());
                 depth_bids = okx_handle::format_depth_items(res_data_json[0]["bids"].clone());
                 t = Decimal::from_str(&res_data_json[0]["seqId"].to_string()).unwrap();
+                create_at = 0;
             }
             ExchangeEnum::BitgetSpot => {
                 depth_asks = bitget_spot_handle::format_depth_items(res_data_json[0]["asks"].clone());
                 depth_bids = bitget_spot_handle::format_depth_items(res_data_json[0]["bids"].clone());
                 t = Decimal::from_str(res_data_json[0]["ts"].as_str().unwrap()).unwrap();
+                create_at = 0;
             }
             _ => {
                 error!("未找到该交易所!handle_special_depth: {:?}",exchange);
@@ -227,13 +236,14 @@ impl HandleSwapInfo {
             }
         }
 
-        let ticker_info = SpecialTicker { sell: depth_asks[0].price, buy: depth_bids[0].price, mid_price: mp, t };
+        let ticker_info = SpecialTicker { sell: depth_asks[0].price, buy: depth_bids[0].price, mid_price: mp, t, create_at };
         let depth_info = bp.iter().cloned().chain(bv.iter().cloned()).chain(ap.iter().cloned()).chain(av.iter().cloned()).collect();
         SpecialDepth {
             name: res_data.label,
             depth: depth_info,
             ticker: ticker_info,
             t,
+            create_at,
         }
     }
 }

+ 3 - 1
standard/src/kucoin_handle.rs

@@ -46,14 +46,16 @@ pub fn format_special_ticker(data: serde_json::Value, label: String) -> SpecialD
     let aq = Decimal::from_f64(data["bestAskSize"].as_f64().unwrap()).unwrap();
     let mp = (bp + ap) * dec!(0.5);
     let t = Decimal::from_str(&data["sequence"].to_string()).unwrap();
+    let create_at = (data["ts"].as_f64().unwrap() / 1000.0).floor() as i64;
 
-    let ticker_info = SpecialTicker { sell: ap, buy: bp, mid_price: mp, t };
+    let ticker_info = SpecialTicker { sell: ap, buy: bp, mid_price: mp, t, create_at };
     let depth_info = vec![bp, bq, ap, aq];
     SpecialDepth {
         name: label,
         depth: depth_info,
         ticker: ticker_info,
         t,
+        create_at,
     }
 }
 

+ 2 - 1
standard/src/kucoin_spot_handle.rs

@@ -122,12 +122,13 @@ pub fn format_special_ticker(data: serde_json::Value, label: String) -> SpecialD
     let mp = (bp + ap) * dec!(0.5);
     let t = Decimal::from_str(data["sequence"].as_str().unwrap()).unwrap();
 
-    let ticker_info = SpecialTicker { sell: ap, buy: bp, mid_price: mp, t };
+    let ticker_info = SpecialTicker { sell: ap, buy: bp, mid_price: mp, t, create_at: Default::default() };
     let depth_info = vec![bp, bq, ap, aq];
     SpecialDepth {
         name: label,
         depth: depth_info,
         ticker: ticker_info,
         t,
+        create_at: Default::default(),
     }
 }

+ 8 - 1
standard/src/lib.rs

@@ -143,13 +143,15 @@ impl Depth {
 /// - `name<String>`: 平台信息;
 /// - `depth(Vec<Decimal>)`: 深度信息;
 /// - `ticker(SpecialTicker)`: 市场行情;
-/// - ``
+/// - `t(Decimal)`: 数据更新id
+/// - `create_at(i64)`: 数据生成时间
 #[derive(Debug, Clone, PartialEq, Eq)]
 pub struct SpecialDepth {
     pub name: String,
     pub depth: Vec<Decimal>,
     pub ticker: SpecialTicker,
     pub t: Decimal,
+    pub create_at: i64,
 }
 
 impl SpecialDepth {
@@ -159,6 +161,7 @@ impl SpecialDepth {
             depth: vec![],
             ticker: SpecialTicker::new(),
             t: Default::default(),
+            create_at: 0,
         }
     }
 }
@@ -167,12 +170,15 @@ impl SpecialDepth {
 /// - `sell(Decimal)`: 卖一价
 /// - `buy(Decimal)`: 买一价
 /// - `mid_price(Decimal)`: 平均价
+/// - `t(Decimal)`: 数据更新id
+/// - `create_at(i64)`: 数据生成时间
 #[derive(Debug, Clone, PartialEq, Eq)]
 pub struct SpecialTicker {
     pub sell: Decimal,
     pub buy: Decimal,
     pub mid_price: Decimal,
     pub t: Decimal,
+    pub create_at: i64
 }
 
 impl SpecialTicker {
@@ -182,6 +188,7 @@ impl SpecialTicker {
             buy: Default::default(),
             mid_price: Default::default(),
             t: Default::default(),
+            create_at: 0,
         }
     }
 }

+ 2 - 1
standard/src/okx_handle.rs

@@ -129,13 +129,14 @@ pub fn format_special_ticker(data: serde_json::Value, label: String) -> SpecialD
     let mp = (bp + ap) * dec!(0.5);
     let t = Decimal::from_str(data["ts"].as_str().unwrap()).unwrap();
 
-    let ticker_info = SpecialTicker { sell: ap, buy: bp, mid_price: mp, t };
+    let ticker_info = SpecialTicker { sell: ap, buy: bp, mid_price: mp, t, create_at: Default::default() };
     let depth_info = vec![bp, bq, ap, aq];
     SpecialDepth {
         name: label,
         depth: depth_info,
         ticker: ticker_info,
         t,
+        create_at: Default::default(),
     }
 }