bingx_swap_handle.rs 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. // use std::str::FromStr;
  2. // use chrono::Utc;
  3. // use rust_decimal::Decimal;
  4. // use rust_decimal::prelude::FromPrimitive;
  5. // use serde_json::Value;
  6. // use exchanges::response_base::ResponseData;
  7. // use crate::{OrderBook, Trade, Record};
  8. // // use crate::{Account, OrderBook, Order, Position, SpecialOrder, Trade, Record};
  9. //
  10. // // 处理账号信息
  11. // // pub fn handle_account_info(_res_data: &ResponseData, _symbol: &String) -> Account {
  12. // // Account::new()
  13. // // }
  14. // //
  15. // // pub fn format_account_info(_data: &Vec<Value>, _symbol: &String) -> Account {
  16. // // Account::new()
  17. // // }
  18. // //
  19. // // // 处理position信息
  20. // // pub fn handle_position(_res_data: &ResponseData, _ct_val: &Decimal) -> Vec<Position> {
  21. // // vec![Position::new()]
  22. // // }
  23. // //
  24. // // pub fn format_position_item(_position: &Value, _ct_val: &Decimal) -> Position {
  25. // // Position::new()
  26. // // }
  27. // //
  28. // // // 处理order信息
  29. // // pub fn handle_order(_res_data: &ResponseData, _ct_val: Decimal) -> SpecialOrder {
  30. // // SpecialOrder::new()
  31. // // }
  32. // //
  33. // // pub fn format_order_item(_order: Value, _ct_val: Decimal) -> Order {
  34. // // Order::new()
  35. // // }
  36. // // 处理特殊Ticket信息
  37. // // pub fn handle_book_ticker(res_data: &ResponseData) -> SpecialDepth {
  38. // // let bp = Decimal::from_str((*res_data).data["b"].as_str().unwrap()).unwrap();
  39. // // let bq = Decimal::from_f64((*res_data).data["B"].as_f64().unwrap()).unwrap();
  40. // // let ap = Decimal::from_str((*res_data).data["a"].as_str().unwrap()).unwrap();
  41. // // let aq = Decimal::from_f64((*res_data).data["A"].as_f64().unwrap()).unwrap();
  42. // // let mp = (bp + ap) * dec!(0.5);
  43. // // let t = Decimal::from_u64((*res_data).data["u"].as_u64().unwrap()).unwrap();
  44. // // let create_at = (*res_data).data["t"].as_i64().unwrap() * 1000;
  45. // //
  46. // // let ticker_info = SpecialTicker { sell: ap, buy: bp, mid_price: mp, t, create_at };
  47. // // let depth_info = vec![bp, bq, ap, aq];
  48. // //
  49. // // SpecialDepth {
  50. // // name: (*res_data).tag.clone(),
  51. // // depth: depth_info,
  52. // // ticker: ticker_info,
  53. // // t,
  54. // // create_at,
  55. // // }
  56. // // }
  57. //
  58. // pub fn handle_records(value: &Value) -> Vec<Record> {
  59. // let mut records = vec![];
  60. // let symbol = value["s"].as_str().unwrap().replace("-", "_");
  61. //
  62. // for record_value in value["data"].as_array().unwrap() {
  63. // records.push(Record {
  64. // time: Decimal::from_i64(Utc::now().timestamp_millis()).unwrap(),
  65. // open: Decimal::from_str(record_value["o"].as_str().unwrap()).unwrap(),
  66. // high: Decimal::from_str(record_value["h"].as_str().unwrap()).unwrap(),
  67. // low: Decimal::from_str(record_value["l"].as_str().unwrap()).unwrap(),
  68. // close: Decimal::from_str(record_value["c"].as_str().unwrap()).unwrap(),
  69. // volume: Decimal::from_str(record_value["v"].as_str().unwrap()).unwrap(),
  70. // symbol: symbol.clone(),
  71. // });
  72. // }
  73. //
  74. // return records;
  75. // }
  76. //
  77. // pub fn format_depth_items(value: &Value) -> Vec<OrderBook> {
  78. // let mut depth_items: Vec<OrderBook> = vec![];
  79. // for value in value.as_array().unwrap() {
  80. // depth_items.push(OrderBook {
  81. // price: Decimal::from_str(value["p"].as_str().unwrap()).unwrap(),
  82. // amount: Decimal::from_f64(value["s"].as_f64().unwrap()).unwrap(),
  83. // })
  84. // }
  85. // return depth_items;
  86. // }
  87. //
  88. // pub fn format_trade_items(res_data: &ResponseData) -> Vec<Trade> {
  89. // let result = res_data.data["data"].as_array().unwrap();
  90. // let mut trades = vec![];
  91. //
  92. // for item in result {
  93. // let side = item["m"] == true;
  94. // let size = Decimal::from_str(item["q"].as_str().unwrap()).unwrap();
  95. // trades.push(Trade {
  96. // id: item["T"].to_string(),
  97. // time: Decimal::from_i64(item["T"].as_i64().unwrap()).unwrap(),
  98. // size: if side { -size } else { size },
  99. // price: Decimal::from_str(item["p"].as_str().unwrap().to_string().as_str()).unwrap(),
  100. // symbol: item["s"].as_str().unwrap().to_string().replace("-", "_"),
  101. // })
  102. // }
  103. //
  104. // return trades;
  105. // }