|
@@ -104,15 +104,36 @@ impl Platform for MexcSwap {
|
|
|
}
|
|
}
|
|
|
// 获取市场行情
|
|
// 获取市场行情
|
|
|
async fn get_ticker(&mut self) -> Result<Ticker, Error> {
|
|
async fn get_ticker(&mut self) -> Result<Ticker, Error> {
|
|
|
- Err(Error::new(ErrorKind::NotFound, "mexc_swap:该交易所方法未实现".to_string()))
|
|
|
|
|
|
|
+ self.get_ticker_symbol(self.symbol.clone()).await
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- async fn get_record(&mut self, _interval: String) -> Result<Vec<Record>, Error> {
|
|
|
|
|
- todo!("还没做呢")
|
|
|
|
|
|
|
+ async fn get_ticker_symbol(&mut self, symbol: String) -> Result<Ticker, Error> {
|
|
|
|
|
+ let params = json!({
|
|
|
|
|
+ "symbol": symbol,
|
|
|
|
|
+ });
|
|
|
|
|
+
|
|
|
|
|
+ let res_data = self.request.get_ticker(params).await;
|
|
|
|
|
+ if res_data.code == 200 {
|
|
|
|
|
+ let ticker_info = res_data.data;
|
|
|
|
|
+ let time = Decimal::from_i64(ticker_info["timestamp"].as_i64().unwrap()).unwrap();
|
|
|
|
|
+ let result = Ticker {
|
|
|
|
|
+ time,
|
|
|
|
|
+ high: Decimal::from_f64(ticker_info["high24Price"].as_f64().unwrap()).unwrap(),
|
|
|
|
|
+ low: Decimal::from_f64(ticker_info["lower24Price"].as_f64().unwrap()).unwrap(),
|
|
|
|
|
+ sell: Decimal::from_f64(ticker_info["ask1"].as_f64().unwrap()).unwrap(),
|
|
|
|
|
+ buy: Decimal::from_f64(ticker_info["bid1"].as_f64().unwrap()).unwrap(),
|
|
|
|
|
+ last: Decimal::from_f64(ticker_info["lastPrice"].as_f64().unwrap()).unwrap(),
|
|
|
|
|
+ volume: Decimal::from_f64(ticker_info["volume24"].as_f64().unwrap()).unwrap(),
|
|
|
|
|
+ open_interest: Decimal::from_f64(ticker_info["holdVol"].as_f64().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> {
|
|
|
|
|
- Err(Error::new(ErrorKind::NotFound, "mexc_swap:该交易所方法未实现".to_string()))
|
|
|
|
|
|
|
+ async fn get_record(&mut self, _interval: String) -> Result<Vec<Record>, Error> {
|
|
|
|
|
+ todo!("还没做呢")
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
async fn get_market(&mut self) -> Result<Market, Error> {
|
|
async fn get_market(&mut self) -> Result<Market, Error> {
|
|
@@ -128,16 +149,17 @@ impl Platform for MexcSwap {
|
|
|
Err(Error::new(ErrorKind::Other, res_data.to_string()))
|
|
Err(Error::new(ErrorKind::Other, res_data.to_string()))
|
|
|
}
|
|
}
|
|
|
Some(value) => {
|
|
Some(value) => {
|
|
|
|
|
+ // info!("get_market:res_data={:}", serde_json::to_string_pretty(&value)?);
|
|
|
let symbol = value["symbol"].as_str().unwrap().to_string();
|
|
let symbol = value["symbol"].as_str().unwrap().to_string();
|
|
|
let base_asset = value["baseCoin"].as_str().unwrap().to_string();
|
|
let base_asset = value["baseCoin"].as_str().unwrap().to_string();
|
|
|
let quote_asset = value["quoteCoin"].as_str().unwrap().to_string();
|
|
let quote_asset = value["quoteCoin"].as_str().unwrap().to_string();
|
|
|
- let tick_size = Decimal::from_i64(value["priceUnit"].as_i64().unwrap()).unwrap();
|
|
|
|
|
- let amount_size = Decimal::from_i64(value["volUnit"].as_i64().unwrap()).unwrap();
|
|
|
|
|
|
|
+ let tick_size = Decimal::from_f64(value["priceUnit"].as_f64().unwrap()).unwrap();
|
|
|
|
|
+ let amount_size = Decimal::from_f64(value["volUnit"].as_f64().unwrap()).unwrap();
|
|
|
let price_precision = Decimal::from_i64(value["priceScale"].as_i64().unwrap()).unwrap();
|
|
let price_precision = Decimal::from_i64(value["priceScale"].as_i64().unwrap()).unwrap();
|
|
|
let amount_precision = Decimal::from_i64(value["volScale"].as_i64().unwrap()).unwrap();
|
|
let amount_precision = Decimal::from_i64(value["volScale"].as_i64().unwrap()).unwrap();
|
|
|
let min_qty = Decimal::from_i64(value["minVol"].as_i64().unwrap()).unwrap();
|
|
let min_qty = Decimal::from_i64(value["minVol"].as_i64().unwrap()).unwrap();
|
|
|
let max_qty = Decimal::from_i64(value["maxVol"].as_i64().unwrap()).unwrap();
|
|
let max_qty = Decimal::from_i64(value["maxVol"].as_i64().unwrap()).unwrap();
|
|
|
- let multiplier = Decimal::from_i64(value["contractSize"].as_i64().unwrap()).unwrap();
|
|
|
|
|
|
|
+ let multiplier = Decimal::from_f64(value["contractSize"].as_f64().unwrap()).unwrap();
|
|
|
|
|
|
|
|
let result = Market {
|
|
let result = Market {
|
|
|
symbol,
|
|
symbol,
|
|
@@ -179,13 +201,13 @@ impl Platform for MexcSwap {
|
|
|
let symbol = value["symbol"].as_str().unwrap().to_string();
|
|
let symbol = value["symbol"].as_str().unwrap().to_string();
|
|
|
let base_asset = value["baseCoin"].as_str().unwrap().to_string();
|
|
let base_asset = value["baseCoin"].as_str().unwrap().to_string();
|
|
|
let quote_asset = value["quoteCoin"].as_str().unwrap().to_string();
|
|
let quote_asset = value["quoteCoin"].as_str().unwrap().to_string();
|
|
|
- let tick_size = Decimal::from_i64(value["priceUnit"].as_i64().unwrap()).unwrap();
|
|
|
|
|
- let amount_size = Decimal::from_i64(value["volUnit"].as_i64().unwrap()).unwrap();
|
|
|
|
|
|
|
+ let tick_size = Decimal::from_f64(value["priceUnit"].as_f64().unwrap()).unwrap();
|
|
|
|
|
+ let amount_size = Decimal::from_f64(value["volUnit"].as_f64().unwrap()).unwrap();
|
|
|
let price_precision = Decimal::from_i64(value["priceScale"].as_i64().unwrap()).unwrap();
|
|
let price_precision = Decimal::from_i64(value["priceScale"].as_i64().unwrap()).unwrap();
|
|
|
let amount_precision = Decimal::from_i64(value["volScale"].as_i64().unwrap()).unwrap();
|
|
let amount_precision = Decimal::from_i64(value["volScale"].as_i64().unwrap()).unwrap();
|
|
|
let min_qty = Decimal::from_i64(value["minVol"].as_i64().unwrap()).unwrap();
|
|
let min_qty = Decimal::from_i64(value["minVol"].as_i64().unwrap()).unwrap();
|
|
|
let max_qty = Decimal::from_i64(value["maxVol"].as_i64().unwrap()).unwrap();
|
|
let max_qty = Decimal::from_i64(value["maxVol"].as_i64().unwrap()).unwrap();
|
|
|
- let multiplier = Decimal::from_i64(value["contractSize"].as_i64().unwrap()).unwrap();
|
|
|
|
|
|
|
+ let multiplier = Decimal::from_f64(value["contractSize"].as_f64().unwrap()).unwrap();
|
|
|
|
|
|
|
|
let result = Market {
|
|
let result = Market {
|
|
|
symbol,
|
|
symbol,
|