binance_spot_handle.rs 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. // use std::str::FromStr;
  2. // use rust_decimal::Decimal;
  3. // use rust_decimal_macros::dec;
  4. // use exchanges::response_base::ResponseData;
  5. // use crate::{MarketOrder, SpecialDepth, SpecialTicker};
  6. // use crate::exchange::ExchangeEnum;
  7. // use crate::handle_info::HandleSwapInfo;
  8. //
  9. //
  10. // // 处理特殊Ticker信息
  11. // pub fn handle_special_ticker(res_data: ResponseData) -> SpecialDepth {
  12. // let res_data_str = res_data.data;
  13. // let res_data_json: serde_json::Value = serde_json::from_str(&*res_data_str).unwrap();
  14. // format_special_ticker(res_data_json, res_data.label)
  15. // }
  16. //
  17. // pub fn format_special_ticker(data: serde_json::Value, label: String) -> SpecialDepth {
  18. // let bp = Decimal::from_str(data["b"].as_str().unwrap()).unwrap();
  19. // let bq = Decimal::from_str(data["B"].as_str().unwrap()).unwrap();
  20. // let ap = Decimal::from_str(data["a"].as_str().unwrap()).unwrap();
  21. // let aq = Decimal::from_str(data["A"].as_str().unwrap()).unwrap();
  22. // let mp = (bp + ap) * dec!(0.5);
  23. // let t = Decimal::from_str(&data["u"].to_string()).unwrap();
  24. //
  25. // let ticker_info = SpecialTicker { sell: ap, buy: bp, mid_price: mp, t, create_at: Default::default() };
  26. // let depth_info = vec![bp, bq, ap, aq];
  27. // SpecialDepth {
  28. // name: label,
  29. // depth: depth_info,
  30. // ticker: ticker_info,
  31. // t,
  32. // create_at: Default::default(),
  33. // }
  34. // }
  35. //
  36. // // 处理特殊深度数据
  37. // pub fn handle_special_depth(res_data: ResponseData) -> SpecialDepth {
  38. // HandleSwapInfo::handle_special_depth(ExchangeEnum::BinanceSpot, res_data)
  39. // }
  40. //
  41. // // 格式化深度信息
  42. // pub fn format_depth_items(value: serde_json::Value) -> Vec<MarketOrder> {
  43. // let mut depth_items: Vec<MarketOrder> = vec![];
  44. // for value in value.as_array().unwrap() {
  45. // depth_items.push(MarketOrder {
  46. // price: Decimal::from_str(value[0].as_str().unwrap()).unwrap(),
  47. // amount: Decimal::from_str(value[1].as_str().unwrap()).unwrap(),
  48. // })
  49. // }
  50. // return depth_items;
  51. // }