| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105 |
- // use std::str::FromStr;
- // use chrono::Utc;
- // use rust_decimal::Decimal;
- // use rust_decimal::prelude::FromPrimitive;
- // use serde_json::Value;
- // use exchanges::response_base::ResponseData;
- // use crate::{OrderBook, Trade, Record};
- // // use crate::{Account, OrderBook, Order, Position, SpecialOrder, Trade, Record};
- //
- // // 处理账号信息
- // // pub fn handle_account_info(_res_data: &ResponseData, _symbol: &String) -> Account {
- // // Account::new()
- // // }
- // //
- // // pub fn format_account_info(_data: &Vec<Value>, _symbol: &String) -> Account {
- // // Account::new()
- // // }
- // //
- // // // 处理position信息
- // // pub fn handle_position(_res_data: &ResponseData, _ct_val: &Decimal) -> Vec<Position> {
- // // vec![Position::new()]
- // // }
- // //
- // // pub fn format_position_item(_position: &Value, _ct_val: &Decimal) -> Position {
- // // Position::new()
- // // }
- // //
- // // // 处理order信息
- // // pub fn handle_order(_res_data: &ResponseData, _ct_val: Decimal) -> SpecialOrder {
- // // SpecialOrder::new()
- // // }
- // //
- // // pub fn format_order_item(_order: Value, _ct_val: Decimal) -> Order {
- // // Order::new()
- // // }
- // // 处理特殊Ticket信息
- // // pub fn handle_book_ticker(res_data: &ResponseData) -> SpecialDepth {
- // // let bp = Decimal::from_str((*res_data).data["b"].as_str().unwrap()).unwrap();
- // // 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()).unwrap();
- // // 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();
- // // let create_at = (*res_data).data["t"].as_i64().unwrap() * 1000;
- // //
- // // let ticker_info = SpecialTicker { sell: ap, buy: bp, mid_price: mp, t, create_at };
- // // let depth_info = vec![bp, bq, ap, aq];
- // //
- // // SpecialDepth {
- // // name: (*res_data).tag.clone(),
- // // depth: depth_info,
- // // ticker: ticker_info,
- // // t,
- // // create_at,
- // // }
- // // }
- //
- // pub fn handle_records(value: &Value) -> Vec<Record> {
- // let mut records = vec![];
- // let symbol = value["s"].as_str().unwrap().replace("-", "_");
- //
- // for record_value in value["data"].as_array().unwrap() {
- // records.push(Record {
- // time: Decimal::from_i64(Utc::now().timestamp_millis()).unwrap(),
- // open: Decimal::from_str(record_value["o"].as_str().unwrap()).unwrap(),
- // high: Decimal::from_str(record_value["h"].as_str().unwrap()).unwrap(),
- // low: Decimal::from_str(record_value["l"].as_str().unwrap()).unwrap(),
- // close: Decimal::from_str(record_value["c"].as_str().unwrap()).unwrap(),
- // volume: Decimal::from_str(record_value["v"].as_str().unwrap()).unwrap(),
- // symbol: symbol.clone(),
- // });
- // }
- //
- // return records;
- // }
- //
- // pub fn format_depth_items(value: &Value) -> Vec<OrderBook> {
- // let mut depth_items: Vec<OrderBook> = vec![];
- // for value in value.as_array().unwrap() {
- // depth_items.push(OrderBook {
- // price: Decimal::from_str(value["p"].as_str().unwrap()).unwrap(),
- // amount: Decimal::from_f64(value["s"].as_f64().unwrap()).unwrap(),
- // })
- // }
- // return depth_items;
- // }
- //
- // pub fn format_trade_items(res_data: &ResponseData) -> Vec<Trade> {
- // let result = res_data.data["data"].as_array().unwrap();
- // let mut trades = vec![];
- //
- // for item in result {
- // let side = item["m"] == true;
- // let size = Decimal::from_str(item["q"].as_str().unwrap()).unwrap();
- // trades.push(Trade {
- // id: item["T"].to_string(),
- // time: Decimal::from_i64(item["T"].as_i64().unwrap()).unwrap(),
- // size: if side { -size } else { size },
- // price: Decimal::from_str(item["p"].as_str().unwrap().to_string().as_str()).unwrap(),
- // symbol: item["s"].as_str().unwrap().to_string().replace("-", "_"),
- // })
- // }
- //
- // return trades;
- // }
|