Selaa lähdekoodia

启动参数优化

hl 1 vuosi sitten
vanhempi
commit
8d04e71aed

+ 29 - 2
exchanges/src/gate_swap_rest.rs

@@ -11,7 +11,7 @@ use serde_json::Value;
 use crate::http_tool::RestTool;
 use crate::response_base::ResponseData;
 use sha2::Sha512;
-use tracing::{error, info};
+use tracing::{error, info, trace};
 
 #[derive(Clone)]
 pub struct GateSwapRest {
@@ -403,6 +403,32 @@ impl GateSwapRest {
     }
 
 
+    //查询合约账户变更历史
+    pub async fn get_account_detali(&mut self) -> ResponseData {
+        let params = serde_json::json!({
+        });
+        let data = self.request("GET".to_string(),
+                                "/api/v4".to_string(),
+                                format!("/options/accounts"),
+                                true,
+                                params.to_string(),
+        ).await;
+        data
+    }
+
+    //查询主账号下-子账户列表
+    pub async fn get_sub_accounts(&mut self) -> ResponseData {
+        let params = serde_json::json!({
+        });
+        let data = self.request("GET".to_string(),
+                                "/api/v4".to_string(),
+                                format!("/sub_accounts"),
+                                true,
+                                params.to_string(),
+        ).await;
+        data
+    }
+
     /*******************************************************************************************************/
     /*****************************************工具函数********************************************************/
     /*******************************************************************************************************/
@@ -573,11 +599,12 @@ impl GateSwapRest {
         let response = request_builder.send().await.unwrap();
         let is_success = response.status().is_success(); // 先检查状态码
         let text = response.text().await.unwrap();
+        trace!("text:{}",text.clone());
         return if is_success {
             self.on_success_data(&text)
         } else {
             self.on_error_data(&text, &addrs_url, &params)
-        }
+        };
     }
 
     pub fn on_success_data(&mut self, text: &String) -> ResponseData {

+ 2 - 2
global/src/clear_position_result.rs

@@ -2,7 +2,7 @@ use serde_derive::{Deserialize, Serialize};
 
 #[derive(Debug, Serialize, Deserialize, Clone)]
 pub struct ClearPositionResult {
-    pub check_id: String,
+    pub r_id: String,
     pub clear_order_num: String,
     pub clear_order_str: String,
     pub clear_position_num: String,
@@ -14,7 +14,7 @@ pub struct ClearPositionResult {
 impl ClearPositionResult {
     pub fn new() -> ClearPositionResult {
         ClearPositionResult{
-            check_id: "".to_string(),
+            r_id: "".to_string(),
             clear_order_num: "0".to_string(),
             clear_order_str: "".to_string(),
             clear_position_num: "0".to_string(),

+ 2 - 2
global/src/params.rs

@@ -53,7 +53,7 @@ pub struct Params {
     // 运行模式 0.正常策略运行, 1.清理挂单及仓位
     pub run_mode: i8,
     // 机器人id
-    pub check_id: String,
+    pub r_id: String,
 }
 
 impl Params {
@@ -101,7 +101,7 @@ impl Params {
             log_level: "info".to_string(),
             port: call_port,
             run_mode: 0,
-            check_id: "-1".to_string()
+            r_id: "-1".to_string()
         };
         Ok(params)
     }

+ 6 - 6
src/main.rs

@@ -47,7 +47,7 @@ fn read_params_json() -> Params {
     let mut call_port = 5555;
     // 运行模式 0.正常策略运行, 1.清理挂单及仓位
     let mut run_mode = 0;
-    let mut check_id = "-1".to_string();
+    let mut r_id = "-1".to_string();
 
     let args: Vec<String> = std::env::args().collect();
 
@@ -83,10 +83,10 @@ fn read_params_json() -> Params {
         }
 
         //上报ID
-        if arg.starts_with("--check_id=") {
+        if arg.starts_with("--r_id=") {
             let parts: Vec<&str> = arg.split('=').collect();
             if parts.len() == 2 {
-                check_id = parts[1].to_string();
+                r_id = parts[1].to_string();
             } else {
                 error!("启动失败,回执单id参数格式设置错误 --check_id=xxx!");
                 panic!("启动失败,回执单id参数格式设置错误 --check_id=xxx!");
@@ -98,12 +98,12 @@ fn read_params_json() -> Params {
     let mut params = Params::new_json(path, call_port).unwrap();
     if run_mode == 1 {
         params.run_mode = 1;
-        if check_id == "-1" {
+        if r_id == "-1" {
             error!("启动失败,缺少机器人id参数!");
             panic!("启动失败,缺少机器人id参数!");
         }
     }
-    params.check_id = check_id;
+    params.r_id = r_id;
     return params;
 }
 
@@ -147,7 +147,7 @@ async fn main() {
         // core初始化动作
         let mut core_arc = clear_core_libs::init(params.clone(), ws_running.clone(), running.clone(), cci_arc.clone()).await;
         info!("开始执行清仓程序");
-        core_arc.exit(params.check_id).await;
+        core_arc.exit(params.r_id).await;
         info!("清仓程序执行完毕");
         // 强制退出
         std::process::exit(0);

+ 2 - 2
strategy/src/clear_core.rs

@@ -531,13 +531,13 @@ impl ClearCore {
 
 
     // #[instrument(skip(self), level="TRACE")]
-    pub async fn exit(&mut self, check_id: String) -> bool {
+    pub async fn exit(&mut self, r_id: String) -> bool {
         info!("-------------------------启动退出流程({})----------------------------", self.exit_msg);
         info!("");
 
         let mut result = self.check_position().await;
         // 设置机器人id
-        result.check_id = check_id;
+        result.r_id = r_id;
         info!("清仓程序结果 {:?}", result);
         // 判断是否有清仓,是否有异常
         if result.clear_position_num != "0" || result.clear_order_num != "0" || result.clear_other_err{