woo_swap_handle.rs 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. // use std::str::FromStr;
  2. // use rust_decimal::Decimal;
  3. // use rust_decimal::prelude::FromPrimitive;
  4. // use serde_json::Value;
  5. // use exchanges::response_base::ResponseData;
  6. // use crate::{OrderBook, Trade, Record};
  7. //
  8. // pub fn handle_records(value: &Value) -> Vec<Record> {
  9. // let mut records = vec![];
  10. // let record = value["data"].clone();
  11. // records.push(Record {
  12. // time: Decimal::from_i64(record["startTime"].as_i64().unwrap()).unwrap(),
  13. // open: Decimal::from_f64(record["open"].as_f64().unwrap()).unwrap(),
  14. // high: Decimal::from_f64(record["high"].as_f64().unwrap()).unwrap(),
  15. // low: Decimal::from_f64(record["low"].as_f64().unwrap()).unwrap(),
  16. // close: Decimal::from_f64(record["close"].as_f64().unwrap()).unwrap(),
  17. // volume: Decimal::from_f64(record["volume"].as_f64().unwrap()).unwrap(),
  18. // symbol: record["symbol"].as_str().unwrap().replace("PERP_", ""),
  19. // });
  20. //
  21. // return records;
  22. // }
  23. //
  24. // pub fn format_depth_items(value: &Value) -> Vec<OrderBook> {
  25. // let mut depth_items: Vec<OrderBook> = vec![];
  26. // for value in value.as_array().unwrap() {
  27. // depth_items.push(OrderBook {
  28. // price: Decimal::from_str(value[0].as_str().unwrap()).unwrap(),
  29. // amount: Decimal::from_str(value[1].as_str().unwrap()).unwrap(),
  30. // })
  31. // }
  32. // return depth_items;
  33. // }
  34. //
  35. // pub fn format_trade_items(res_data: &ResponseData) -> Vec<Trade> {
  36. // let result = res_data.data["data"].as_array().unwrap();
  37. // let mut trades = vec![];
  38. // for item in result {
  39. // let side = item["b"] == "BUY";
  40. // let size = Decimal::from_f64(item["a"].as_f64().unwrap()).unwrap();
  41. // let price = Decimal::from_f64(item["p"].as_f64().unwrap()).unwrap();
  42. // trades.push(Trade {
  43. // id: res_data.data["ts"].to_string(),
  44. // time: Decimal::from_i64(res_data.data["ts"].as_i64().unwrap()).unwrap(),
  45. // size: if side { size * price } else { -size * price },
  46. // price,
  47. // symbol: item["s"].as_str().unwrap().replace("PERP_", ""),
  48. // })
  49. // }
  50. //
  51. // return trades;
  52. // }