Эх сурвалжийг харах

1. 至多500ms才挂撤单一次
2. 修复pos比较少时识别到的inv小于0的问题
3. 平仓时使用pk、pd,而不是kk,kd

skyfffire 11 сар өмнө
parent
commit
1c6a018699

+ 9 - 0
strategy/src/avellaneda_stoikov.rs

@@ -377,6 +377,15 @@ impl AvellanedaStoikov {
         self.pos_amount = pos_amount.clone();
         self.pos_avg_price = pos_avg_price.clone();
         self.inventory = (pos_amount / (min_amount_value / self.mid_price)).trunc();
+        // 小于1但不为0的情况,需要平完
+        if self.inventory.is_zero() && !pos_amount.is_zero() {
+            self.inventory = if pos_amount > &Decimal::ZERO {
+                Decimal::ONE
+            } else {
+                Decimal::NEGATIVE_ONE
+            };
+        }
+
         if prev_inventory != self.inventory && prev_inventory.is_zero() {
             self.prev_trade_time = Utc::now().timestamp_micros();
             self.close_price = self.order_ref_price;

+ 4 - 4
strategy/src/strategy.rs

@@ -840,7 +840,7 @@ impl Strategy {
             if order.side == "kd".to_string() {
                 // 在价格范围内时不处理
                 // if order.price <= long_upper && order.price >= long_lower {
-                if (self.local_time - order.local_time <= 200) && (order.price <= long_upper && order.price >= long_lower) {
+                if (self.local_time - order.local_time <= 500) && (order.price <= long_upper && order.price >= long_lower) {
                     continue
                 }
                 // debug!(?key, ?order.price, ?long_upper, ?long_lower);
@@ -848,7 +848,7 @@ impl Strategy {
             } else if order.side == "kk".to_string() { // 开空订单处理
                 // 在价格范围内时不处理
                 // if order.price >= short_lower && order.price <= short_upper {
-                if (self.local_time - order.local_time <= 200) && (order.price >= short_lower && order.price <= short_upper) {
+                if (self.local_time - order.local_time <= 500) && (order.price >= short_lower && order.price <= short_upper) {
                     continue
                 }
                 // debug!(?key, ?order.price, ?short_lower, ?short_upper);
@@ -981,7 +981,7 @@ impl Strategy {
                 let client_id = utils::generate_client_id(Some(self.broker_id.clone()));
                 let order = vec![
                     amount.to_string(),
-                    "kd".to_string(),
+                    if predictor.inventory < Decimal::ZERO {"pk".to_string()} else {"kd".to_string()},
                     target_buy_price.to_string(),
                     client_id.clone(),
                 ];
@@ -1023,7 +1023,7 @@ impl Strategy {
                 let client_id = utils::generate_client_id(Some(self.broker_id.clone()));
                 let order = vec![
                     amount.to_string(),
-                    "kk".to_string(),
+                    if predictor.inventory > Decimal::ZERO {"pd".to_string()} else {"kk".to_string()},
                     target_sell_price.to_string(),
                     client_id.clone(),
                 ];