875428575@qq.com 2 жил өмнө
parent
commit
5d4a3e35e3

+ 9 - 2
Cargo.toml

@@ -15,7 +15,14 @@ serde_derive = "1.0.183"
 serde_json = "1.0.104"
 ndarray = "0.15"
 time = "0.2"
-tokio = {version = "1.31.0", features = ["full"]}
+tokio = { version = "1.31.0", features = ["full"] }
 
-tungstenite = {git="https://github.com/PrivateRookie/tungstenite-rs.git", rev="1d9289276518e5ab7e5194126d40b441d8938375"}
+tungstenite = { git = "https://github.com/PrivateRookie/tungstenite-rs.git", rev = "1d9289276518e5ab7e5194126d40b441d8938375" }
 url = "2.4.0"
+base64 = "0.13"
+rust-crypto = "0.2.36"
+
+hmac = "0.8.0"
+sha2 = "0.9"
+hex = "0.4"
+ring = "0.17.0-alpha.11"

+ 3 - 13
src/exchange_libs.rs

@@ -1,18 +1,9 @@
 use std::collections::{BTreeMap, HashMap};
 use std::env;
-use std::fs::metadata;
-use std::future::Future;
-use std::path::Component::Prefix;
-use std::time::{SystemTime, UNIX_EPOCH};
-use chrono::Utc;
 use reqwest;
 use reqwest::header::{HeaderMap, HeaderValue, USER_AGENT};
-use base64::{encode, decode};
-use sha2::Sha256;
 use hex;
-use reqwest::Error;
 use ring::hmac;
-use serde_json::Value;
 
 
 /*币安-k线条*/
@@ -225,9 +216,9 @@ impl OkxExc {
 //统一返回
 #[derive(Debug)]
 pub struct ReqData {
-    pub(crate) code: String,
-    pub(crate)  message: String,
-    pub(crate)  data: String,
+    pub code: String,
+    pub message: String,
+    pub data: String,
 }
 
 impl ReqData {
@@ -238,7 +229,6 @@ impl ReqData {
     pub fn error(message: String) -> ReqData {
         ReqData { code: "-1".to_string(), message: "请求失败:".to_string() + &message, data: "".to_string() }
     }
-
 }
 
 

+ 26 - 26
src/exchange_middle_ware.rs

@@ -8,48 +8,48 @@ use crate::exchange_libs;
 // 深度结构体
 #[derive(Debug)]
 pub struct Depth {
-    pub(crate) asks: Vec<DepthItem>,
-    pub(crate) bids: Vec<DepthItem>,
+    pub asks: Vec<DepthItem>,
+    pub bids: Vec<DepthItem>,
 }
 #[derive(Debug)]
 pub struct DepthItem {
-    pub(crate) price: f64,
-    pub(crate) amount: f64,
+    pub price: f64,
+    pub amount: f64,
 }
 
 // k线数据结构体
 #[derive(Debug)]
 pub struct Record {
-    pub(crate) time: i64,      // 时间
-    pub(crate) open: f64,      // 开盘价
-    pub(crate) high: f64,      // 最高价
-    pub(crate) low: f64,       // 最低价
-    pub(crate) close: f64,     // 收盘价
-    pub(crate) volume: f64,    // 交易量
+    pub time: i64,      // 时间
+    pub open: f64,      // 开盘价
+    pub high: f64,      // 最高价
+    pub low: f64,       // 最低价
+    pub close: f64,     // 收盘价
+    pub volume: f64,    // 交易量
 }
 
 // Account信息结构体
 pub struct Account{
-    pub(crate) balance: f64,           // 可用计价币数量
-    pub(crate) frozen_balance: f64,    // Balance挂单的冻结数量
-    pub(crate) stocks: f64,            // 可用交易币数量
-    pub(crate) frozen_stocks: f64,     // stocks挂单的冻结数量
+    pub balance: f64,           // 可用计价币数量
+    pub frozen_balance: f64,    // Balance挂单的冻结数量
+    pub stocks: f64,            // 可用交易币数量
+    pub frozen_stocks: f64,     // stocks挂单的冻结数量
 }
 
 // 币对市场信息结构体
 pub struct Market {
-    pub(crate) symbol: String,
-    pub(crate) base_asset: String,
-    pub(crate) quote_asset: String,
-    pub(crate) tick_size: f64,
-    pub(crate) amount_size: f64,       // 下单量最小变动数值
-    pub(crate) price_precision: f64,   // 价格精度,表示价格精确到2位小数
-    pub(crate) amount_precision: f64,  // 下单量精度,表示下单量精确到3位小数
-    pub(crate) min_qty: f64,           // 最小下单量
-    pub(crate) max_qty: f64,           // 最大下单量
-    pub(crate) min_notional: f64,      // 最小下单金额
-    pub(crate) max_notional: f64,      // 最大下单金额
-    pub(crate) ct_val: f64,            // 合约价值
+    pub symbol: String,
+    pub base_asset: String,
+    pub quote_asset: String,
+    pub tick_size: f64,
+    pub amount_size: f64,       // 下单量最小变动数值
+    pub price_precision: f64,   // 价格精度,表示价格精确到2位小数
+    pub amount_precision: f64,  // 下单量精度,表示下单量精确到3位小数
+    pub min_qty: f64,           // 最小下单量
+    pub max_qty: f64,           // 最大下单量
+    pub min_notional: f64,      // 最小下单金额
+    pub max_notional: f64,      // 最大下单金额
+    pub ct_val: f64,            // 合约价值
 }
 
 // 处理交易对格式