Selaa lähdekoodia

v4.2.1: 浮动余额、最后平仓的bug修复。

skyffire 8 kuukautta sitten
vanhempi
commit
bf30049a1d
1 muutettua tiedostoa jossa 9 lisäystä ja 4 poistoa
  1. 9 4
      strategy/src/predictor.rs

+ 9 - 4
strategy/src/predictor.rs

@@ -264,7 +264,7 @@ impl Predictor {
                     };
 
                     self.float_balance = self.balance + self.profit;
-                    self.float_balance.rescale(8);
+                    self.float_balance.rescale(4);
                 }
                 self.profit.rescale(6);
                 if self.profit_high < self.profit {
@@ -510,6 +510,7 @@ impl Predictor {
     pub async fn on_balance(&mut self, balance: Decimal) {
         if self.inventory.is_zero() {
             self.balance = balance;
+            self.float_balance = self.balance;
             self.one_grid_order_value = (self.params.lever_rate * self.balance) / self.params.grid;
         }
     }
@@ -587,7 +588,11 @@ impl Predictor {
 
             if now - *first > self.params.holding_time * Decimal::ONE_THOUSAND {
                 let side = self.trade_side_map.get(first).unwrap();
-                self.ready_close_amount = self.trade_amount_map.get(first).unwrap().clone();
+                self.ready_close_amount = if self.trade_time_vec.len() == 1 {
+                    self.pos_amount
+                } else {
+                    self.trade_amount_map.get(first).unwrap().clone()
+                };
 
                 match side.as_str() {
                     "kd" => {
@@ -629,7 +634,7 @@ impl Predictor {
             self.trade_condition = dec!(3);
             self.trade_condition_time = now;
 
-            info!(?self.mid_price, ?prev_order_price, ?self.inventory, ?self.trade_condition);
+            // info!(?self.mid_price, ?prev_order_price, ?self.inventory, ?self.trade_condition);
         }
         if is_open_short {
             self.trade_condition = dec!(4);
@@ -741,7 +746,7 @@ impl Predictor {
     }
 
     // #[instrument(skip(self), level="TRACE")]
-    async fn processor(&mut self, data_time: Decimal, is_hard_update: bool) {
+    async fn processor(&mut self, _data_time: Decimal, is_hard_update: bool) {
         self.check_ready();
         if !self.is_ready {
             return;