瀏覽代碼

馬丁與取消訂單邏輯調整。

skyfffire 1 年之前
父節點
當前提交
75fa9aa5d2
共有 2 個文件被更改,包括 42 次插入39 次删除
  1. 1 1
      global/src/public_params.rs
  2. 41 38
      strategy/src/strategy.rs

+ 1 - 1
global/src/public_params.rs

@@ -22,7 +22,7 @@ pub const GATE_SPOT_LIMIT:i64 = 10;
 pub const GATE_USDT_SWAP_LIMIT:i64 = 100;
 pub const KUCOIN_SPOT_LIMIT:i64 = 15;
 pub const KUCOIN_USDT_SWAP_LIMIT:i64 = 7;
-pub const BINANCE_USDT_SWAP_LIMIT:i64 = 5;
+pub const BINANCE_USDT_SWAP_LIMIT:i64 = 10;
 pub const BINANCE_SPOT_LIMIT:i64 = 2;
 pub const COINEX_SPOT_LIMIT:i64 = 20;
 pub const COINEX_USDT_SWAP_LIMIT:i64 = 15;

+ 41 - 38
strategy/src/strategy.rs

@@ -836,22 +836,25 @@ impl Strategy {
             let key = format!("Cancel{}", *order_client_id);
             let value = vec![order.client_id.clone(), order.order_id.clone()];
 
-            // 开多订单处理
-            if order.side == "kd".to_string() {
-                // 在价格范围内时不处理
-                if order.price <= long_upper && order.price >= long_lower {
-                    continue
-                }
-                // debug!(?key, ?order.price, ?long_upper, ?long_lower);
-                command.cancel.insert(key, value);
-            } else if order.side == "kk".to_string() { // 开空订单处理
-                // 在价格范围内时不处理
-                if order.price >= short_lower && order.price <= short_upper {
-                    continue
-                }
-                // debug!(?key, ?order.price, ?short_lower, ?short_upper);
+            if self.local_time - order.local_time > 100 {
                 command.cancel.insert(key, value);
             }
+            // // 开多订单处理
+            // if order.side == "kd".to_string() {
+            //     // 在价格范围内时不处理
+            //     if order.price <= long_upper && order.price >= long_lower {
+            //         continue
+            //     }
+            //     // debug!(?key, ?order.price, ?long_upper, ?long_lower);
+            //     command.cancel.insert(key, value);
+            // } else if order.side == "kk".to_string() { // 开空订单处理
+            //     // 在价格范围内时不处理
+            //     if order.price >= short_lower && order.price <= short_upper {
+            //         continue
+            //     }
+            //     // debug!(?key, ?order.price, ?short_lower, ?short_upper);
+            //     command.cancel.insert(key, value);
+            // }
         }
     }
 
@@ -953,18 +956,18 @@ impl Strategy {
             let mut target_buy_price = predictor.optimal_bid_price;
             // target_buy_price = utils::clip(target_buy_price, self.bp * dec!(0.97), self.ap * dec!(1.0005));
             target_buy_price = utils::fix_price(target_buy_price, self.tick_size);
-            let amount = utils::get_amount_by_min_amount_value(self.min_amount_value, target_buy_price, self.step_size);
-            // let amount = if predictor.inventory < Decimal::ZERO {
-            //     // utils::fix_amount(self.step_size * predictor.inventory.abs(), self.step_size)
-            //     if predictor.level >= dec!(6) {
-            //         utils::get_amount_by_min_amount_value(self.min_amount_value * predictor.inventory, target_buy_price, self.step_size)
-            //     } else {
-            //         utils::get_amount_by_min_amount_value(self.min_amount_value * predictor.level, target_buy_price, self.step_size)
-            //     }
-            // } else {
-            //     // utils::fix_amount(self.step_size * (predictor.level + Decimal::ONE), self.step_size)
-            //     utils::get_amount_by_min_amount_value(self.min_amount_value * (predictor.level + Decimal::ONE), target_buy_price, self.step_size)
-            // };
+            // let amount = utils::get_amount_by_min_amount_value(self.min_amount_value, target_buy_price, self.step_size);
+            let amount = if predictor.inventory < Decimal::ZERO {
+                // utils::fix_amount(self.step_size * predictor.inventory.abs(), self.step_size)
+                if predictor.level >= dec!(4) {
+                    utils::get_amount_by_min_amount_value(self.min_amount_value * predictor.inventory.abs(), target_buy_price, self.step_size)
+                } else {
+                    utils::get_amount_by_min_amount_value(self.min_amount_value * predictor.level, target_buy_price, self.step_size)
+                }
+            } else {
+                // utils::fix_amount(self.step_size * (predictor.level + Decimal::ONE), self.step_size)
+                utils::get_amount_by_min_amount_value(self.min_amount_value * (predictor.level + Decimal::ONE), target_buy_price, self.step_size)
+            };
 
 
             // 下单价值判定
@@ -990,18 +993,18 @@ impl Strategy {
             // target_sell_price = utils::clip(target_sell_price, self.bp * dec!(0.9995), self.ap * dec!(1.03));
             // 取消大小限制
             target_sell_price = utils::fix_price(target_sell_price, self.tick_size);
-            let amount = utils::get_amount_by_min_amount_value(self.min_amount_value, target_sell_price, self.step_size);
-            // let amount = if predictor.inventory > Decimal::ZERO {
-            //     if predictor.level >= dec!(6) {
-            //         utils::get_amount_by_min_amount_value(self.min_amount_value * predictor.inventory, target_sell_price, self.step_size)
-            //     } else {
-            //         utils::get_amount_by_min_amount_value(self.min_amount_value * predictor.level, target_sell_price, self.step_size)
-            //     }
-            //     // utils::fix_amount(self.step_size * predictor.inventory.abs(), self.step_size)
-            // } else {
-            //     utils::get_amount_by_min_amount_value(self.min_amount_value * (predictor.level + Decimal::ONE), target_sell_price, self.step_size)
-            //     // utils::fix_amount(self.step_size * (predictor.level + Decimal::ONE), self.step_size)
-            // };
+            // let amount = utils::get_amount_by_min_amount_value(self.min_amount_value, target_sell_price, self.step_size);
+            let amount = if predictor.inventory > Decimal::ZERO {
+                if predictor.level >= dec!(4) {
+                    utils::get_amount_by_min_amount_value(self.min_amount_value * predictor.inventory.abs(), target_sell_price, self.step_size)
+                } else {
+                    utils::get_amount_by_min_amount_value(self.min_amount_value * predictor.level, target_sell_price, self.step_size)
+                }
+                // utils::fix_amount(self.step_size * predictor.inventory.abs(), self.step_size)
+            } else {
+                utils::get_amount_by_min_amount_value(self.min_amount_value * (predictor.level + Decimal::ONE), target_sell_price, self.step_size)
+                // utils::fix_amount(self.step_size * (predictor.level + Decimal::ONE), self.step_size)
+            };
 
             // 下单价值不能太大,也不能太小
             let amount_value = amount * target_sell_price;