Ver Fonte

测试2

skyffire há 1 ano atrás
pai
commit
84d9619500
2 ficheiros alterados com 23 adições e 15 exclusões
  1. 15 7
      strategy/src/avellaneda_stoikov.rs
  2. 8 8
      strategy/src/strategy.rs

+ 15 - 7
strategy/src/avellaneda_stoikov.rs

@@ -275,7 +275,7 @@ impl AvellanedaStoikov {
 
     pub fn update_delta(&mut self) {
         if self.gamma != Decimal::ZERO {
-            let pos_edge = self.sigma_square * self.inventory * self.t_diff;
+            let pos_edge = self.sigma_square * self.inventory.abs() * self.t_diff;
 
             self.base_delta = self.sigma_square;
             // self.ratio_edge = self.flow_ratio_mfi * self.sigma_square;
@@ -284,11 +284,11 @@ impl AvellanedaStoikov {
             self.ask_delta = self.base_delta;
 
             if self.inventory > Decimal::ZERO {
-                self.bid_delta += pos_edge * Decimal::TEN;
-                self.ask_delta = Decimal::ZERO;
+                self.bid_delta += pos_edge * Decimal::TWO;
+                self.ask_delta = Decimal::NEGATIVE_ONE;
             } else if self.inventory < Decimal::ZERO {
-                self.bid_delta = Decimal::ZERO;
-                self.ask_delta += pos_edge * Decimal::TEN;
+                self.bid_delta = Decimal::NEGATIVE_ONE;
+                self.ask_delta += pos_edge * Decimal::TWO;
             }
             //
             // if (self.ratio_edge > Decimal::ZERO) || (self.money_flow_index > dec!(60) && self.inventory > Decimal::ZERO) {
@@ -315,8 +315,16 @@ impl AvellanedaStoikov {
     }
 
     pub fn update_optimal_ask_and_bid(&mut self) {
-        self.optimal_ask_price = max(self.ref_price + self.ask_delta, self.ask_price);
-        self.optimal_bid_price = min(self.ref_price - self.bid_delta, self.bid_price);
+        self.optimal_ask_price = if self.ask_delta == Decimal::NEGATIVE_ONE {
+            self.ask_price
+        } else {
+            max(self.ref_price + self.ask_delta, self.ask_price)
+        };
+        self.optimal_bid_price = if self.bid_price == Decimal::NEGATIVE_ONE {
+            self.bid_price
+        } else {
+            min(self.ref_price - self.bid_delta, self.bid_price)
+        };
     }
 
     pub fn update_t_diff(&mut self) {

+ 8 - 8
strategy/src/strategy.rs

@@ -826,10 +826,10 @@ impl Strategy {
     pub fn _cancel_open(&self, command: &mut OrderCommand, local_orders: &HashMap<String, OrderInfo>) {
         // debug!(?command);
         // 挂单范围
-        // let long_upper = self.open_dist[0];
-        // let long_lower = self.open_dist[1];
-        // let short_lower = self.open_dist[2];
-        // let short_upper = self.open_dist[3];
+        let long_upper = self.open_dist[0];
+        let long_lower = self.open_dist[1];
+        let short_lower = self.open_dist[2];
+        let short_upper = self.open_dist[3];
 
         for order_client_id in local_orders.keys() {
             let order = local_orders.get(order_client_id).unwrap();
@@ -839,16 +839,16 @@ impl Strategy {
             // 开多订单处理
             if order.side == "kd".to_string() {
                 // 在价格范围内时不处理
-                // if (order.price <= long_upper && order.price >= long_lower) || self.local_time - order.local_time <= 200 {
-                if self.local_time - order.local_time <= 200 {
+                if order.price <= long_upper && order.price >= long_lower {
+                // if self.local_time - order.local_time <= 200 {
                     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) || self.local_time - order.local_time <= 200 {
-                if self.local_time - order.local_time <= 200 {
+                if order.price >= short_lower && order.price <= short_upper {
+                // if self.local_time - order.local_time <= 200 {
                     continue
                 }
                 // debug!(?key, ?order.price, ?short_lower, ?short_upper);