Bläddra i källkod

v4.2.5: 取消订单后二次检查。

skyffire 7 månader sedan
förälder
incheckning
8381633589
3 ändrade filer med 48 tillägg och 46 borttagningar
  1. 16 13
      standard/src/bitget_swap.rs
  2. 5 6
      standard/src/bybit_swap.rs
  3. 27 27
      strategy/src/core.rs

+ 16 - 13
standard/src/bitget_swap.rs

@@ -525,19 +525,22 @@ impl Platform for BitgetSwap {
             return Err(Error::new(ErrorKind::NotFound, response.to_string()));
         }
 
-        let res_data_json = response.data;
-        let result = Order {
-            id: res_data_json["orderId"].as_str().unwrap().to_string(),
-            custom_id: res_data_json["clientOid"].as_str().unwrap().to_string(),
-            price: Decimal::ZERO,
-            amount: Decimal::ZERO,
-            deal_amount: Decimal::ZERO,
-            avg_price: Decimal::ZERO,
-            status: "REMOVE".to_string(),
-            order_type: res_data_json.to_string(),
-            trace_stack: TraceStack::new(0, Instant::now()).on_special("530 bitget_swap".to_string()),
-        };
-        Ok(result)
+        // let res_data_json = response.data;
+        // let result = Order {
+        //     id: res_data_json["orderId"].as_str().unwrap().to_string(),
+        //     custom_id: res_data_json["clientOid"].as_str().unwrap().to_string(),
+        //     price: Decimal::ZERO,
+        //     amount: Decimal::ZERO,
+        //     deal_amount: Decimal::ZERO,
+        //     avg_price: Decimal::ZERO,
+        //     status: "REMOVE".to_string(),
+        //     order_type: res_data_json.to_string(),
+        //     trace_stack: TraceStack::new(0, Instant::now()).on_special("530 bitget_swap".to_string()),
+        // };
+        // info!("cancel result: {:?}", result);
+        // Ok(result)
+
+        self.get_order_detail(order_id, custom_id).await
     }
 
     async fn cancel_orders(&mut self) -> Result<Vec<Order>, Error> {

+ 5 - 6
standard/src/bybit_swap.rs

@@ -495,11 +495,10 @@ impl Platform for BybitSwap {
         let symbol = self.symbol_uppercase.clone();
         let id = format!("t-{}", custom_id);
         let res_data = self.request.cancel_order(symbol, String::from(order_id), id.clone()).await;
-        if res_data.code == 200 {
-            let result = format_cancel_order_item(res_data.data);
-            Ok(result)
-        } else {
+        if res_data.code != 200 {
             Err(Error::new(ErrorKind::Other, res_data.to_string()))
+        } else {
+            self.get_order_detail(order_id, custom_id).await
         }
     }
     // 批量撤销订单
@@ -633,8 +632,8 @@ impl Platform for BybitSwap {
             let handle = tokio::spawn(async move {
                 let result = self_clone.cancel_order(&order_id, &custom_id).await;
                 match result {
-                    Ok(_) => {
-                        // result_sd.send(result).await.unwrap();
+                    Ok(order) => {
+                        self_clone.order_sender.send(order).await.unwrap();
                     }
                     Err(error) => {
                         // 取消失败去查订单。

+ 27 - 27
strategy/src/core.rs

@@ -348,7 +348,7 @@ impl Core {
             if self.local_orders_backup.contains_key(&data.client_id) {
                 // 不在已处理cid缓存队列中 说明还没参与过仓位计算 则执行订单计算
                 if self.handled_orders_cid.contains(&data.client_id) {
-                    // info!("订单已经参与过仓位计算 拒绝重复进行计算, 订单号:{}", data.client_id);
+                    info!("订单已经参与过仓位计算 拒绝重复进行计算, 订单号:{}", data.client_id);
                 } else {
                     // 添加进已处理队列
                     self.handled_orders_cid.push(data.client_id.clone());
@@ -562,7 +562,7 @@ impl Core {
                     }
                 }
             } else {
-                // info!("订单不属于本策略 拒绝进行仓位计算: {}", data.client_id);
+                info!("订单不属于本策略 拒绝进行仓位计算: {}", data.client_id);
             }
 
             if self.local_orders.contains_key(&data.client_id) {
@@ -1059,31 +1059,31 @@ impl Core {
         }
 
         // 仓位异常风控,只在合约模式下执行
-        // if !self.exchange.contains("spot") {
-        //     let local_position_by_orders_pos = (self.local_position_by_orders.long_pos - self.local_position_by_orders.short_pos).abs();
-        //     let local_position_pos = (self.local_position.long_pos - self.local_position.short_pos).abs();
-        //
-        //     if local_position_by_orders_pos != local_position_pos {
-        //         warn!("{}发现仓位异常", self.params.account_name);
-        //         warn!(?self.local_position_by_orders, ?self.local_position);
-        //         self.position_check_series.push(1);
-        //     } else {
-        //         self.position_check_series.push(0);
-        //     }
-        //
-        //     // self.position_check_series长度限制
-        //     if self.position_check_series.len() > 6 {
-        //         self.position_check_series.remove(0);
-        //     }
-        //
-        //     // 连续不符合判定
-        //     if self.position_check_series.iter().sum::<i8>() >= 6 {
-        //         let exit_msg = format!("{} 合约连续检查本地仓位和推算仓位不符合,退出。", self.params.account_name);
-        //         warn!(exit_msg);
-        //         self.exit_msg = exit_msg;
-        //         self.stop().await;
-        //     }
-        // }
+        if !self.exchange.contains("spot") {
+            let local_position_by_orders_pos = (self.local_position_by_orders.long_pos - self.local_position_by_orders.short_pos).abs();
+            let local_position_pos = (self.local_position.long_pos - self.local_position.short_pos).abs();
+
+            if local_position_by_orders_pos != local_position_pos {
+                warn!("{}发现仓位异常", self.params.account_name);
+                warn!(?self.local_position_by_orders, ?self.local_position);
+                self.position_check_series.push(1);
+            } else {
+                self.position_check_series.push(0);
+            }
+
+            // self.position_check_series长度限制
+            if self.position_check_series.len() > 6 {
+                self.position_check_series.remove(0);
+            }
+
+            // 连续不符合判定
+            if self.position_check_series.iter().sum::<i8>() >= 6 {
+                let exit_msg = format!("{} 合约连续检查本地仓位和推算仓位不符合,退出。", self.params.account_name);
+                warn!(exit_msg);
+                self.exit_msg = exit_msg;
+                self.stop().await;
+            }
+        }
 
         // 下单异常风控
         if self.strategy.total_amount == Decimal::ZERO {