Procházet zdrojové kódy

深度用指针不用clone.

skyffire před 1 rokem
rodič
revize
c5f03e4172

+ 0 - 7
standard/src/binance_swap_handle.rs

@@ -4,8 +4,6 @@ use rust_decimal_macros::dec;
 use serde_json::Value;
 use exchanges::response_base::ResponseData;
 use crate::{MarketOrder, SpecialDepth, SpecialTicker};
-use crate::exchange::ExchangeEnum;
-use crate::handle_info::HandleSwapInfo;
 
 
 // 处理特殊Ticker信息
@@ -29,11 +27,6 @@ pub fn handle_special_ticker(res_data: &ResponseData) -> SpecialDepth {
     }
 }
 
-// 处理特殊深度数据
-pub fn handle_special_depth(res_data: ResponseData) -> SpecialDepth {
-    HandleSwapInfo::handle_special_depth(ExchangeEnum::BinanceSwap, res_data)
-}
-
 // 格式化深度信息
 pub fn format_depth_items(value: Value) -> Vec<MarketOrder> {
     let mut depth_items: Vec<MarketOrder> = vec![];

+ 0 - 7
standard/src/gate_swap_handle.rs

@@ -8,8 +8,6 @@ use tracing::{error};
 use exchanges::response_base::ResponseData;
 use global::trace_stack::TraceStack;
 use crate::{Account, MarketOrder, Order, Position, PositionModeEnum, SpecialDepth, SpecialOrder, SpecialTicker};
-use crate::exchange::ExchangeEnum;
-use crate::handle_info::HandleSwapInfo;
 
 // 处理账号信息
 pub fn handle_account_info(res_data: ResponseData, symbol: String) -> Account {
@@ -144,11 +142,6 @@ pub fn handle_special_ticker(res_data: &ResponseData) -> SpecialDepth {
     }
 }
 
-// 处理特殊深度数据
-pub fn handle_special_depth(res_data: ResponseData) -> SpecialDepth {
-    HandleSwapInfo::handle_special_depth(ExchangeEnum::GateSwap, res_data)
-}
-
 pub fn format_depth_items(value: serde_json::Value) -> Vec<MarketOrder> {
     let mut depth_items: Vec<MarketOrder> = vec![];
     for value in value.as_array().unwrap() {

+ 10 - 11
standard/src/handle_info.rs

@@ -140,7 +140,7 @@ impl HandleSwapInfo {
     }
 
     // 处理深度信息
-    pub fn handle_special_depth(exchange: ExchangeEnum, res_data: ResponseData) -> SpecialDepth {
+    pub fn handle_special_depth(exchange: ExchangeEnum, res_data: &ResponseData) -> SpecialDepth {
         let label = res_data.label.clone();
         // 格式化
         let mut format_depth = format_depth(exchange, res_data);
@@ -214,8 +214,7 @@ pub fn make_special_depth(label: String, depth_asks: &mut Vec<MarketOrder>, dept
     }
 }
 
-pub fn format_depth(exchange: ExchangeEnum, res_data: ResponseData) -> DepthParam {
-    let res_data_json = res_data.data;
+pub fn format_depth(exchange: ExchangeEnum, res_data: &ResponseData) -> DepthParam {
     let depth_asks: Vec<MarketOrder>;
     let depth_bids: Vec<MarketOrder>;
     let t: Decimal;
@@ -228,17 +227,17 @@ pub fn format_depth(exchange: ExchangeEnum, res_data: ResponseData) -> DepthPara
         //     create_at = 0;
         // }
         ExchangeEnum::BinanceSwap => {
-            depth_asks = binance_swap_handle::format_depth_items(res_data_json["a"].clone());
-            depth_bids = binance_swap_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;
+            depth_asks = binance_swap_handle::format_depth_items(res_data.data["a"].clone());
+            depth_bids = binance_swap_handle::format_depth_items(res_data.data["b"].clone());
+            t = Decimal::from_str(&res_data.data["u"].to_string()).unwrap();
+            create_at = res_data.data["E"].as_i64().unwrap() * 1000;
         }
         ExchangeEnum::GateSwap => {
-            depth_asks = gate_swap_handle::format_depth_items(res_data_json["asks"].clone());
-            depth_bids = gate_swap_handle::format_depth_items(res_data_json["bids"].clone());
+            depth_asks = gate_swap_handle::format_depth_items(res_data.data["asks"].clone());
+            depth_bids = gate_swap_handle::format_depth_items(res_data.data["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;
+            t = Decimal::from_str(&res_data.data["t"].to_string()).unwrap();
+            create_at = res_data.data["t"].as_i64().unwrap() * 1000;
         }
         // ExchangeEnum::KucoinSwap => {
         //     depth_asks = kucoin_handle::format_depth_items(res_data_json["asks"].clone());

+ 1 - 1
strategy/src/binance_usdt_swap.rs

@@ -90,7 +90,7 @@ async fn on_data(core_arc_clone: Arc<Mutex<Core>>,
     } else if data.channel == "depth" {
         // 将depth数据转换为模拟深度
         let label = data.label.clone();
-        let special_depth = standard::handle_info::HandleSwapInfo::handle_special_depth(BinanceSwap, data);
+        let special_depth = standard::handle_info::HandleSwapInfo::handle_special_depth(BinanceSwap, &data);
 
         on_special_depth(core_arc_clone, update_flag_u, label, trace_stack, special_depth).await;
     }

+ 4 - 2
strategy/src/gate_swap.rs

@@ -103,9 +103,11 @@ async fn on_data(core_arc_clone: Arc<Mutex<Core>>,
 
     let trace_stack = TraceStack::new(data.time, data.ins);
     if data.channel == "futures.order_book" {
-        let depth = standard::handle_info::HandleSwapInfo::handle_special_depth(GateSwap, data.clone());
+        let depth = standard::handle_info::HandleSwapInfo::handle_special_depth(GateSwap, &data);
 
-        on_special_depth(core_arc_clone, update_flag_u, data.label, trace_stack, depth).await;
+        TraceStack::show_delay(&data.ins);
+
+        on_special_depth(core_arc_clone, update_flag_u, data.label.clone(), trace_stack, depth).await;
     } else if data.channel == "futures.balances" {
         let account = standard::handle_info::HandleSwapInfo::handle_account_info(GateSwap, data, run_symbol.clone());
         {