|
|
@@ -2,12 +2,11 @@ use tokio::time::Instant;
|
|
|
use std::collections::{BTreeMap, HashMap};
|
|
|
use std::io::Error;
|
|
|
use std::sync::Arc;
|
|
|
-use std::sync::atomic::{AtomicBool, Ordering};
|
|
|
+use std::sync::atomic::{AtomicBool};
|
|
|
use std::time::Duration;
|
|
|
use chrono::{Utc};
|
|
|
use reqwest::header::{CONTENT_TYPE, HeaderMap, HeaderValue};
|
|
|
use rust_decimal::Decimal;
|
|
|
-use rust_decimal::prelude::ToPrimitive;
|
|
|
use rust_decimal_macros::dec;
|
|
|
use tokio::sync::mpsc::{Sender};
|
|
|
use tokio::sync::{Mutex};
|
|
|
@@ -432,14 +431,12 @@ impl ClearCore {
|
|
|
let mut result = ClearPositionResult::new();
|
|
|
info!("------------------------------------------------------------------------------------------------------------");
|
|
|
info!("步骤一:检查挂单:");
|
|
|
- let mut is_order_clear = false;
|
|
|
match self.platform_rest.cancel_orders_all().await {
|
|
|
Ok(val) => {
|
|
|
let length = val.len();
|
|
|
- is_order_clear = length == 0;
|
|
|
result.clear_order_num = length.to_string();
|
|
|
info!("已清空所有挂单({}条)", length);
|
|
|
- result.clear_order_str = serde_json::to_string(&val).expect("Failed to serialize to JSON---- order");
|
|
|
+ result.clear_order_str = format!("清空所有挂单:{:?}", val);
|
|
|
for o in val {
|
|
|
info!(" {:?}", o);
|
|
|
}
|
|
|
@@ -449,9 +446,8 @@ impl ClearCore {
|
|
|
match self.platform_rest.cancel_orders().await {
|
|
|
Ok(val) => {
|
|
|
let length = val.len();
|
|
|
- is_order_clear = length == 0;
|
|
|
result.clear_order_num = length.to_string();
|
|
|
- result.clear_order_str = serde_json::to_string(&val).expect("Failed to serialize to JSON---- order");
|
|
|
+ result.clear_order_str = format!("清空所有挂单(备用):{:?}", val);
|
|
|
info!("清空所有挂单({}条):{:?}", length, val);
|
|
|
}
|
|
|
Err(exc) => {
|
|
|
@@ -543,11 +539,10 @@ impl ClearCore {
|
|
|
// 设置机器人id
|
|
|
result.robot_id = robot_id;
|
|
|
info!("清仓程序结果 {:?}", result);
|
|
|
- /**
|
|
|
- * todo: 判断是否有清仓,是否有异常
|
|
|
- **/
|
|
|
+ // 判断是否有清仓,是否有异常
|
|
|
if result.clear_position_num != "0" || result.clear_order_num != "0" || result.clear_other_err{
|
|
|
- send_clear_msg_request(&result).await;
|
|
|
+ info!("上报了清仓信息!!!")
|
|
|
+ // send_clear_msg_request(&result).await;
|
|
|
// 上报清仓日志
|
|
|
}
|
|
|
|
|
|
@@ -589,8 +584,6 @@ impl ClearCore {
|
|
|
// 初始化策略基础信息
|
|
|
if mp <= Decimal::ZERO {
|
|
|
self.exit_msg = format!("{}{}", "初始价格获取错误: ", mp);
|
|
|
- // 停止程序
|
|
|
- self.stop().await;
|
|
|
return false;
|
|
|
} else {
|
|
|
info!("初始价格为 {}", mp);
|
|
|
@@ -614,8 +607,6 @@ impl ClearCore {
|
|
|
}
|
|
|
if self.strategy.step_size.is_zero() || self.strategy.tick_size.is_zero() {
|
|
|
self.exit_msg = format!("{}{}{}{}", "交易精度未正常获取 step_size: ", self.strategy.step_size, " tick_size:", self.strategy.tick_size);
|
|
|
- // 停止程序
|
|
|
- self.stop().await;
|
|
|
return false;
|
|
|
} else {
|
|
|
info!("数量精度 {}", self.strategy.step_size);
|
|
|
@@ -655,12 +646,13 @@ pub async fn send_clear_msg_request(body_params: &ClearPositionResult) {
|
|
|
.await;
|
|
|
match res {
|
|
|
Ok(response) => {
|
|
|
+ let status = response.status();
|
|
|
let response_text = response.text().await.unwrap_or("获取请求的响应文本异常".to_string());
|
|
|
// 检查响应状态并读取响应体
|
|
|
- if response.status().is_success() {
|
|
|
+ if status.is_success() {
|
|
|
info!("清仓结果上报中控,请求成功,响应文本: {}", response_text);
|
|
|
} else {
|
|
|
- println!("清仓结果上报中控,请求失败: 响应异常码 {},响应文本 {}", response.status(), response_text);
|
|
|
+ println!("清仓结果上报中控,请求失败: 响应异常码 {},响应文本 {}", status, response_text);
|
|
|
}
|
|
|
},
|
|
|
Err(e) => {
|