|
|
@@ -179,6 +179,36 @@ impl Platform for GateSwap {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ async fn get_ticker_symbol(&mut self, symbol: String) -> Result<Ticker, Error> {
|
|
|
+ let symbol_array: Vec<&str> = symbol.split("_").collect();
|
|
|
+ let res_data = self.request.get_ticker(symbol_array[1].to_string().to_lowercase()).await;
|
|
|
+ if res_data.code == "200" {
|
|
|
+ let res_data_str = &res_data.data;
|
|
|
+ let res_data_json: Vec<serde_json::Value> = serde_json::from_str(res_data_str).unwrap();
|
|
|
+ let ticker_info = res_data_json.iter().find(|item| item["contract"].as_str().unwrap() == symbol);
|
|
|
+ match ticker_info {
|
|
|
+ None => {
|
|
|
+ error!("Gate:获取Ticker信息错误!\nget_ticker:res_data={:?}", res_data_str);
|
|
|
+ panic!("Gate:获取Ticker信息错误!\nget_ticker:res_data={:?}", res_data_str)
|
|
|
+ }
|
|
|
+ Some(value) => {
|
|
|
+ let result = Ticker {
|
|
|
+ time: chrono::Utc::now().timestamp_millis(),
|
|
|
+ high: Decimal::from_str(value["high_24h"].as_str().unwrap()).unwrap(),
|
|
|
+ low: Decimal::from_str(value["low_24h"].as_str().unwrap()).unwrap(),
|
|
|
+ sell: Decimal::from_str(value["lowest_ask"].as_str().unwrap()).unwrap(),
|
|
|
+ buy: Decimal::from_str(value["highest_bid"].as_str().unwrap()).unwrap(),
|
|
|
+ last: Decimal::from_str(value["last"].as_str().unwrap()).unwrap(),
|
|
|
+ volume: Decimal::from_str(value["volume_24h"].as_str().unwrap()).unwrap(),
|
|
|
+ };
|
|
|
+ Ok(result)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ Err(Error::new(ErrorKind::Other, res_data.to_string()))
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
async fn get_market(&mut self) -> Result<Market, Error> {
|
|
|
let symbol_array: Vec<&str> = self.symbol.split("_").collect();
|
|
|
let res_data = self.request.get_market_details(symbol_array[1].to_string().to_lowercase()).await;
|
|
|
@@ -220,6 +250,49 @@ impl Platform for GateSwap {
|
|
|
Err(Error::new(ErrorKind::Other, res_data.to_string()))
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+ async fn get_market_symbol(&mut self, symbol: String) -> Result<Market, Error> {
|
|
|
+ let symbol_array: Vec<&str> = symbol.split("_").collect();
|
|
|
+ let res_data = self.request.get_market_details(symbol_array[1].to_string().to_lowercase()).await;
|
|
|
+ if res_data.code == "200" {
|
|
|
+ let res_data_str = &res_data.data;
|
|
|
+ let res_data_json: Vec<serde_json::Value> = serde_json::from_str(res_data_str).unwrap();
|
|
|
+ let market_info = res_data_json.iter().find(|item| item["name"].as_str().unwrap() == symbol);
|
|
|
+ match market_info {
|
|
|
+ None => {
|
|
|
+ error!("Gate:获取Market信息错误!\nget_market:market_info={:?}", market_info);
|
|
|
+ panic!("Gate:获取Market信息错误!\nget_market:market_info={:?}", market_info)
|
|
|
+ }
|
|
|
+ Some(value) => {
|
|
|
+ let name = value["name"].as_str().unwrap();
|
|
|
+ let name_array: Vec<&str> = name.split("_").collect();
|
|
|
+ let tick_size = Decimal::from_str(value["order_price_round"].as_str().unwrap()).unwrap();
|
|
|
+ let amount_size = Decimal::from_str(value["quanto_multiplier"].as_str().unwrap()).unwrap();
|
|
|
+ let price_precision = Decimal::from_u32(tick_size.scale()).unwrap();
|
|
|
+ let amount_precision = Decimal::from_u32(amount_size.scale()).unwrap();
|
|
|
+
|
|
|
+ let result = Market {
|
|
|
+ symbol: name.to_string(),
|
|
|
+ base_asset: name_array[0].to_string(),
|
|
|
+ quote_asset: name_array[1].to_string(),
|
|
|
+ tick_size,
|
|
|
+ amount_size,
|
|
|
+ price_precision,
|
|
|
+ amount_precision,
|
|
|
+ min_qty: Decimal::from_str(&value["order_size_min"].to_string()).unwrap(),
|
|
|
+ max_qty: Decimal::from_str(&value["order_size_max"].to_string()).unwrap(),
|
|
|
+ min_notional: Default::default(),
|
|
|
+ max_notional: Default::default(),
|
|
|
+ ct_val: Default::default(),
|
|
|
+ };
|
|
|
+ Ok(result)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ Err(Error::new(ErrorKind::Other, res_data.to_string()))
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
// 获取订单详情
|
|
|
async fn get_order_detail(&mut self, order_id: &str, custom_id: &str) -> Result<Order, Error> {
|
|
|
let symbol_array: Vec<&str> = self.symbol.split("_").collect();
|