Ver Fonte

v3.2.7: 修复平仓信号更新不及时导致的多次打订单问题。

skyffire há 7 meses atrás
pai
commit
10467e7ee9
3 ficheiros alterados com 22 adições e 20 exclusões
  1. 17 17
      strategy/src/core.rs
  2. 1 1
      strategy/src/predictor.rs
  3. 4 2
      strategy/src/strategy.rs

+ 17 - 17
strategy/src/core.rs

@@ -654,26 +654,26 @@ impl Core {
         }
     }
 
-    pub async fn on_trade(&mut self, trade: &Trade, _name_ref: &String, trace_stack: &mut TraceStack, index: usize) {
+    pub async fn on_trade(&mut self, trade: &Trade, _name_ref: &String, _trace_stack: &mut TraceStack, index: usize) {
         if self.mode_signal == 0 && self.ready == 1 {
             self.predictor.on_trade(trade, index).await;
 
-            // 产生交易信号
-            if trade.value > Decimal::ONE_HUNDRED {
-                let mut orders = self.strategy.do_strategy(&mut self.predictor, &self.local_orders, &self.local_position, &self.local_coin, &self.local_cash);
-                trace_stack.on_after_strategy();
-
-                if orders.is_not_empty() {
-                    let mut platform_rest_fb = self.platform_rest.clone_box();
-                    // 先更新本地记录再发单。
-                    self._update_local_orders(&mut orders);
-                    // info!("订单指令:{:?}", orders);
-                    let mut ts = trace_stack.clone();
-                    spawn(async move {
-                        platform_rest_fb.command_order(&mut orders, &mut ts).await;
-                    });
-                }
-            }
+            // // 产生交易信号
+            // if trade.value > Decimal::ONE_HUNDRED {
+            //     let mut orders = self.strategy.do_strategy(&mut self.predictor, &self.local_orders, &self.local_position, &self.local_coin, &self.local_cash);
+            //     trace_stack.on_after_strategy();
+            //
+            //     if orders.is_not_empty() {
+            //         let mut platform_rest_fb = self.platform_rest.clone_box();
+            //         // 先更新本地记录再发单。
+            //         self._update_local_orders(&mut orders);
+            //         // info!("订单指令:{:?}", orders);
+            //         let mut ts = trace_stack.clone();
+            //         spawn(async move {
+            //             platform_rest_fb.command_order(&mut orders, &mut ts).await;
+            //         });
+            //     }
+            // }
         }
     }
 

+ 1 - 1
strategy/src/predictor.rs

@@ -217,7 +217,7 @@ impl Predictor {
             trade_side_map: HashMap::new(),
             trade_amount_map: HashMap::new(),
             trade_price_map: HashMap::new(),
-            ready_close_amount: Default::default(),
+            ready_close_amount: dec!(-1),
 
             // prev_update_state_time: Default::default(),
             // state: 1,

+ 4 - 2
strategy/src/strategy.rs

@@ -813,7 +813,7 @@ impl Strategy {
         // }
         // // debug!(?command);
 
-        if predictor.ask_delta != dec!(-2) && predictor.ask_delta != Decimal::ZERO {
+        if predictor.ask_delta != dec!(-2) && predictor.ask_delta != Decimal::ZERO && predictor.ready_close_amount != dec!(-1) {
             if pd_order_num == 0 {
                 let mut price = (short_lower + short_upper) * dec!(0.5);
                 // 不限制大小
@@ -833,11 +833,12 @@ impl Strategy {
                 ];
 
                 command.limits_close.insert(order_client_id, order);
+                predictor.ready_close_amount = dec!(-1);
 
                 // debug!(?command);
             }
         }
-        if predictor.bid_delta != dec!(-2) && predictor.bid_delta != Decimal::ZERO {
+        if predictor.bid_delta != dec!(-2) && predictor.bid_delta != Decimal::ZERO && predictor.ready_close_amount != dec!(-1) {
             if pk_order_num == 0 {
                 let mut price = (long_upper + long_lower) * dec!(0.5);
                 // 不限制大小
@@ -857,6 +858,7 @@ impl Strategy {
                 ];
 
                 command.limits_close.insert(order_client_id, order);
+                predictor.ready_close_amount = dec!(-1);
 
                 // debug!(?command);
             }