|
|
@@ -1148,14 +1148,14 @@ impl Core {
|
|
|
|
|
|
// #[instrument(skip(self, target_hold_coin), level="TRACE")]
|
|
|
pub async fn check_position(&mut self, target_hold_coin: Decimal) -> bool {
|
|
|
- let mut is_clear = false;
|
|
|
|
|
|
info!("------------------------------------------------------------------------------------------------------------");
|
|
|
info!("步骤一:检查挂单:");
|
|
|
+ let mut is_order_clear = false;
|
|
|
match self.platform_rest.cancel_orders_all().await {
|
|
|
Ok(val) => {
|
|
|
let length = val.len();
|
|
|
- is_clear = length == 0;
|
|
|
+ is_order_clear = length == 0;
|
|
|
|
|
|
info!("已清空所有挂单({}条)", length);
|
|
|
|
|
|
@@ -1169,7 +1169,7 @@ impl Core {
|
|
|
match self.platform_rest.cancel_orders().await {
|
|
|
Ok(val) => {
|
|
|
let length = val.len();
|
|
|
- is_clear = length == 0;
|
|
|
+ is_order_clear = length == 0;
|
|
|
|
|
|
info!("清空所有挂单({}条):{:?}", length, val);
|
|
|
}
|
|
|
@@ -1183,17 +1183,18 @@ impl Core {
|
|
|
info!("");
|
|
|
|
|
|
info!("步骤二:检查仓位:");
|
|
|
+ let is_position_clear;
|
|
|
if self.exchange.contains("spot") { // 现货
|
|
|
- is_clear = is_clear && (self.check_position_spot(target_hold_coin.clone()).await == 0);
|
|
|
+ is_position_clear = self.check_position_spot(target_hold_coin.clone()).await == 0;
|
|
|
info!("检查遗漏仓位(现货),目标持仓:{}USDT", target_hold_coin);
|
|
|
} else { // 合约
|
|
|
- is_clear = is_clear && (self.check_position_swap().await == 0);
|
|
|
+ is_position_clear = self.check_position_swap().await == 0;
|
|
|
info!("遗漏仓位检查完毕(合约)!");
|
|
|
}
|
|
|
info!("------------------------------------------------------------------------------------------------------------");
|
|
|
info!("");
|
|
|
|
|
|
- return is_clear;
|
|
|
+ return is_order_clear && is_position_clear;
|
|
|
}
|
|
|
|
|
|
// #[instrument(skip(self, target_hold_coin), level="TRACE")]
|
|
|
@@ -1447,15 +1448,7 @@ impl Core {
|
|
|
info!("-------------------------启动退出流程----------------------------");
|
|
|
info!("");
|
|
|
|
|
|
- // 循环清空仓位,如若彻底清空,才进行退出。
|
|
|
- let mut clear_count = 1;
|
|
|
- while !self.check_position(Decimal::ZERO).await {
|
|
|
- sleep(Duration::from_secs(1)).await;
|
|
|
-
|
|
|
- clear_count += 1;
|
|
|
- info!("清理指令发送完毕,启动第{}次检查。", clear_count);
|
|
|
- info!("");
|
|
|
- }
|
|
|
+ self.clear_position_and_orders(Decimal::ZERO).await;
|
|
|
|
|
|
info!("订单、仓位清除完毕,为避免api失效导致遗漏仓位,建议人工复查。");
|
|
|
info!("停机原因:{}。", self.exit_msg);
|
|
|
@@ -1562,7 +1555,7 @@ impl Core {
|
|
|
}
|
|
|
|
|
|
// 清空挂单和仓位
|
|
|
- self.check_position(self.hold_coin).await;
|
|
|
+ self.clear_position_and_orders(self.hold_coin).await;
|
|
|
/*
|
|
|
###### 交易前准备就绪 可以开始交易 ######
|
|
|
self.loop.create_task(self.rest.go())
|
|
|
@@ -1573,6 +1566,17 @@ impl Core {
|
|
|
*/
|
|
|
return true;
|
|
|
}
|
|
|
+
|
|
|
+ pub async fn clear_position_and_orders(&mut self, target_hold_coin: Decimal) {
|
|
|
+ let mut clear_count = 1;
|
|
|
+ while !self.check_position(target_hold_coin).await {
|
|
|
+ sleep(Duration::from_secs(1)).await;
|
|
|
+
|
|
|
+ clear_count += 1;
|
|
|
+ info!("清理指令发送完毕,启动第{}次检查。", clear_count);
|
|
|
+ info!("");
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
// #[instrument(skip(core_arc), level="TRACE")]
|