Przeglądaj źródła

Merge branch 'dev' into test

skyfffire 1 rok temu
rodzic
commit
f3ecd1c46d

+ 4 - 0
global/src/trace_stack.rs

@@ -121,6 +121,10 @@ impl fmt::Display for TraceStack {
             msg.push_str(format!("发送订单耗时(发送-服务器处理-响应到本地){}毫秒  ", (self.after_send - self.before_send).to_f64().unwrap() / 1000.0).as_str());
         }
 
+        if self.after_network != 0 && self.before_send != 0 {
+            msg.push_str(format!("本地总耗时{}微秒  ", self.before_send - self.after_network).as_str());
+        }
+
         if self.after_send != 0 && self.after_network != 0 {
             msg.push_str(format!("总共耗时{}毫秒", (self.after_send - self.after_network).to_f64().unwrap() / 1000.0).as_str());
         }

+ 1 - 1
strategy/src/binance_spot.rs

@@ -96,7 +96,7 @@ async fn on_data(bot_arc_clone: Arc<Mutex<Quant>>,
                  min_sell: &mut Decimal,
                  data: ResponseData) {
     let mut trace_stack = TraceStack::default();
-    trace_stack.on_after_network(data.time);
+    trace_stack.on_after_network(chrono::Utc::now().timestamp_micros());
     trace_stack.on_before_quant();
 
     if data.code != "200".to_string() {

+ 1 - 1
strategy/src/binance_usdt_swap.rs

@@ -59,7 +59,7 @@ async fn on_data(bot_arc_clone: Arc<Mutex<Quant>>,
                  _min_sell: &mut Decimal,
                  data: ResponseData) {
     let mut trace_stack = TraceStack::default();
-    trace_stack.on_after_network(data.time);
+    trace_stack.on_after_network(chrono::Utc::now().timestamp_micros());
     trace_stack.on_before_quant();
 
     if data.code != "200".to_string() {

+ 2 - 2
strategy/src/bitget_spot.rs

@@ -130,7 +130,7 @@ pub async fn bitget_spot_run(bool_v1 :Arc<AtomicBool>,
 async fn on_private_data(bot_arc_clone: Arc<Mutex<Quant>>, ct_val: Decimal, data: ResponseData) {
     let mut trace_stack = TraceStack::default();
 
-    trace_stack.on_after_network(data.time);
+    trace_stack.on_after_network(chrono::Utc::now().timestamp_micros());
     trace_stack.on_before_quant();
 
     if data.code != "200".to_string() {
@@ -179,7 +179,7 @@ async fn on_private_data(bot_arc_clone: Arc<Mutex<Quant>>, ct_val: Decimal, data
 async fn on_public_data(bot_arc_clone: Arc<Mutex<Quant>>, update_flag_u: &mut Decimal, max_buy: &mut Decimal, min_sell: &mut Decimal, data: ResponseData) {
     let mut trace_stack = TraceStack::default();
 
-    trace_stack.on_after_network(data.time);
+    trace_stack.on_after_network(chrono::Utc::now().timestamp_micros());
     trace_stack.on_before_quant();
 
     if data.code != "200".to_string() {

+ 1 - 1
strategy/src/gate_swap.rs

@@ -101,7 +101,7 @@ async fn on_data(bot_arc_clone: Arc<Mutex<Quant>>,
                  min_sell: &mut Decimal,
                  data: ResponseData) {
     let mut trace_stack = TraceStack::default();
-    trace_stack.on_after_network(data.time);
+    trace_stack.on_after_network(chrono::Utc::now().timestamp_micros());
     trace_stack.on_before_quant();
 
     if data.code != "200".to_string() {

+ 1 - 1
strategy/src/kucoin_spot.rs

@@ -77,7 +77,7 @@ async fn on_kucoin_spot_data(bot_arc_clone: Arc<Mutex<Quant>>,
                              min_sell: &mut Decimal,
                              data: ResponseData) {
     let mut trace_stack = TraceStack::default();
-    trace_stack.on_after_network(data.time);
+    trace_stack.on_after_network(chrono::Utc::now().timestamp_micros());
     trace_stack.on_before_quant();
 
     if data.code != "200".to_string() {

+ 1 - 1
strategy/src/kucoin_swap.rs

@@ -116,7 +116,7 @@ async fn on_data(bot_arc_clone: Arc<Mutex<Quant>>,
                  min_sell: &mut Decimal,
                  data: ResponseData) {
     let mut trace_stack = TraceStack::default();
-    trace_stack.on_after_network(data.time);
+    trace_stack.on_after_network(chrono::Utc::now().timestamp_micros());
     trace_stack.on_before_quant();
 
     if data.code != "200".to_string() {

+ 2 - 2
strategy/src/okx_usdt_swap.rs

@@ -109,7 +109,7 @@ pub async fn okex_swap_run(bool_v1: Arc<AtomicBool>,
 async fn on_private_data(bot_arc_clone: Arc<Mutex<Quant>>, ct_val: Decimal, data: ResponseData, run_symbol: String) {
     let mut trace_stack = TraceStack::default();
 
-    trace_stack.on_after_network(data.time);
+    trace_stack.on_after_network(chrono::Utc::now().timestamp_micros());
     trace_stack.on_before_quant();
 
     if data.code != "200".to_string() {
@@ -162,7 +162,7 @@ async fn on_private_data(bot_arc_clone: Arc<Mutex<Quant>>, ct_val: Decimal, data
 
 async fn on_public_data(bot_arc_clone: Arc<Mutex<Quant>>, update_flag_u: &mut Decimal, max_buy: &mut Decimal, min_sell: &mut Decimal, data: ResponseData) {
     let mut trace_stack = TraceStack::default();
-    trace_stack.on_after_network(data.time);
+    trace_stack.on_after_network(chrono::Utc::now().timestamp_micros());
     trace_stack.on_before_quant();
 
     if data.code != "200".to_string() {

+ 4 - 4
strategy/src/quant.rs

@@ -231,10 +231,10 @@ impl Quant {
             log_ready_log_interval: 10 * 1000,
             side: "normal".to_string(),
             trades: vec![],
-            recall_time: dec!(1680),
-            recall_max_count: 1680.to_usize().unwrap(),
-            short_volume_rate: dec!(0.8),
-            long_volume_rate: dec!(0.8),
+            recall_time: dec!(6180),
+            recall_max_count: 5000.to_usize().unwrap(),
+            short_volume_rate: dec!(0.618),
+            long_volume_rate: dec!(0.618),
         };
         for i in 0..=params.ref_exchange.len() - 1 {
             // 拼接不会消耗原字符串

+ 12 - 7
strategy/src/strategy.rs

@@ -593,12 +593,17 @@ impl Strategy {
 
             // 判断是否在本地挂单表中
             if let Some(order) = order_some {
-                let is_side_equals = (order.side == "kk" && self.side == "short") || (order.side == "kd" && self.side == "long");
+                let is_side_error = (order.side == "kk" && self.side == "long") || (order.side == "kd" && self.side == "short");
 
-                // 如果订单创建时间大于100ms,或有相反方向订单,才能有撤单操作
-                if is_side_equals || self.local_time - order.create_time < 100 {
+                // 如果订单创建时间大于100ms,才能有撤单操作
+                if  self.local_time - order.create_time < 100 {
                     need_limit_cancel = false;
                 }
+
+                // 如果方向有误,直接撤单
+                if is_side_error {
+                    need_limit_cancel = true;
+                }
             }
 
             if need_limit_cancel {
@@ -1008,7 +1013,7 @@ impl Strategy {
             // 开多订单处理
             if order.side == "kd".to_string() {
                 // 在价格范围内时不处理
-                if order.price <= long_upper && order.price >= long_lower && self.side == "long".to_string() {
+                if order.price <= long_upper && order.price >= long_lower && self.side != "short".to_string() {
                     continue
                 }
                 // debug!(?key, ?order.price, ?long_upper, ?long_lower);
@@ -1018,7 +1023,7 @@ impl Strategy {
             // 开空订单处理
             if order.side == "kk".to_string() {
                 // 在价格范围内时不处理
-                if order.price >= short_lower && order.price <= short_upper && self.side == "short".to_string() {
+                if order.price >= short_lower && order.price <= short_upper && self.side != "long".to_string() {
                     continue
                 }
                 // debug!(?key, ?order.price, ?short_lower, ?short_upper);
@@ -1128,7 +1133,7 @@ impl Strategy {
 
         // debug!(?self.post_side);
         // 挂多单
-        if self.post_side >= 0 && self.side == "long".to_string() {
+        if self.post_side >= 0 && self.side != "short".to_string() {
             // debug!(?buy_price_list);
             if buy_price_list.len() == 0 {
                 let mut target_buy_price = (long_upper + long_lower) * dec!(0.5);
@@ -1155,7 +1160,7 @@ impl Strategy {
             }
         }
         // 挂空单
-        if self.post_side <= 0 && self.side == "short".to_string() {
+        if self.post_side <= 0 && self.side != "long".to_string() {
             // debug!(?sell_price_list);
             if sell_price_list.len() == 0 {
                 let mut target_sell_price = (short_lower + short_upper) * dec!(0.5);