|
|
@@ -1,4 +1,5 @@
|
|
|
use std::str::FromStr;
|
|
|
+use chrono::Utc;
|
|
|
use rust_decimal::Decimal;
|
|
|
use rust_decimal::prelude::FromPrimitive;
|
|
|
use serde_json::{from_value, Value};
|
|
|
@@ -6,7 +7,7 @@ use tokio::time::Instant;
|
|
|
use tracing::{error};
|
|
|
use exchanges::response_base::ResponseData;
|
|
|
use global::trace_stack::TraceStack;
|
|
|
-use crate::{Account, OrderBook, Order, Position, PositionModeEnum, SpecialOrder, Depth, Trade};
|
|
|
+use crate::{Account, OrderBook, Order, Position, PositionModeEnum, SpecialOrder, Depth, Trade, Ticker};
|
|
|
|
|
|
// 处理账号信息
|
|
|
pub fn handle_account_info(res_data: &ResponseData, symbol: &String) -> Account {
|
|
|
@@ -193,6 +194,29 @@ pub fn handle_book_ticker(res_data: &ResponseData, mul: &Decimal) -> Depth {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+pub fn handle_ticker(res_data: &ResponseData) -> Ticker {
|
|
|
+ let time = Decimal::from_i64(Utc::now().timestamp_millis()).unwrap();
|
|
|
+ let high = Decimal::from_str(res_data.data["highPrice24h"].as_str().unwrap()).unwrap();
|
|
|
+ let low = Decimal::from_str(res_data.data["lowPrice24h"].as_str().unwrap()).unwrap();
|
|
|
+ let sell = Decimal::from_str(res_data.data["ask1Price"].as_str().unwrap()).unwrap();
|
|
|
+ let buy = Decimal::from_str(res_data.data["bid1Price"].as_str().unwrap()).unwrap();
|
|
|
+ let last = Decimal::from_str(res_data.data["lastPrice"].as_str().unwrap()).unwrap();
|
|
|
+ let volume = Decimal::from_str(res_data.data["volume24h"].as_str().unwrap()).unwrap();
|
|
|
+ let open_interest = Decimal::from_str(res_data.data["openInterest"].as_str().unwrap()).unwrap();
|
|
|
+ // let s = res_data.data["symbol"].as_str().unwrap().replace("USDT", "_USDT");
|
|
|
+
|
|
|
+ Ticker {
|
|
|
+ time,
|
|
|
+ high,
|
|
|
+ low,
|
|
|
+ sell,
|
|
|
+ buy,
|
|
|
+ last,
|
|
|
+ volume,
|
|
|
+ open_interest,
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
pub fn format_depth_items(value: Value, mul: &Decimal) -> Vec<OrderBook> {
|
|
|
let mut depth_items: Vec<OrderBook> = vec![];
|
|
|
for val in value.as_array().unwrap() {
|