Ver Fonte

v4.2.5_beta: 尝试修复卡仓位和负仓位的问题。

skyffire há 7 meses atrás
pai
commit
2c2660321d
3 ficheiros alterados com 13 adições e 11 exclusões
  1. 2 2
      standard/src/bitget_swap.rs
  2. 2 2
      standard/src/bybit_swap.rs
  3. 9 7
      strategy/src/predictor.rs

+ 2 - 2
standard/src/bitget_swap.rs

@@ -471,7 +471,7 @@ impl Platform for BitgetSwap {
             }
             "pd" => {
                 params["side"] = json!("sell");
-                // params["reduceOnly"] = json!("YES");
+                params["reduceOnly"] = json!("YES");
             }
             "kk" => {
                 params["side"] = json!("sell");
@@ -479,7 +479,7 @@ impl Platform for BitgetSwap {
             }
             "pk" => {
                 params["side"] = json!("buy");
-                // params["reduceOnly"] = json!("YES");
+                params["reduceOnly"] = json!("YES");
             }
             _ => { panic!("bitget_usdt_swap 下单参数错误"); }
         };

+ 2 - 2
standard/src/bybit_swap.rs

@@ -413,7 +413,7 @@ impl Platform for BybitSwap {
             "pd" => {
                 params["side"] = json!("Sell");
                 // 减仓
-                // params["reduceOnly"] = json!(true);
+                params["reduceOnly"] = json!(true);
             }
             "kk" => {
                 params["side"] = json!("Sell");
@@ -422,7 +422,7 @@ impl Platform for BybitSwap {
             "pk" => {
                 params["side"] = json!("Buy");
                 // 减仓
-                // params["reduceOnly"] = json!(true);
+                params["reduceOnly"] = json!(true);
                 // params["positionIdx"] = json!(2);
             }
             _ => { error!("下单参数错误"); }

+ 9 - 7
strategy/src/predictor.rs

@@ -500,13 +500,15 @@ impl Predictor {
             if self.trade_time_vec.len() > 0 {
                 let pop_time = self.trade_time_vec.pop_front().unwrap();
 
-                self.trade_side_map.remove(&pop_time);
-                self.trade_amount_map.remove(&pop_time);
-                self.trade_price_map.remove(&pop_time);
-            } else {
-                // 卡仓位临时处理方案,后面再改
-                if self.inventory.is_zero() && !self.pos_amount.is_zero() {
-                    panic!("仓位卡起了:inventory={}, pos_amount={}", self.inventory, self.pos_amount);
+                let amount_cache = self.trade_amount_map.get(&pop_time).unwrap();
+                let remaining_amount = amount_cache - amount;
+
+                if remaining_amount.is_zero() {
+                    self.trade_side_map.remove(&pop_time);
+                    self.trade_amount_map.remove(&pop_time);
+                    self.trade_price_map.remove(&pop_time);
+                } else {
+                    self.trade_amount_map.insert(pop_time, remaining_amount);
                 }
             }
         }