Browse Source

debug开仓委托逻辑

skyffire 8 months ago
parent
commit
c4f00d62b0
3 changed files with 20 additions and 6 deletions
  1. 10 4
      strategy/src/core.rs
  2. 2 2
      strategy/src/predictor.rs
  3. 8 0
      strategy/src/strategy.rs

+ 10 - 4
strategy/src/core.rs

@@ -42,7 +42,7 @@ pub struct Core {
     //
     pub strategy: Strategy,
     // 本地挂单时间表
-    pub local_order_times: HashMap<String, i64>,
+    pub local_order_infos: HashMap<String, Vec<String>>,
     // 本地挂单表
     pub local_orders: HashMap<String, OrderInfo>,
     // 本地订单缓存队列
@@ -137,7 +137,7 @@ impl Core {
             // 现货底仓
             hold_coin: clip(params.hold_coin, Decimal::ZERO, Decimal::ONE_HUNDRED * Decimal::ONE_HUNDRED),
             strategy: Strategy::new(&params, true),
-            local_order_times: Default::default(),
+            local_order_infos: Default::default(),
             local_orders: Default::default(),
             local_orders_backup: Default::default(),
             local_orders_backup_cid: Default::default(),
@@ -493,12 +493,18 @@ impl Core {
                         }
                         // info!("成交单耗时数据:{}", time_record.to_string());
                         info!("更新推算仓位 {:?}", self.local_position_by_orders);
-                        info!("当前时间-订单委托时间={}ms", Utc::now().timestamp_millis() - self.local_order_times.get(&data.client_id).unwrap());
+                        let place_time = self.local_order_infos.get(&data.client_id).unwrap()[4].parse::<i64>().unwrap();
+                        info!("当前时间-订单委托时间={}ms", Utc::now().timestamp_millis() - place_time);
                         if let Some(cancel_time) = self.local_cancel_time.get(&data.client_id) {
                             info!("当前时间-订单首次取消时间={}ms", Utc::now().timestamp_millis() - cancel_time)
                         } else {
                             info!("没有提交过取消订单")
                         }
+                        info!("委托时fp={}, mp={}, op={}",
+                            self.local_order_infos.get(&data.client_id).unwrap()[5],
+                            self.local_order_infos.get(&data.client_id).unwrap()[6],
+                            self.local_order_infos.get(&data.client_id).unwrap()[7]
+                        );
                         // 本地计算利润
                         self._print_local_trades_summary().await;
                         // 打印各类信息
@@ -827,7 +833,7 @@ impl Core {
                     fee: Default::default(),
                     trace_stack: TraceStack::new(0, Instant::now()),
                 };
-                self.local_order_times.insert(orders.limits_open.get(j).unwrap()[3].clone(), Utc::now().timestamp_millis());
+                self.local_order_infos.insert(orders.limits_open.get(j).unwrap()[3].clone(), orders.limits_open.get(j).unwrap().clone());
                 // 本地挂单表
                 self.local_orders.insert(orders.limits_open.get(j).unwrap()[3].clone(), order_info.clone());
                 // 本地缓存表

+ 2 - 2
strategy/src/predictor.rs

@@ -362,13 +362,13 @@ impl Predictor {
             self.optimal_bid_price = max(self.mid_price, self.fair_price);
             self.optimal_ask_price = Self::DONT_VIEW;
         } else if self.inventory.is_zero() {
-            if self.fair_price > self.mid_price * (Decimal::ONE + self.params.open / Decimal::TWO) {
+            if self.fair_price > self.mid_price {
                 self.bid_delta = dec!(0);
                 self.ask_delta = dec!(-2);
 
                 self.optimal_bid_price = self.fair_price - self.fair_price * self.params.open;
                 self.optimal_ask_price = Self::DONT_VIEW;
-            } else if self.fair_price < self.mid_price * (Decimal::ONE - self.params.open / Decimal::TWO) {
+            } else if self.fair_price < self.mid_price {
                 self.ask_delta = dec!(0);
                 self.bid_delta = dec!(-2);
 

+ 8 - 0
strategy/src/strategy.rs

@@ -1005,6 +1005,10 @@ impl Strategy {
                     "kd".to_string(),
                     target_buy_price.to_string(),
                     client_id.clone(),
+                    Utc::now().timestamp_millis().to_string(),
+                    predictor.fair_price.to_string(),
+                    predictor.mid_price.to_string(),
+                    predictor.optimal_ask_price.to_string(),
                 ];
 
                 // debug!(?order);
@@ -1037,6 +1041,10 @@ impl Strategy {
                     "kk".to_string(),
                     target_sell_price.to_string(),
                     client_id.clone(),
+                    Utc::now().timestamp_millis().to_string(),
+                    predictor.fair_price.to_string(),
+                    predictor.mid_price.to_string(),
+                    predictor.optimal_ask_price.to_string(),
                 ];
 
                 // debug!(?order);