浏览代码

定义接口部分方法
修改f64为Decimal
添加Ticker、Order、Market等结构体

gepangpang 2 年之前
父节点
当前提交
16649dedbf

+ 4 - 0
standard/Cargo.toml

@@ -8,3 +8,7 @@ edition = "2021"
 [dependencies]
 exchanges = { path = "../exchanges" }
 tokio = { version = "1.31.0", features = ["full"] }
+async-trait = "0.1.73"
+serde_json = "1.0.105"
+rust_decimal = "1.32.0"
+rust_decimal_macros = "1.32.0"

+ 47 - 19
standard/src/binance_spot.rs

@@ -1,9 +1,13 @@
 use std::collections::BTreeMap;
+use std::io::{Error, ErrorKind};
+use std::result::Result;
+use async_trait::async_trait;
+use rust_decimal_macros::dec;
 use crate::utils;
-use crate::{Platform, ExchangeEnum, Account, Depth, DepthItem};
+use crate::{Platform, ExchangeEnum, Account, Depth, MarketOrder};
 use exchanges::binance_spot_rest::BinanceSpotRest;
 use exchanges::binance_spot_ws::BinanceSpotWs;
-// use exchanges::response_base::ResponseData;
+use exchanges::response_base::ResponseData;
 
 #[allow(dead_code)]
 pub struct BinanceSpot {
@@ -27,7 +31,7 @@ impl BinanceSpot {
         }
     }
 }
