浏览代码

修改gate handle_book_ticker空字符报错

gepangpang 1 年之前
父节点
当前提交
960b1f1eb9
共有 2 个文件被更改,包括 4 次插入4 次删除
  1. 1 1
      standard/Cargo.toml
  2. 3 3
      standard/src/gate_swap_handle.rs

+ 1 - 1
standard/Cargo.toml

@@ -12,7 +12,7 @@ tokio = { version = "1.31.0", features = ["full"] }
 async-trait = "0.1.73"
 serde = { version = "1.0", features = ["derive"] }
 serde_json = "1.0.104"
-rust_decimal = "1.32.0"
+rust_decimal = { version = "1.32.0", features = ["maths"] }
 rust_decimal_macros = "1.32.0"
 chrono = "0.4.30"
 futures = "0.3"

+ 3 - 3
standard/src/gate_swap_handle.rs

@@ -1,5 +1,5 @@
 use std::str::FromStr;
-use rust_decimal::Decimal;
+use rust_decimal::{Decimal, Error};
 use rust_decimal::prelude::FromPrimitive;
 use rust_decimal_macros::dec;
 use serde_json::Value;
@@ -121,9 +121,9 @@ pub fn format_order_item(order: serde_json::Value, ct_val: Decimal) -> Order {
 }
 // 处理特殊Ticket信息
 pub fn handle_book_ticker(res_data: &ResponseData) -> SpecialDepth {
-    let bp = Decimal::from_str((*res_data).data["b"].as_str().unwrap_or("0")).unwrap();
+    let bp = Decimal::from_str((*res_data).data["b"].as_str().unwrap_or("0")).unwrap_or(Decimal::ZERO);
     let bq = Decimal::from_f64((*res_data).data["B"].as_f64().unwrap()).unwrap();
-    let ap = Decimal::from_str((*res_data).data["a"].as_str().unwrap_or("0")).unwrap();
+    let ap = Decimal::from_str((*res_data).data["a"].as_str().unwrap_or("0")).unwrap_or(Decimal::ZERO);
     let aq = Decimal::from_f64((*res_data).data["A"].as_f64().unwrap()).unwrap();
     let mp = (bp + ap) * dec!(0.5);
     let t = Decimal::from_u64((*res_data).data["u"].as_u64().unwrap()).unwrap();