Pārlūkot izejas kodu

修改所有返回为Number类型数据的转换

gepangpang 2 gadi atpakaļ
vecāks
revīzija
d70fd63cc4

+ 4 - 4
standard/src/binance_swap.rs

@@ -217,8 +217,8 @@ impl Platform for BinanceSwap {
                         quote_asset,
                         tick_size: Decimal::from_str(&price_filter["tickSize"].as_str().unwrap()).unwrap(),
                         amount_size: Decimal::from_str(lot_size_filter["stepSize"].as_str().unwrap()).unwrap(),
-                        price_precision: Decimal::from_str(&value["pricePrecision"].to_string()).unwrap(),
-                        amount_precision: Decimal::from_str(&value["quantityPrecision"].to_string()).unwrap(),
+                        price_precision: Decimal::from_str(&value["pricePrecision"].as_f64().unwrap().to_string()).unwrap(),
+                        amount_precision: Decimal::from_str(&value["quantityPrecision"].as_f64().unwrap().to_string()).unwrap(),
                         min_qty: Decimal::from_str(lot_size_filter["minQty"].as_str().unwrap()).unwrap(),
                         max_qty: Decimal::from_str(lot_size_filter["maxQty"].as_str().unwrap()).unwrap(),
                         min_notional: Decimal::from_str(price_filter["minPrice"].as_str().unwrap()).unwrap(),
@@ -260,8 +260,8 @@ impl Platform for BinanceSwap {
                         quote_asset,
                         tick_size: Decimal::from_str(&price_filter["tickSize"].as_str().unwrap()).unwrap(),
                         amount_size: Decimal::from_str(lot_size_filter["stepSize"].as_str().unwrap()).unwrap(),
-                        price_precision: Decimal::from_str(&value["pricePrecision"].to_string()).unwrap(),
-                        amount_precision: Decimal::from_str(&value["quantityPrecision"].to_string()).unwrap(),
+                        price_precision: Decimal::from_str(&value["pricePrecision"].as_f64().unwrap().to_string()).unwrap(),
+                        amount_precision: Decimal::from_str(&value["quantityPrecision"].as_f64().unwrap().to_string()).unwrap(),
                         min_qty: Decimal::from_str(lot_size_filter["minQty"].as_str().unwrap()).unwrap(),
                         max_qty: Decimal::from_str(lot_size_filter["maxQty"].as_str().unwrap()).unwrap(),
                         min_notional: Decimal::from_str(price_filter["minPrice"].as_str().unwrap()).unwrap(),

+ 11 - 11
standard/src/gate_handle.rs

@@ -24,7 +24,7 @@ pub fn format_account_info(data: Vec<serde_json::Value>, symbol: String) -> Acco
             panic!("Gate:格式化账号信息错误!\nformat_account_info: balance_info={:?}", balance_info)
         }
         Some(value) => {
-            let balance = Decimal::from_str(&value["balance"].to_string()).unwrap();
+            let balance = Decimal::from_str(&value["balance"].as_f64().unwrap().to_string()).unwrap();
             Account {
                 coin: symbol_array[1].to_string(),
                 balance,
@@ -55,7 +55,7 @@ pub fn format_position_item(position: &serde_json::Value, ct_val: Decimal) -> Po
             panic!("Gate:格式化持仓模式错误!\nformat_position_item:position_mode={:?}", position["mode"])
         }
     };
-    let size = Decimal::from_str(&position["size"].to_string()).unwrap();
+    let size = Decimal::from_str(&position["size"].as_f64().unwrap().to_string()).unwrap();
     let amount = size * ct_val;
     match position_mode {
         PositionModeEnum::Both => {
@@ -69,13 +69,13 @@ pub fn format_position_item(position: &serde_json::Value, ct_val: Decimal) -> Po
     }
     Position {
         symbol: position["contract"].as_str().unwrap().to_string(),
-        margin_level: Decimal::from_str(&position["leverage"].to_string()).unwrap(),
+        margin_level: Decimal::from_str(&position["leverage"].as_f64().unwrap().to_string()).unwrap(),
         amount,
         frozen_amount: Decimal::ZERO,
-        price: Decimal::from_str(&position["entry_price"].to_string()).unwrap(),
-        profit: Decimal::from_str(&position["realised_pnl"].to_string()).unwrap(),
+        price: Decimal::from_str(&position["entry_price"].as_f64().unwrap().to_string()).unwrap(),
+        profit: Decimal::from_str(&position["realised_pnl"].as_f64().unwrap().to_string()).unwrap(),
         position_mode,
-        margin: Decimal::from_str(&position["margin"].to_string()).unwrap(),
+        margin: Decimal::from_str(&position["margin"].as_f64().unwrap().to_string()).unwrap(),
     }
 }
 
@@ -99,8 +99,8 @@ pub fn format_order_item(order: serde_json::Value, ct_val: Decimal) -> Order {
     debug!(?order);
     let status = order["status"].as_str().unwrap_or("");
     let text = order["text"].as_str().unwrap_or("");
-    let size = Decimal::from_str(&order["size"].to_string()).unwrap();
-    let left = Decimal::from_str(&order["left"].to_string()).unwrap();
+    let size = Decimal::from_str(&order["size"].as_f64().unwrap().to_string()).unwrap();
+    let left = Decimal::from_str(&order["left"].as_f64().unwrap().to_string()).unwrap();
 
     let amount = size * ct_val;
     let deal_amount = (size - left) * ct_val;
@@ -111,10 +111,10 @@ pub fn format_order_item(order: serde_json::Value, ct_val: Decimal) -> Order {
     let rst_order = Order {
         id: order["id"].to_string(),
         custom_id: text.replace("t-my-custom-id_", ""),
-        price: Decimal::from_str(&order["price"].to_string()).unwrap(),
+        price: Decimal::from_str(&order["price"].as_f64().unwrap().to_string()).unwrap(),
         amount,
         deal_amount,
-        avg_price: Decimal::from_str(&order["fill_price"].to_string()).unwrap(),
+        avg_price: Decimal::from_str(&order["fill_price"].as_f64().unwrap().to_string()).unwrap(),
         status: custom_status,
         order_type: "limit".to_string(),
         trace_stack: TraceStack::default().on_special("120 gate_handle".to_string()),
@@ -135,7 +135,7 @@ pub fn format_depth_items(value: serde_json::Value) -> Vec<MarketOrder> {
     for value in value.as_array().unwrap() {
         depth_items.push(MarketOrder {
             price: Decimal::from_str(value["p"].as_str().unwrap()).unwrap(),
-            amount: Decimal::from_str(&value["s"].to_string()).unwrap(),
+            amount: Decimal::from_str(&value["s"].as_f64().unwrap().to_string()).unwrap(),
         })
     }
     return depth_items;

+ 8 - 8
standard/src/kucoin_handle.rs

@@ -39,9 +39,9 @@ pub fn handle_special_ticker(res_data: ResponseData) -> SpecialDepth {
 
 pub fn format_special_ticker(data: serde_json::Value, label: String) -> SpecialDepth {
     let bp = Decimal::from_str(&data["bestBidPrice"].as_str().unwrap()).unwrap();
-    let bq = Decimal::from_str(&data["bestBidSize"].to_string()).unwrap();
+    let bq = Decimal::from_str(&data["bestBidSize"].as_f64().unwrap().to_string()).unwrap();
     let ap = Decimal::from_str(&data["bestAskPrice"].as_str().unwrap()).unwrap();
-    let aq = Decimal::from_str(&data["bestAskSize"].to_string()).unwrap();
+    let aq = Decimal::from_str(&data["bestAskSize"].as_f64().unwrap().to_string()).unwrap();
     let mp = (bp + ap) * dec!(0.5);
 
     let ticker_info = SpecialTicker { sell: ap, buy: bp, mid_price: mp };
@@ -63,14 +63,14 @@ pub fn handle_position(res_data: ResponseData, ct_val: Decimal) -> Vec<Position>
 
 pub fn format_position_item(position: &serde_json::Value, ct_val: Decimal) -> Position {
     let symbol = position["symbol"].as_str().unwrap_or("");
-    let real_leverage = Decimal::from_str(&position["realLeverage"].to_string()).unwrap();
+    let real_leverage = Decimal::from_str(&position["realLeverage"].as_f64().unwrap().to_string()).unwrap();
     let currency = position["settleCurrency"].as_str().unwrap_or("");
     let coin = &symbol[..symbol.find(currency).unwrap_or(0)];
-    let avg_entry_price = Decimal::from_str(&position["avgEntryPrice"].to_string()).unwrap();
-    let unrealised_pnl = Decimal::from_str(&position["unrealisedPnl"].to_string()).unwrap();
-    let pos_margin = Decimal::from_str(&position["posMargin"].to_string()).unwrap();
+    let avg_entry_price = Decimal::from_str(&position["avgEntryPrice"].as_f64().unwrap().to_string()).unwrap();
+    let unrealised_pnl = Decimal::from_str(&position["unrealisedPnl"].as_f64().unwrap().to_string()).unwrap();
+    let pos_margin = Decimal::from_str(&position["posMargin"].as_f64().unwrap().to_string()).unwrap();
 
-    let current_qty = Decimal::from_str(&position["currentQty"].to_string()).unwrap();
+    let current_qty = Decimal::from_str(&position["currentQty"].as_f64().unwrap().to_string()).unwrap();
     let amount = current_qty * ct_val;
     let position_mode = match amount {
         amount if amount > Decimal::ZERO => PositionModeEnum::Long,
@@ -146,7 +146,7 @@ pub fn format_depth_items(value: serde_json::Value) -> Vec<MarketOrder> {
     for value in value.as_array().unwrap() {
         depth_items.push(MarketOrder {
             price: Decimal::from_str(value[0].as_str().unwrap()).unwrap(),
-            amount: Decimal::from_str(&value[1].to_string()).unwrap(),
+            amount: Decimal::from_str(&value[1].as_f64().unwrap().to_string()).unwrap(),
         })
     }
     return depth_items;

+ 26 - 26
standard/src/kucoin_swap.rs

@@ -93,8 +93,8 @@ impl Platform for KucoinSwap {
             let res_data_str = &res_data.data;
             let res_data_json: serde_json::Value = serde_json::from_str(res_data_str).unwrap();
 
-            let balance = Decimal::from_str(&res_data_json["marginBalance"].to_string()).unwrap();
-            let available_balance = Decimal::from_str(&res_data_json["availableBalance"].to_string()).unwrap();
+            let balance = Decimal::from_str(&res_data_json["marginBalance"].as_f64().unwrap().to_string()).unwrap();
+            let available_balance = Decimal::from_str(&res_data_json["availableBalance"].as_f64().unwrap().to_string()).unwrap();
             let frozen_balance = balance - available_balance;
             let result = Account {
                 coin: symbol_array[1].to_string(),
@@ -156,12 +156,12 @@ impl Platform for KucoinSwap {
             let time = (Decimal::from_str(&*ticker_info["ts"].to_string()).unwrap() / dec!(1000000)).floor().to_i64().unwrap();
             let result = Ticker {
                 time,
-                high: Decimal::from_str(&ticker_info["bestAskPrice"].to_string()).unwrap(),
-                low: Decimal::from_str(&ticker_info["bestBidPrice"].to_string()).unwrap(),
-                sell: Decimal::from_str(&ticker_info["bestAskPrice"].to_string()).unwrap(),
-                buy: Decimal::from_str(&ticker_info["bestBidPrice"].to_string()).unwrap(),
-                last: Decimal::from_str(&ticker_info["price"].to_string()).unwrap(),
-                volume: Decimal::from_str(&ticker_info["size"].to_string()).unwrap(),
+                high: Decimal::from_str(&ticker_info["bestAskPrice"].as_f64().unwrap().to_string()).unwrap(),
+                low: Decimal::from_str(&ticker_info["bestBidPrice"].as_f64().unwrap().to_string()).unwrap(),
+                sell: Decimal::from_str(&ticker_info["bestAskPrice"].as_f64().unwrap().to_string()).unwrap(),
+                buy: Decimal::from_str(&ticker_info["bestBidPrice"].as_f64().unwrap().to_string()).unwrap(),
+                last: Decimal::from_str(&ticker_info["price"].as_f64().unwrap().to_string()).unwrap(),
+                volume: Decimal::from_str(&ticker_info["size"].as_f64().unwrap().to_string()).unwrap(),
             };
             Ok(result)
         } else {
@@ -179,12 +179,12 @@ impl Platform for KucoinSwap {
             let time = (Decimal::from_str(&*ticker_info["ts"].to_string()).unwrap() / dec!(1000000)).floor().to_i64().unwrap();
             let result = Ticker {
                 time,
-                high: Decimal::from_str(&ticker_info["bestAskPrice"].to_string()).unwrap(),
-                low: Decimal::from_str(&ticker_info["bestBidPrice"].to_string()).unwrap(),
-                sell: Decimal::from_str(&ticker_info["bestAskPrice"].to_string()).unwrap(),
-                buy: Decimal::from_str(&ticker_info["bestBidPrice"].to_string()).unwrap(),
-                last: Decimal::from_str(&ticker_info["price"].to_string()).unwrap(),
-                volume: Decimal::from_str(&ticker_info["size"].to_string()).unwrap(),
+                high: Decimal::from_str(&ticker_info["bestAskPrice"].as_f64().unwrap().to_string()).unwrap(),
+                low: Decimal::from_str(&ticker_info["bestBidPrice"].as_f64().unwrap().to_string()).unwrap(),
+                sell: Decimal::from_str(&ticker_info["bestAskPrice"].as_f64().unwrap().to_string()).unwrap(),
+                buy: Decimal::from_str(&ticker_info["bestBidPrice"].as_f64().unwrap().to_string()).unwrap(),
+                last: Decimal::from_str(&ticker_info["price"].as_f64().unwrap().to_string()).unwrap(),
+                volume: Decimal::from_str(&ticker_info["size"].as_f64().unwrap().to_string()).unwrap(),
             };
             Ok(result)
         } else {
@@ -207,9 +207,9 @@ impl Platform for KucoinSwap {
                 Some(value) => {
                     let base_asset = value["baseCurrency"].as_str().unwrap_or("").to_string();
                     let quote_asset = value["quoteCurrency"].as_str().unwrap_or("").to_string();
-                    let tick_size = Decimal::from_str(&value["tickSize"].to_string()).unwrap();
-                    let min_qty = Decimal::from_str(&value["lotSize"].to_string()).unwrap();
-                    let ct_val = Decimal::from_str(&value["multiplier"].to_string()).unwrap();
+                    let tick_size = Decimal::from_str(&value["tickSize"].as_f64().unwrap().to_string()).unwrap();
+                    let min_qty = Decimal::from_str(&value["lotSize"].as_f64().unwrap().to_string()).unwrap();
+                    let ct_val = Decimal::from_str(&value["multiplier"].as_f64().unwrap().to_string()).unwrap();
 
                     let amount_size = min_qty * ct_val;
                     let price_precision = Decimal::from_u32(tick_size.scale()).unwrap();
@@ -225,9 +225,9 @@ impl Platform for KucoinSwap {
                         price_precision,
                         amount_precision,
                         min_qty,
-                        max_qty: Decimal::from_str(&value["maxOrderQty"].to_string()).unwrap(),
+                        max_qty: Decimal::from_str(&value["maxOrderQty"].as_f64().unwrap().to_string()).unwrap(),
                         min_notional,
-                        max_notional: Decimal::from_str(&value["maxPrice"].to_string()).unwrap(),
+                        max_notional: Decimal::from_str(&value["maxPrice"].as_f64().unwrap().to_string()).unwrap(),
                         ct_val,
                     };
                     Ok(result)
@@ -253,9 +253,9 @@ impl Platform for KucoinSwap {
                 Some(value) => {
                     let base_asset = value["baseCurrency"].as_str().unwrap_or("").to_string();
                     let quote_asset = value["quoteCurrency"].as_str().unwrap_or("").to_string();
-                    let tick_size = Decimal::from_str(&value["tickSize"].to_string()).unwrap();
-                    let min_qty = Decimal::from_str(&value["lotSize"].to_string()).unwrap();
-                    let ct_val = Decimal::from_str(&value["multiplier"].to_string()).unwrap();
+                    let tick_size = Decimal::from_str(&value["tickSize"].as_f64().unwrap().to_string()).unwrap();
+                    let min_qty = Decimal::from_str(&value["lotSize"].as_f64().unwrap().to_string()).unwrap();
+                    let ct_val = Decimal::from_str(&value["multiplier"].as_f64().unwrap().to_string()).unwrap();
 
                     let amount_size = min_qty * ct_val;
                     let price_precision = Decimal::from_u32(tick_size.scale()).unwrap();
@@ -271,9 +271,9 @@ impl Platform for KucoinSwap {
                         price_precision,
                         amount_precision,
                         min_qty,
-                        max_qty: Decimal::from_str(&value["maxOrderQty"].to_string()).unwrap(),
+                        max_qty: Decimal::from_str(&value["maxOrderQty"].as_f64().unwrap().to_string()).unwrap(),
                         min_notional,
-                        max_notional: Decimal::from_str(&value["maxPrice"].to_string()).unwrap(),
+                        max_notional: Decimal::from_str(&value["maxPrice"].as_f64().unwrap().to_string()).unwrap(),
                         ct_val,
                     };
                     Ok(result)
@@ -626,9 +626,9 @@ impl Platform for KucoinSwap {
 
 pub fn format_order_item(order: serde_json::Value, ct_val: Decimal) -> Order {
     let price = Decimal::from_str(order["price"].as_str().unwrap()).unwrap();
-    let size = Decimal::from_str(&order["size"].to_string()).unwrap();
+    let size = Decimal::from_str(&order["size"].as_f64().unwrap().to_string()).unwrap();
     let status = order["status"].as_str().unwrap_or("");
-    let filled_size = Decimal::from_str(&order["filledSize"].to_string()).unwrap();
+    let filled_size = Decimal::from_str(&order["filledSize"].as_f64().unwrap().to_string()).unwrap();
     let filled_value = Decimal::from_str(order["filledValue"].as_str().unwrap()).unwrap();
 
     let amount = size * ct_val;

+ 4 - 4
standard/src/okx_handle.rs

@@ -133,11 +133,11 @@ pub fn format_position_item(position: serde_json::Value, ct_val: Decimal) -> Pos
     let real_leverage = dec!(-1);
     let currency = position["ccy"].as_str().unwrap_or("");
     let coin: Vec<&str> = symbol.split("-").collect();
-    let avg_entry_price = Decimal::from_str(&position["avgPx"].to_string()).unwrap();
-    let unrealised_pnl = Decimal::from_str(&position["unrealisedPnl"].to_string()).unwrap();
-    let pos_margin = Decimal::from_str(&position["posSide"].to_string()).unwrap();
+    let avg_entry_price = Decimal::from_str(&position["avgPx"].as_f64().unwrap().to_string()).unwrap();
+    let unrealised_pnl = Decimal::from_str(&position["unrealisedPnl"].as_f64().unwrap().to_string()).unwrap();
+    let pos_margin = Decimal::from_str(&position["posSide"].as_f64().unwrap().to_string()).unwrap();
 
-    let current_qty = Decimal::from_str(&position["pos"].to_string()).unwrap();
+    let current_qty = Decimal::from_str(&position["pos"].as_f64().unwrap().to_string()).unwrap();
     let amount = current_qty * ct_val;
     let position_mode = match amount {
         amount if amount > Decimal::ZERO => PositionModeEnum::Long,