|
|
@@ -5,11 +5,13 @@ use tokio::sync::mpsc::Sender;
|
|
|
use std::str::FromStr;
|
|
|
use async_trait::async_trait;
|
|
|
use rust_decimal::Decimal;
|
|
|
+use rust_decimal::prelude::ToPrimitive;
|
|
|
+use rust_decimal_macros::dec;
|
|
|
use serde_json::{Value};
|
|
|
use tokio::time::Instant;
|
|
|
use global::trace_stack::TraceStack;
|
|
|
use crate::exchange::ExchangeEnum;
|
|
|
-use crate::{Account, Market, Order, OrderCommand, Platform, Position, Ticker};
|
|
|
+use crate::{Account, Market, Order, OrderCommand, Platform, Position, Ticker, utils};
|
|
|
|
|
|
#[allow(dead_code)]
|
|
|
#[derive(Clone)]
|
|
|
@@ -101,27 +103,25 @@ impl Platform for BitgetSwap {
|
|
|
async fn get_positions(&mut self) -> Result<Vec<Position>, Error> { Err(Error::new(ErrorKind::NotFound, "bitget_swap:该交易所方法未实现".to_string())) }
|
|
|
|
|
|
async fn get_ticker(&mut self) -> Result<Ticker, Error> {
|
|
|
- // let symbol_format = utils::format_symbol(self.symbol.clone(), "");
|
|
|
- // let res_data = self.request.get_tickers(symbol_format).await;
|
|
|
- // if res_data.code == "200" {
|
|
|
- // let res_data_str = &res_data.data;
|
|
|
- // let res_data_json: serde_json::Value = serde_json::from_str(res_data_str).unwrap();
|
|
|
- // let ticker_info = res_data_json[0].clone();
|
|
|
- // let time = (Decimal::from_str(&*ticker_info["ts"].as_str().unwrap()).unwrap() / dec!(1000)).floor().to_i64().unwrap();
|
|
|
- // let result = Ticker {
|
|
|
- // time,
|
|
|
- // high: Decimal::from_str(ticker_info["high24h"].as_str().unwrap()).unwrap(),
|
|
|
- // low: Decimal::from_str(ticker_info["low24h"].as_str().unwrap()).unwrap(),
|
|
|
- // sell: Decimal::from_str(ticker_info["askPr"].as_str().unwrap()).unwrap(),
|
|
|
- // buy: Decimal::from_str(ticker_info["bidPr"].as_str().unwrap()).unwrap(),
|
|
|
- // last: Decimal::from_str(ticker_info["lastPr"].as_str().unwrap()).unwrap(),
|
|
|
- // volume: Decimal::from_str(ticker_info["quoteVolume"].as_str().unwrap()).unwrap(),
|
|
|
- // };
|
|
|
- // Ok(result)
|
|
|
- // } else {
|
|
|
- // Err(Error::new(ErrorKind::Other, res_data.to_string()))
|
|
|
- // }
|
|
|
- Err(Error::new(ErrorKind::NotFound, "bitget_swap:该交易所方法未实现".to_string()))
|
|
|
+ let symbol_format = utils::format_symbol(self.symbol.clone(), "");
|
|
|
+ let res_data = self.request.get_tickers(symbol_format).await;
|
|
|
+ if res_data.code == "200" {
|
|
|
+ let res_data_json = res_data.data;
|
|
|
+ let ticker_info = res_data_json[0].clone();
|
|
|
+ let time = (Decimal::from_str(&*ticker_info["ts"].as_str().unwrap()).unwrap() / dec!(1000)).floor().to_i64().unwrap();
|
|
|
+ let result = Ticker {
|
|
|
+ time,
|
|
|
+ high: Decimal::from_str(ticker_info["high24h"].as_str().unwrap()).unwrap(),
|
|
|
+ low: Decimal::from_str(ticker_info["low24h"].as_str().unwrap()).unwrap(),
|
|
|
+ sell: Decimal::from_str(ticker_info["askPr"].as_str().unwrap()).unwrap(),
|
|
|
+ buy: Decimal::from_str(ticker_info["bidPr"].as_str().unwrap()).unwrap(),
|
|
|
+ last: Decimal::from_str(ticker_info["lastPr"].as_str().unwrap()).unwrap(),
|
|
|
+ volume: Decimal::from_str(ticker_info["quoteVolume"].as_str().unwrap()).unwrap(),
|
|
|
+ };
|
|
|
+ Ok(result)
|
|
|
+ } else {
|
|
|
+ Err(Error::new(ErrorKind::Other, res_data.to_string()))
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
async fn get_ticker_symbol(&mut self, symbol: String) -> Result<Ticker, Error> {
|