Эх сурвалжийг харах

支持trade的id写入。

skyffire 1 жил өмнө
parent
commit
e4844f7975

+ 3 - 2
src/listener_tools.rs

@@ -1,3 +1,4 @@
+use std::str::FromStr;
 use rust_decimal::prelude::ToPrimitive;
 use tokio::sync::MutexGuard;
 use tracing::info;
@@ -9,8 +10,8 @@ pub async fn update_trade(new_trade: &Trade, mut trades_map: MutexGuard<'_, Trad
     if let Some(trades) = trades_map.get_mut(new_trade.symbol.as_str()) {
         if let Some(last_trade) = trades.last() {
             // 这里的last_trade.0是以元组形式进行访问。
-            let last_trade_minutes = last_trade.inner()[0].to_i64().unwrap() / 60000; // 将毫秒转换成分钟数
-            let new_trade_minutes = new_trade.time.to_i64().unwrap() / 60000; // 同上
+            let last_trade_minutes = i64::from_str(last_trade.inner()[1].as_str()).unwrap() / 60000;    // 将毫秒转换成分钟数
+            let new_trade_minutes = new_trade.time.to_i64().unwrap() / 60000;                           // 同上
 
             // 如果分钟数不同,则清空列表并添加新的depth
             if last_trade_minutes != new_trade_minutes {

+ 1 - 0
standard/src/gate_swap_handle.rs

@@ -154,6 +154,7 @@ pub fn format_trade_items(res_data: &ResponseData) -> Vec<Trade> {
 
     for item in result {
         trades.push(Trade {
+            id: item["id"].to_string(),
             time: Decimal::from_i64(item["create_time_ms"].as_i64().unwrap()).unwrap(),
             size: Decimal::from_i64(item["size"].as_i64().unwrap()).unwrap(),
             price: Decimal::from_str(item["price"].as_str().unwrap().to_string().as_str()).unwrap(),

+ 7 - 5
standard/src/lib.rs

@@ -79,12 +79,14 @@ impl Account {
 }
 
 /// 交易结构体(订单流)
+/// - `id(String)`: id
 /// - `time(Decimal)`: 交易更新时间戳(ms)
 /// - `size(Decimal)`: 交易量,负数是卖方
 /// - `price(Decimal)`: 成交价格
 /// - `symbol(String)`: 成交符号
 #[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
 pub struct Trade {
+    pub id: String,
     pub time: Decimal,
     pub size: Decimal,
     pub price: Decimal,
@@ -96,25 +98,25 @@ pub struct Trade {
 /// - `1(Decimal)`: 交易量,负数是卖方
 /// - `2(Decimal)`: 成交价格
 #[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
-pub struct SpecialTrade(pub Vec<Decimal>);
+pub struct SpecialTrade(pub Vec<String>);
 impl SpecialTrade {
     // 获取内部 Vec<Decimal> 的引用
-    pub fn inner(&self) -> &Vec<Decimal> {
+    pub fn inner(&self) -> &Vec<String> {
         &self.0
     }
 
     // 获取内部 Vec<Decimal> 的可变引用
-    pub fn inner_mut(&mut self) -> &mut Vec<Decimal> {
+    pub fn inner_mut(&mut self) -> &mut Vec<String> {
         &mut self.0
     }
 
     // 索引访问特定元素
-    pub fn get(&self, index: usize) -> Option<&Decimal> {
+    pub fn get(&self, index: usize) -> Option<&String> {
         self.0.get(index)
     }
 
     pub fn new(trade: &Trade) -> SpecialTrade {
-        SpecialTrade(vec![trade.time, trade.size, trade.price])
+        SpecialTrade(vec![trade.id.clone(), trade.time.to_string(), trade.size.to_string(), trade.price.to_string()])
     }
 }