-
+#[async_trait]
 impl Platform for BinanceSpot {
     // 获取交易所模式
     fn get_self_exchange(&self) -> ExchangeEnum {
@@ -46,21 +50,45 @@ impl Platform for BinanceSpot {
         self.params.clone()
     }
     // 获取现货账号信息
-    fn get_account(&self, symbol: &str) -> Account {
+    async fn get_account(&self, symbol: &str) -> Result<Account, Error> {
         let format_symbol = utils::format_symbol(symbol, "");
-        println!("spot_real_symbol: {}", format_symbol);
-        Account {
-            balance: 0.0,
-            frozen_balance: 0.0,
-            stocks: 0.0,
-            frozen_stocks: 0.0,
+        println!("format_symbol: {}",format_symbol);
+        // let res_data = self.request.get_account(&format_symbol).await;
+        let res_data = ResponseData{
+            code: "200".to_string(),
+            message: "你猜猜这是什么错误".to_string(),
+            data: "{}".to_string(),
+            channel: "".to_string(),
+        };
+        if res_data.code == "200" {
+            // let res_data_str = res_data.data;
+            // let res_data_json: Vec<serde_json::Value> = serde_json::from_str(&*res_data_str).unwrap();
+            // let symbol_array: Vec<&str> = symbol.split("_").collect();
+            // let details = res_data_json[0]["details"].as_array().unwrap();
+            // let default_info = json!({"availBal":"0","fixedBal":"0"});
+            // let stocks_info = details.iter().find(|item| item["ccy"].as_str().unwrap() == symbol_array[0].to_string()).unwrap_or(&default_info);
+            // let balance_info = details.iter().find(|item| item["ccy"].as_str().unwrap() == symbol_array[1].to_string()).unwrap_or(&default_info);
+            // let result = Account {
+            //     balance: balance_info["availBal"].as_str().unwrap().parse().unwrap_or(dec!(0.0)),
+            //     frozen_balance: balance_info["fixedBal"].as_str().unwrap().parse().unwrap_or(dec!(0.0)),
+            //     stocks: stocks_info["availBal"].as_str().unwrap().parse().unwrap_or(dec!(0.0)),
+            //     frozen_stocks: stocks_info["fixedBal"].as_str().unwrap().parse().unwrap_or(dec!(0.0)),
+            // };
+            let result = Account {
+                balance: dec!(0.0),
+                frozen_balance: dec!(0.0),
+                stocks: dec!(0.0),
+                frozen_stocks: dec!(0.0),
+            };
+            Ok(result)
+        } else {
+            Err(Error::new(ErrorKind::Other, res_data.message))
         }
     }
-
     // 获取深度信息
     fn get_depth(&self) -> Depth {
-        let depth_asks = vec![DepthItem { price: 1.0, amount: 0.0 }];
-        let depth_bids = vec![DepthItem { price: 0.0, amount: 0.0 }];
+        let depth_asks = vec![MarketOrder { price: dec!(0.0), amount: dec!(0.0) }];
+        let depth_bids = vec![MarketOrder { price: dec!(0.0), amount: dec!(0.0) }];
         Depth {
             time: 0,
             asks: depth_asks,
@@ -82,16 +110,16 @@ impl Platform for BinanceSpot {
 
     fn subscribe_account(&self) -> Account {
         Account {
-            balance: 0.0,
-            frozen_balance: 0.0,
-            stocks: 0.0,
-            frozen_stocks: 0.0,
+            balance: dec!(0.0),
+            frozen_balance: dec!(0.0),
+            stocks: dec!(0.0),
+            frozen_stocks: dec!(0.0),
         }
     }
 
     fn subscribe_depth(&self) -> Depth {
-        let depth_asks = vec![DepthItem { price: 1.0, amount: 0.0 }];
-        let depth_bids = vec![DepthItem { price: 0.0, amount: 0.0 }];
+        let depth_asks = vec![MarketOrder { price: dec!(0.0), amount: dec!(0.0) }];
+        let depth_bids = vec![MarketOrder { price: dec!(0.0), amount: dec!(0.0) }];
         Depth {
             time: 0,
             asks: depth_asks,

+ 41 - 16
standard/src/binance_swap.rs

@@ -1,6 +1,10 @@
 use std::collections::BTreeMap;
+use std::io::{Error, ErrorKind};
+use std::result::Result;
+use async_trait::async_trait;
+use rust_decimal_macros::dec;
 use crate::utils;
-use crate::{Platform, ExchangeEnum, Account, Depth, DepthItem};
+use crate::{Platform, ExchangeEnum, Account, Depth, MarketOrder};
 use exchanges::binance_usdt_swap_rest::BinanceUsdtSwapRest;
 use exchanges::binance_usdt_swap_ws::BinanceUsdtSwapWs;
 use exchanges::response_base::ResponseData;
@@ -28,6 +32,7 @@ impl BinanceSwap {
     }
 }
 
+#[async_trait]
 impl Platform for BinanceSwap {
     // 获取交易所模式
     fn get_self_exchange(&self) -> ExchangeEnum {
@@ -46,20 +51,40 @@ impl Platform for BinanceSwap {
         self.params.clone()
     }
     // 获取期货账号信息
-    fn get_account(&self, symbol: &str) -> Account {
+    async fn get_account(&self, symbol: &str) -> Result<Account, Error> {
         let format_symbol = utils::format_symbol(symbol, "");
-        println!("swap_real_symbol: {}", format_symbol);
-        Account {
-            balance: 0.0,
-            frozen_balance: 0.0,
-            stocks: 0.0,
-            frozen_stocks: 0.0,
+        println!("format_symbol: {}",format_symbol);
+        let res_data = self.request.get_account().await;
+        if res_data.code == "200" {
+            println!("{:?}",res_data);
+            // let res_data_str = res_data.data;
+            // let res_data_json: Vec<serde_json::Value> = serde_json::from_str(&*res_data_str).unwrap();
+            // let symbol_array: Vec<&str> = symbol.split("_").collect();
+            // let details = res_data_json[0]["details"].as_array().unwrap();
+            // let default_info = json!({"availBal":"0","fixedBal":"0"});
+            // let stocks_info = details.iter().find(|item| item["ccy"].as_str().unwrap() == symbol_array[0].to_string()).unwrap_or(&default_info);
+            // let balance_info = details.iter().find(|item| item["ccy"].as_str().unwrap() == symbol_array[1].to_string()).unwrap_or(&default_info);
+            // let result = Account {
+            //     balance: balance_info["availBal"].as_str().unwrap().parse().unwrap_or(0.0),
+            //     frozen_balance: balance_info["fixedBal"].as_str().unwrap().parse().unwrap_or(0.0),
+            //     stocks: stocks_info["availBal"].as_str().unwrap().parse().unwrap_or(0.0),
+            //     frozen_stocks: stocks_info["fixedBal"].as_str().unwrap().parse().unwrap_or(0.0),
+            // };
+            let result = Account {
+                balance: dec!(1.0),
+                frozen_balance: dec!(0.0),
+                stocks: dec!(0.0),
+                frozen_stocks: dec!(0.0),
+            };
+            Ok(result)
+        } else {
+            Err(Error::new(ErrorKind::Other, res_data.message))
         }
     }
     // 获取深度信息
     fn get_depth(&self) -> Depth {
-        let depth_asks = vec![DepthItem { price: 2.0, amount: 0.0 }];
-        let depth_bids = vec![DepthItem { price: 0.0, amount: 0.0 }];
+        let depth_asks = vec![MarketOrder { price: dec!(1.0), amount: dec!(0.0), }];
+        let depth_bids = vec![MarketOrder { price: dec!(0.0), amount: dec!(0.0), }];
         Depth {
             time: 0,
             asks: depth_asks,
@@ -82,16 +107,16 @@ impl Platform for BinanceSwap {
 
     fn subscribe_account(&self) -> Account {
         Account {
-            balance: 0.0,
-            frozen_balance: 0.0,
-            stocks: 0.0,
-            frozen_stocks: 0.0,
+            balance: dec!(0.0),
+            frozen_balance: dec!(0.0),
+            stocks: dec!(0.0),
+            frozen_stocks: dec!(0.0),
         }
     }
 
     fn subscribe_depth(&self) -> Depth {
-        let depth_asks = vec![DepthItem { price: 2.0, amount: 0.0 }];
-        let depth_bids = vec![DepthItem { price: 0.0, amount: 0.0 }];
+        let depth_asks = vec![MarketOrder { price: dec!(1.0), amount: dec!(0.0) }];
+        let depth_bids = vec![MarketOrder { price: dec!(0.0), amount: dec!(0.0) }];
         Depth {
             time: 0,
             asks: depth_asks,

+ 1 - 1
standard/src/exchange.rs

@@ -45,7 +45,7 @@ pub enum ExchangeEnum {
 /// params.insert("access_key".to_string(), "your_access_key".to_string());
 /// params.insert("access_key".to_string(), "your_secret_key".to_string());
 /// let exchange = Exchange::new(ExchangeEnum::BinanceSwap, true, true, params);
-pub struct Exchange {}
+pub struct Exchange;
 
 impl Exchange {
     pub fn new(exchange: ExchangeEnum, is_colo: bool, is_login: bool, params: BTreeMap<String, String>) -> Box<dyn Platform> {

+ 46 - 17
standard/src/gate_spot.rs

@@ -1,9 +1,12 @@
 use std::collections::BTreeMap;
+use std::io::{Error, ErrorKind};
+use async_trait::async_trait;
+use rust_decimal_macros::dec;
 use crate::utils;
-use crate::{Platform, ExchangeEnum, Account, Depth, DepthItem};
+use crate::{Platform, ExchangeEnum, Account, Depth, MarketOrder};
 use exchanges::gate_spot_rest::GateSpotRest;
 use exchanges::gate_spot_ws::GateSpotWs;
-// use exchanges::response_base::ResponseData;
+use exchanges::response_base::ResponseData;
 
 #[allow(dead_code)]
 pub struct GateSpot {
@@ -28,6 +31,7 @@ impl GateSpot {
     }
 }
 
+#[async_trait]
 impl Platform for GateSpot {
     // 获取交易所模式
     fn get_self_exchange(&self) -> ExchangeEnum {
@@ -46,20 +50,45 @@ impl Platform for GateSpot {
         self.params.clone()
     }
     // 获取现货账号信息
-    fn get_account(&self, symbol: &str) -> Account {
+    async fn get_account(&self, symbol: &str) -> Result<Account, Error> {
         let format_symbol = utils::format_symbol(symbol, "_");
-        println!("spot_real_symbol: {}", format_symbol);
-        Account {
-            balance: 0.0,
-            frozen_balance: 0.0,
-            stocks: 0.0,
-            frozen_stocks: 0.0,
+        println!("format_symbol: {}",format_symbol);
+        // let res_data = self.request.get_account(&format_symbol).await;
+        let res_data = ResponseData{
+            code: "200".to_string(),
+            message: "你猜猜这是什么错误".to_string(),
+            data: "".to_string(),
+            channel: "".to_string(),
+        };
+        if res_data.code == "200" {
+            // let res_data_str = res_data.data;
+            // let res_data_json: Vec<serde_json::Value> = serde_json::from_str(&*res_data_str).unwrap();
+            // let symbol_array: Vec<&str> = symbol.split("_").collect();
+            // let details = res_data_json[0]["details"].as_array().unwrap();
+            // let default_info = json!({"availBal":"0","fixedBal":"0"});
+            // let stocks_info = details.iter().find(|item| item["ccy"].as_str().unwrap() == symbol_array[0].to_string()).unwrap_or(&default_info);
+            // let balance_info = details.iter().find(|item| item["ccy"].as_str().unwrap() == symbol_array[1].to_string()).unwrap_or(&default_info);
+            // let result = Account {
+            //     balance: balance_info["availBal"].as_str().unwrap().parse().unwrap_or(dec!(0.0)),
+            //     frozen_balance: balance_info["fixedBal"].as_str().unwrap().parse().unwrap_or(dec!(0.0)),
+            //     stocks: stocks_info["availBal"].as_str().unwrap().parse().unwrap_or(dec!(0.0)),
+            //     frozen_stocks: stocks_info["fixedBal"].as_str().unwrap().parse().unwrap_or(dec!(0.0)),
+            // };
+            let result = Account {
+                balance: dec!(2.0),
+                frozen_balance: dec!(0.0),
+                stocks: dec!(0.0),
+                frozen_stocks: dec!(0.0),
+            };
+            Ok(result)
+        } else {
+            Err(Error::new(ErrorKind::Other, res_data.message))
         }
     }
     // 获取深度信息
     fn get_depth(&self) -> Depth {
-        let depth_asks = vec![DepthItem { price: 3.0, amount: 0.0 }];
-        let depth_bids = vec![DepthItem { price: 0.0, amount: 0.0 }];
+        let depth_asks = vec![MarketOrder { price: dec!(2.0), amount: dec!(0.0) }];
+        let depth_bids = vec![MarketOrder { price: dec!(0.0), amount: dec!(0.0) }];
         Depth {
             time: 0,
             asks: depth_asks,
@@ -82,16 +111,16 @@ impl Platform for GateSpot {
 
     fn subscribe_account(&self) -> Account {
         Account {
-            balance: 0.0,
-            frozen_balance: 0.0,
-            stocks: 0.0,
-            frozen_stocks: 0.0,
+            balance: dec!(0.0),
+            frozen_balance: dec!(0.0),
+            stocks: dec!(0.0),
+            frozen_stocks: dec!(0.0),
         }
     }
 
     fn subscribe_depth(&self) -> Depth {
-        let depth_asks = vec![DepthItem { price: 3.0, amount: 0.0 }];
-        let depth_bids = vec![DepthItem { price: 0.0, amount: 0.0 }];
+        let depth_asks = vec![MarketOrder { price: dec!(2.0), amount: dec!(0.0) }];
+        let depth_bids = vec![MarketOrder { price: dec!(0.0), amount: dec!(0.0) }];
         Depth {
             time: 0,
             asks: depth_asks,

+ 46 - 18
standard/src/gate_swap.rs

@@ -1,9 +1,12 @@
 use std::collections::BTreeMap;
+use std::io::{Error, ErrorKind};
+use async_trait::async_trait;
+use rust_decimal_macros::dec;
 use crate::utils;
-use crate::{Platform, ExchangeEnum, Account, Depth, DepthItem};
+use crate::{Platform, ExchangeEnum, Account, Depth, MarketOrder};
 use exchanges::gate_usdt_swap_rest::GateUsdtSwapRest;
 use exchanges::gate_usdt_swap_ws::GateUsdtSwapWs;
-// use exchanges::response_base::ResponseData;
+use exchanges::response_base::ResponseData;
 
 #[allow(dead_code)]
 pub struct GateSwap {
@@ -28,6 +31,7 @@ impl GateSwap {
     }
 }
 
+#[async_trait]
 impl Platform for GateSwap {
     // 获取交易所模式
     fn get_self_exchange(&self) -> ExchangeEnum {
@@ -46,20 +50,44 @@ impl Platform for GateSwap {
         self.params.clone()
     }
     // 获取期货账号信息
-    fn get_account(&self, symbol: &str) -> Account {
+    async fn get_account(&self, symbol: &str) -> Result<Account, Error> {
         let format_symbol = utils::format_symbol(symbol, "_");
-        println!("swap_real_symbol: {}", format_symbol);
-        Account {
-            balance: 0.0,
-            frozen_balance: 0.0,
-            stocks: 0.0,
-            frozen_stocks: 0.0,
+        println!("format_symbol: {}",format_symbol);
+        // let res_data = self.request.get_account(&format_symbol).await;
+        let res_data = ResponseData{
+            code: "200".to_string(),
+            message: "你猜猜这是什么错误".to_string(),
+            data: "".to_string(),
+            channel: "".to_string(),
+        };
+        if res_data.code == "200" {
+            // let res_data_str = res_data.data;
+            // let res_data_json: Vec<serde_json::Value> = serde_json::from_str(&*res_data_str).unwrap();
+            // let symbol_array: Vec<&str> = symbol.split("_").collect();
+            // let details = res_data_json[0]["details"].as_array().unwrap();
+            // let default_info = json!({"availBal":"0","fixedBal":"0"});
+            // let stocks_info = details.iter().find(|item| item["ccy"].as_str().unwrap() == symbol_array[0].to_string()).unwrap_or(&default_info);
+            // let balance_info = details.iter().find(|item| item["ccy"].as_str().unwrap() == symbol_array[1].to_string()).unwrap_or(&default_info);
+            // let result = Account {
+            //     balance: balance_info["availBal"].as_str().unwrap().parse().unwrap_or(dec!(0.0)),
+            //     frozen_balance: balance_info["fixedBal"].as_str().unwrap().parse().unwrap_or(dec!(0.0)),
+            //     stocks: stocks_info["availBal"].as_str().unwrap().parse().unwrap_or(dec!(0.0)),
+            //     frozen_stocks: stocks_info["fixedBal"].as_str().unwrap().parse().unwrap_or(dec!(0.0)),
+            // };
+            let result = Account {
+                balance: dec!(3.0),
+                frozen_balance: dec!(0.0),
+                stocks: dec!(0.0),
+                frozen_stocks: dec!(0.0),
+            };
+            Ok(result)
+        } else {
+            Err(Error::new(ErrorKind::Other, res_data.message))
         }
     }
-
     fn get_depth(&self) -> Depth {
-        let depth_asks = vec![DepthItem { price: 4.0, amount: 0.0 }];
-        let depth_bids = vec![DepthItem { price: 0.0, amount: 0.0 }];
+        let depth_asks = vec![MarketOrder { price: dec!(3.0), amount: dec!(0.0) }];
+        let depth_bids = vec![MarketOrder { price: dec!(0.0), amount: dec!(0.0) }];
         Depth {
             time: 0,
             asks: depth_asks,
@@ -81,16 +109,16 @@ impl Platform for GateSwap {
 
     fn subscribe_account(&self) -> Account {
         Account {
-            balance: 0.0,
-            frozen_balance: 0.0,
-            stocks: 0.0,
-            frozen_stocks: 0.0,
+            balance: dec!(0.0),
+            frozen_balance: dec!(0.0),
+            stocks: dec!(0.0),
+            frozen_stocks: dec!(0.0),
         }
     }
 
     fn subscribe_depth(&self) -> Depth {
-        let depth_asks = vec![DepthItem { price: 4.0, amount: 0.0 }];
-        let depth_bids = vec![DepthItem { price: 0.0, amount: 0.0 }];
+        let depth_asks = vec![MarketOrder { price: dec!(3.0), amount: dec!(0.0) }];
+        let depth_bids = vec![MarketOrder { price: dec!(0.0), amount: dec!(0.0) }];
         Depth {
             time: 0,
             asks: depth_asks,

+ 144 - 35
standard/src/lib.rs

@@ -1,4 +1,7 @@
 use std::collections::BTreeMap;
+use std::io::Error;
+use async_trait::async_trait;
+use rust_decimal::Decimal;
 use crate::exchange::ExchangeEnum;
 
 // 引入exchange模块
@@ -12,54 +15,122 @@ mod gate_spot;
 // 引入工具模块
 pub mod utils;
 
-/// Account结构体
-/// - `balance(f64)`: 可用计价币数量;
-/// - `frozen_balance(f64)`: balance挂单的冻结数量
-/// - `stocks(f64)`: 可用交易币数量
-/// - `frozen_stocks(f64)`: stocks挂单的冻结数量
+/// Account结构体(账户信息)
+/// - `balance(Decimal)`: 可用计价币数量;
+/// - `frozen_balance(Decimal)`: balance挂单的冻结数量
+/// - `stocks(Decimal)`: 可用交易币数量
+/// - `frozen_stocks(Decimal)`: stocks挂单的冻结数量
 #[derive(Debug)]
 pub struct Account {
-    pub balance: f64,
-    pub frozen_balance: f64,
-    pub stocks: f64,
-    pub frozen_stocks: f64,
+    pub balance: Decimal,
+    pub frozen_balance: Decimal,
+    pub stocks: Decimal,
+    pub frozen_stocks: Decimal,
 }
 
-/// Depth结构体
+/// Depth结构体(市场深度)
 /// - `time(i64)`: 深度更新时间戳(ms);
-/// - `asks(Vec<DepthItem>)`: 卖方深度列表;
-/// - `bids(Vec<DepthItem>)`: 买方深度列表;
+/// - `asks(Vec<MarketOrder>)`: 卖方深度列表;
+/// - `bids(Vec<MarketOrder>)`: 买方深度列表;
 #[derive(Debug)]
 pub struct Depth {
     pub time: i64,
-    pub asks: Vec<DepthItem>,
-    pub bids: Vec<DepthItem>,
+    pub asks: Vec<MarketOrder>,
+    pub bids: Vec<MarketOrder>,
 }
 
-/// DepthItem结构体
-/// - `price(f64)`: 价格
-/// - `amount(f64)`: 数量
+/// MarketOrder结构体(市场深度单)
+/// - `price(Decimal)`: 价格
+/// - `amount(Decimal)`: 数量
 #[derive(Debug)]
-pub struct DepthItem {
-    pub price: f64,
-    pub amount: f64,
+pub struct MarketOrder {
+    pub price: Decimal,
+    pub amount: Decimal,
 }
 
-/// Record结构体
+/// Record结构体(标准的OHLC结构)
 /// - `time(i64)`: 时间戳;
-/// - `open(f64)`: 开盘价;
-/// - `high(f64)`: 最高价;
-/// - `low(f64):` 最低价;
-/// - `close(f64)`: 收盘价;
-/// - `volume(f64)`: 交易量;
+/// - `open(Decimal)`: 开盘价;
+/// - `high(Decimal)`: 最高价;
+/// - `low(Decimal):` 最低价;
+/// - `close(Decimal)`: 收盘价;
+/// - `volume(Decimal)`: 交易量;
 #[derive(Debug)]
 pub struct Record {
     pub time: i64,
-    pub open: f64,
-    pub high: f64,
-    pub low: f64,
-    pub close: f64,
-    pub volume: f64,
+    pub open: Decimal,
+    pub high: Decimal,
+    pub low: Decimal,
+    pub close: Decimal,
+    pub volume: Decimal,
+}
+
+/// Order结构体(订单)
+/// - `id(String)`: 交易单唯一标识
+/// - `custom_id(String)`: 自定义Id
+/// - `price(Decimal)`: 下单价格
+/// - `amount(Decimal)`: 下单数量
+/// - `deal_amount(Decimal)`: 成交数量
+/// - `avg_price(Decimal)`: 成交均价
+/// - `status(String)`: 订单状态
+/// - `order_type(String)`: 订单类型
+#[derive(Debug)]
+pub struct Order {
+    pub id: String,
+    pub custom_id: String,
+    pub price: Decimal,
+    pub amount: Decimal,
+    pub deal_amount: Decimal,
+    pub avg_price: Decimal,
+    pub status: String,
+    pub order_type: String,
+}
+
+/// Ticker结构体(市场行情)
+/// - `time(i64)`: 毫秒级别时间戳
+/// - `high(Decimal)`: 最高价
+/// - `low(Decimal)`: 最低价
+/// - `sell(Decimal)`: 卖一价
+/// - `buy(Decimal)`: 买一价
+/// - `last(Decimal)`: 最后成交价
+/// - `volume(Decimal)`: 最近成交量
+pub struct Ticker {
+    pub time: i64,
+    pub high: Decimal,
+    pub low: Decimal,
+    pub sell: Decimal,
+    pub buy: Decimal,
+    pub last: Decimal,
+    pub volume: Decimal,
+}
+
+/// Market结构体(交易品种的市场信息)
+/// - `symbol(String)`: 交易对
+/// - `base_asset(String)`: 交易币
+/// - `quote_asset(String)`: 计价币
+/// - `tick_size(Decimal)`: 价格最小变动数值
+/// - `amount_size(Decimal)`: 下单量最小变动数值
+/// - `price_precision(Decimal)`: 价格精度
+/// - `amount_precision(Decimal)`: 下单量精度
+/// - `min_qty(Decimal)`: 最小下单量
+/// - `max_qty(Decimal)`: 最大下单量
+/// - `min_notional(Decimal)`: 最小下单金额
+/// - `max_notional(Decimal)`: 最大下单金额
+/// - `ct_val(Decimal)`: 合约价值
+#[derive(Debug)]
+pub struct Market {
+    pub symbol: String,
+    pub base_asset: String,
+    pub quote_asset: String,
+    pub tick_size: Decimal,
+    pub amount_size: Decimal,
+    pub price_precision: Decimal,
+    pub amount_precision: Decimal,
+    pub min_qty: Decimal,
+    pub max_qty: Decimal,
+    pub min_notional: Decimal,
+    pub max_notional: Decimal,
+    pub ct_val: Decimal,
 }
 
 /// 交易所统一方法接口
@@ -74,8 +145,44 @@ pub struct Record {
 /// params.insert("access_key".to_string(), "your_secret_key".to_string());
 /// let exchange = Exchange::new(ExchangeEnum::BinanceSwap, true, true, params);
 /// ```
+/// 获取当前交易所交易模式
+/// - fn get_self_exchange(&self) -> ExchangeEnum;
+/// ```rust
+/// # use std::collections::BTreeMap;
+/// # use standard::exchange::{Exchange, ExchangeEnum};
+/// # let mut params:BTreeMap<String,String> = BTreeMap::new();
+/// # params.insert("access_key".to_string(), "your_access_key".to_string());
+/// # params.insert("access_key".to_string(), "your_secret_key".to_string());
+/// # let exchange = Exchange::new(ExchangeEnum::BinanceSwap, true, true, params);
+///
+/// exchange.get_self_exchange();
+/// ```
+/// 获取当前是否使用高速模式
+/// - fn get_self_is_colo(&self) -> bool;
+/// ```rust
+/// # use std::collections::BTreeMap;
+/// # use standard::exchange::{Exchange, ExchangeEnum};
+/// # let mut params:BTreeMap<String,String> = BTreeMap::new();
+/// # params.insert("access_key".to_string(), "your_access_key".to_string());
+/// # params.insert("access_key".to_string(), "your_secret_key".to_string());
+/// # let exchange = Exchange::new(ExchangeEnum::BinanceSwap, true, true, params);
+///
+/// exchange.get_self_is_colo();
+/// ```
+/// 获取当前是否使用登录
+/// - fn get_self_is_login(&self) -> bool;
+/// ```rust
+/// # use std::collections::BTreeMap;
+/// # use standard::exchange::{Exchange, ExchangeEnum};
+/// # let mut params:BTreeMap<String,String> = BTreeMap::new();
+/// # params.insert("access_key".to_string(), "your_access_key".to_string());
+/// # params.insert("access_key".to_string(), "your_secret_key".to_string());
+/// # let exchange = Exchange::new(ExchangeEnum::BinanceSwap, true, true, params);
+///
+/// exchange.get_self_is_login();
+/// ```
 /// 获取登录params信息
-/// - fn get_params_info(&self) -> BTreeMap<String,String>;
+/// - fn get_self_params(&self) -> BTreeMap<String, String>;
 /// ```rust
 /// # use std::collections::BTreeMap;
 /// # use standard::exchange::{Exchange, ExchangeEnum};
@@ -84,9 +191,10 @@ pub struct Record {
 /// # params.insert("access_key".to_string(), "your_secret_key".to_string());
 /// # let exchange = Exchange::new(ExchangeEnum::BinanceSwap, true, true, params);
 ///
-/// exchange.get_params_info();
+/// exchange.get_self_params();
 /// ```
 /// 获取账号信息
+/// - async fn get_account(&self, symbol: &str) -> Result<Account, Error>;
 /// ```rust
 /// # use std::collections::BTreeMap;
 /// # use standard::exchange::{Exchange, ExchangeEnum};
@@ -95,7 +203,7 @@ pub struct Record {
 /// # params.insert("access_key".to_string(), "your_secret_key".to_string());
 /// # let exchange = Exchange::new(ExchangeEnum::BinanceSwap, true, true, params);
 ///
-/// exchange.get_account("BTC_USDT".to_string());
+/// exchange.get_account("BTC_USDT");
 /// ```
 /// 订阅账号信息
 /// ```rust
@@ -108,6 +216,7 @@ pub struct Record {
 ///
 /// exchange.subscribe_account();
 /// ```
+#[async_trait]
 pub trait Platform {
     // 获取当前交易所交易模式
     fn get_self_exchange(&self) -> ExchangeEnum;
@@ -118,7 +227,7 @@ pub trait Platform {
     // 获取登录params信息
     fn get_self_params(&self) -> BTreeMap<String, String>;
     // 获取账号信息
-    fn get_account(&self, symbol: &str) -> Account;
+    async fn get_account(&self, symbol: &str) -> Result<Account, Error>;
     // 获取深度信息
     fn get_depth(&self) -> Depth;
     // 下单接口

+ 12 - 8
standard/tests/libs_test.rs

@@ -1,15 +1,20 @@
 use std::collections::BTreeMap;
+use std::env;
 use standard::Platform;
 use standard::utils;
 use standard::exchange::{Exchange, ExchangeEnum};
 
+
+
 // 创建交易所实体方法
 fn test_new_exchange(exchange: ExchangeEnum) -> Box<dyn Platform> {
     match exchange {
         ExchangeEnum::BinanceSwap => {
             let mut params: BTreeMap<String, String> = BTreeMap::new();
-            params.insert("access_key".to_string(), "binance_swap_access_key".to_string());
-            params.insert("secret_key".to_string(), "binance_swap_secret_key".to_string());
+            let access_key = env::var("binance_access_key").unwrap().parse().unwrap_or("".to_string());
+            let secret_key = env::var("binance_secret_key").unwrap().parse().unwrap_or("".to_string());
+            params.insert("access_key".to_string(), access_key);
+            params.insert("secret_key".to_string(), secret_key);
             Exchange::new(exchange, false, false, params)
         }
         ExchangeEnum::BinanceSpot => {
@@ -33,7 +38,6 @@ fn test_new_exchange(exchange: ExchangeEnum) -> Box<dyn Platform> {
     }
 }
 
-
 // 测试获取Binance交易所期货实体
 #[tokio::test]
 async fn test_binance_swap_account() {
@@ -84,13 +88,13 @@ async fn test_replace_symbol() {
 #[tokio::test]
 async fn test_get_account() {
     let binance_swap_exchange: Box<dyn Platform> = test_new_exchange(ExchangeEnum::BinanceSwap);
-    println!("binance_swap account:{:?}", binance_swap_exchange.get_account("BTC_USDT"));
+    println!("binance_swap account:{:?}", binance_swap_exchange.get_account("BTC_USDT").await);
     let binance_spot_exchange: Box<dyn Platform> = test_new_exchange(ExchangeEnum::BinanceSpot);
-    println!("binance_spot account:{:?}", binance_spot_exchange.get_account("BTC_USDT"));
+    println!("binance_spot account:{:?}", binance_spot_exchange.get_account("BTC_USDT").await);
     let gate_swap_exchange: Box<dyn Platform> = test_new_exchange(ExchangeEnum::GateSwap);
-    println!("gate_swap account:{:?}", gate_swap_exchange.get_account("BTC_USDT"));
+    println!("gate_swap account:{:?}", gate_swap_exchange.get_account("BTC_USDT").await);
     let gate_spot_exchange: Box<dyn Platform> = test_new_exchange(ExchangeEnum::GateSpot);
-    println!("gate_spot account:{:?}", gate_spot_exchange.get_account("BTC_USDT"));
+    println!("gate_spot account:{:?}", gate_spot_exchange.get_account("BTC_USDT").await);
 }
 
 // 测试Binance期货K线推送
@@ -98,4 +102,4 @@ async fn test_get_account() {
 async fn test_subscribe_kline() {
     let binance_exchange: Box<dyn Platform> = test_new_exchange(ExchangeEnum::BinanceSwap);
     binance_exchange.subscribe_kline();
-}
+}