Переглянути джерело

修改交易所推送数据更新标记

gepangpang 1 рік тому
батько
коміт
4918784748

+ 1 - 3
standard/src/bitget_spot_handle.rs

@@ -1,7 +1,5 @@
 use std::str::FromStr;
-use chrono::Utc;
 use rust_decimal::Decimal;
-use rust_decimal::prelude::FromPrimitive;
 use rust_decimal_macros::dec;
 use serde_json::json;
 use tracing::trace;
@@ -122,7 +120,7 @@ pub fn format_special_ticker(data: serde_json::Value, label: String) -> SpecialD
     let ap = Decimal::from_str(data["askPr"].as_str().unwrap()).unwrap();
     let aq = Decimal::from_str(data["askSz"].as_str().unwrap()).unwrap();
     let mp = (bp + ap) * dec!(0.5);
-    let t = Decimal::from_i64(Utc::now().timestamp_micros()).unwrap();
+    let t = Decimal::from_str(data["ts"].as_str().unwrap()).unwrap();
 
     let ticker_info = SpecialTicker { sell: ap, buy: bp, mid_price: mp, t };
     let depth_info = vec![bp, bq, ap, aq];

+ 3 - 4
standard/src/handle_info.rs

@@ -1,6 +1,5 @@
 use std::cmp::Ordering;
 use std::str::FromStr;
-use chrono::Utc;
 use rust_decimal::{Decimal};
 use rust_decimal::prelude::FromPrimitive;
 use rust_decimal_macros::dec;
@@ -150,7 +149,7 @@ impl HandleSwapInfo {
             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());
-                t = Decimal::from_i64(Utc::now().timestamp_micros()).unwrap();
+                t = Decimal::from_str(&res_data_json["t"].to_string()).unwrap();
             }
             ExchangeEnum::KucoinSwap => {
                 depth_asks = kucoin_handle::format_depth_items(res_data_json["asks"].clone());
@@ -165,12 +164,12 @@ impl HandleSwapInfo {
             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_i64(Utc::now().timestamp_micros()).unwrap();
+                t = Decimal::from_str(&res_data_json["seqId"].to_string()).unwrap();
             }
             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_i64(Utc::now().timestamp_micros()).unwrap();
+                t = Decimal::from_str(res_data_json["ts"].as_str().unwrap()).unwrap();
             }
             _ => {
                 error!("未找到该交易所!handle_special_depth: {:?}",exchange);

+ 1 - 3
standard/src/okx_handle.rs

@@ -1,7 +1,5 @@
 use std::str::FromStr;
-use chrono::Utc;
 use rust_decimal::Decimal;
-use rust_decimal::prelude::FromPrimitive;
 use rust_decimal_macros::dec;
 use serde::{Deserialize, Serialize};
 use tracing::trace;
@@ -129,7 +127,7 @@ pub fn format_special_ticker(data: serde_json::Value, label: String) -> SpecialD
     let ap = Decimal::from_str(asks[0].as_str().unwrap()).unwrap();
     let aq = Decimal::from_str(asks[1].as_str().unwrap()).unwrap();
     let mp = (bp + ap) * dec!(0.5);
-    let t = Decimal::from_i64(Utc::now().timestamp_micros()).unwrap();
+    let t = Decimal::from_str(data["ts"].as_str().unwrap()).unwrap();
 
     let ticker_info = SpecialTicker { sell: ap, buy: bp, mid_price: mp, t };
     let depth_info = vec![bp, bq, ap, aq];