فهرست منبع

封装获取测试账号方法,添加测试账号配置

gepangpang 2 سال پیش
والد
کامیت
09125bdd33
6فایلهای تغییر یافته به همراه65 افزوده شده و 58 حذف شده
  1. 2 1
      .gitignore
  2. 59 0
      global/src/account_info.rs
  3. 1 0
      global/src/lib.rs
  4. 2 1
      standard/.gitignore
  5. 1 56
      standard/tests/exchange_test.rs
  6. 0 0
      test_account.toml.sample

+ 2 - 1
.gitignore

@@ -5,4 +5,5 @@ Cargo.lock
 config.toml*
 *.log
 *.log.*
-/logs*
+/logs*
+/test_account.toml

+ 59 - 0
global/src/account_info.rs

@@ -0,0 +1,59 @@
+use std::fs::File;
+use std::io::Read;
+use serde_derive::Deserialize;
+use toml::from_str;
+use tracing::{error};
+
+#[derive(Debug, Deserialize, Clone)]
+pub struct AccountInfo {
+    pub gate_access_key: String,
+    pub gate_secret_key: String,
+    pub binance_access_key: String,
+    pub binance_secret_key: String,
+    pub kucoin_access_key: String,
+    pub kucoin_secret_key: String,
+    pub kucoin_pass: String,
+    pub okx_access_key: String,
+    pub okx_secret_key: String,
+    pub okx_pass: String,
+    pub bitget_access_key: String,
+    pub bitget_secret_key: String,
+    pub bitget_pass: String,
+}
+
+impl AccountInfo {
+    pub fn new() -> AccountInfo {
+        AccountInfo {
+            gate_access_key: "".to_string(),
+            gate_secret_key: "".to_string(),
+            binance_access_key: "".to_string(),
+            binance_secret_key: "".to_string(),
+            kucoin_access_key: "".to_string(),
+            kucoin_secret_key: "".to_string(),
+            kucoin_pass: "".to_string(),
+            okx_access_key: "".to_string(),
+            okx_secret_key: "".to_string(),
+            okx_pass: "".to_string(),
+            bitget_access_key: "".to_string(),
+            bitget_secret_key: "".to_string(),
+            bitget_pass: "".to_string(),
+        }
+    }
+}
+
+// 获取文件内容
+pub fn get_account_info(file_path: &str) -> AccountInfo {
+    let file = File::open(file_path);
+    let mut contents = String::new();
+    let result = match file {
+        Ok(mut value) => {
+            value.read_to_string(&mut contents).unwrap_or_default();
+            from_str(&contents).unwrap_or(AccountInfo::new())
+        }
+        Err(_) => {
+            error!("没有获取到账号配置文件!");
+            AccountInfo::new()
+        }
+    };
+    result
+}

+ 1 - 0
global/src/lib.rs

@@ -3,3 +3,4 @@ pub mod log_utils;
 pub mod params;
 pub mod trace_stack;
 pub mod export_utils;
+pub mod account_info;

+ 2 - 1
standard/.gitignore

@@ -1,4 +1,5 @@
 /target
 /.idea
 /logs*
-/config.toml
+
+/Cargo.lock

+ 1 - 56
standard/tests/exchange_test.rs

@@ -24,61 +24,6 @@ use standard::exchange::{Exchange, ExchangeEnum};
 use standard::{kucoin_spot_handle, Order, Platform, utils};
 // use standard::{bitget_spot_handle, Order, Platform, utils};
 
-#[derive(Debug, Deserialize, Clone)]
-pub struct AccountInfo {
-    pub gate_access_key: String,
-    pub gate_secret_key: String,
-    pub binance_access_key: String,
-    pub binance_secret_key: String,
-    pub kucoin_access_key: String,
-    pub kucoin_secret_key: String,
-    pub kucoin_pass: String,
-    pub okx_access_key: String,
-    pub okx_secret_key: String,
-    pub okx_pass: String,
-    pub bitget_access_key: String,
-    pub bitget_secret_key: String,
-    pub bitget_pass: String,
-}
-
-impl AccountInfo {
-    pub fn new() -> AccountInfo {
-        AccountInfo {
-            gate_access_key: "".to_string(),
-            gate_secret_key: "".to_string(),
-            binance_access_key: "".to_string(),
-            binance_secret_key: "".to_string(),
-            kucoin_access_key: "".to_string(),
-            kucoin_secret_key: "".to_string(),
-            kucoin_pass: "".to_string(),
-            okx_access_key: "".to_string(),
-            okx_secret_key: "".to_string(),
-            okx_pass: "".to_string(),
-            bitget_access_key: "".to_string(),
-            bitget_secret_key: "".to_string(),
-            bitget_pass: "".to_string(),
-        }
-    }
-}
-
-// 获取文件内容
-pub fn get_account_info(file_path: &str) -> AccountInfo {
-    let file = File::open(file_path);
-    let mut contents = String::new();
-    let result = match file {
-        Ok(mut value) => {
-            value.read_to_string(&mut contents).unwrap_or_default();
-            from_str(&contents).unwrap_or(AccountInfo::new())
-        }
-        Err(_) => {
-            trace!("没有获取到账号配置文件!");
-            AccountInfo::new()
-        }
-    };
-    result
-}
-
-
 // 创建实体
 #[allow(dead_code)]
 pub async fn test_new_exchange(exchange: ExchangeEnum, symbol: &str) -> Box<dyn Platform> {
@@ -86,7 +31,7 @@ pub async fn test_new_exchange(exchange: ExchangeEnum, symbol: &str) -> Box<dyn
     let (order_sender, _order_receiver): (Sender<Order>, Receiver<Order>) = channel(1024);
     let (error_sender, _error_receiver): (Sender<Error>, Receiver<Error>) = channel(1024);
 
-    let account_info = get_account_info("config.toml");
+    let account_info = global::account_info::get_account_info("../test_account.toml");
     match exchange {
         ExchangeEnum::BinanceSwap => {
             let mut params: BTreeMap<String, String> = BTreeMap::new();

+ 0 - 0
standard/config.toml.sample → test_account.toml.sample