|
@@ -1,113 +1,172 @@
|
|
|
-// use std::collections::BTreeMap;
|
|
|
|
|
-// use std::io::{Error, ErrorKind};
|
|
|
|
|
-// use async_trait::async_trait;
|
|
|
|
|
-// use rust_decimal::Decimal;
|
|
|
|
|
-// use rust_decimal_macros::dec;
|
|
|
|
|
-// use tracing::warn;
|
|
|
|
|
-// use crate::{Platform, ExchangeEnum, Account, Position, Ticker, Market, Order, OrderCommand};
|
|
|
|
|
-// use exchanges::gate_spot_rest::GateSpotRest;
|
|
|
|
|
-// use global::trace_stack::TraceStack;
|
|
|
|
|
-//
|
|
|
|
|
-// #[allow(dead_code)]
|
|
|
|
|
-// #[derive(Clone)]
|
|
|
|
|
-// pub struct GateSpot {
|
|
|
|
|
-// exchange: ExchangeEnum,
|
|
|
|
|
-// symbol: String,
|
|
|
|
|
-// is_colo: bool,
|
|
|
|
|
-// params: BTreeMap<String, String>,
|
|
|
|
|
-// request: GateSpotRest,
|
|
|
|
|
-// }
|
|
|
|
|
-//
|
|
|
|
|
-// impl GateSpot {
|
|
|
|
|
-// pub fn new(symbol: String, is_colo: bool, params: BTreeMap<String, String>) -> GateSpot {
|
|
|
|
|
-// GateSpot {
|
|
|
|
|
-// exchange: ExchangeEnum::GateSpot,
|
|
|
|
|
-// symbol: symbol.to_uppercase(),
|
|
|
|
|
-// is_colo,
|
|
|
|
|
-// params: params.clone(),
|
|
|
|
|
-// request: GateSpotRest::new(is_colo, params.clone()),
|
|
|
|
|
-// }
|
|
|
|
|
-// }
|
|
|
|
|
-// }
|
|
|
|
|
-//
|
|
|
|
|
-// #[async_trait]
|
|
|
|
|
-// impl Platform for GateSpot {
|
|
|
|
|
-// // 克隆方法
|
|
|
|
|
-// fn clone_box(&self) -> Box<dyn Platform + Send + Sync> { Box::new(self.clone()) }
|
|
|
|
|
-// // 获取交易所模式
|
|
|
|
|
-// fn get_self_exchange(&self) -> ExchangeEnum {
|
|
|
|
|
-// ExchangeEnum::GateSpot
|
|
|
|
|
-// }
|
|
|
|
|
-// // 获取交易对
|
|
|
|
|
-// fn get_self_symbol(&self) -> String { self.symbol.clone() }
|
|
|
|
|
-// // 获取是否使用高速通道
|
|
|
|
|
-// fn get_self_is_colo(&self) -> bool {
|
|
|
|
|
-// self.is_colo
|
|
|
|
|
-// }
|
|
|
|
|
-// // 获取params信息
|
|
|
|
|
-// fn get_self_params(&self) -> BTreeMap<String, String> {
|
|
|
|
|
-// self.params.clone()
|
|
|
|
|
-// }
|
|
|
|
|
-//
|
|
|
|
|
-// fn get_self_market(&self) -> Market {
|
|
|
|
|
-// warn!("gate_spot:该交易所方法未实现");
|
|
|
|
|
-// return Market::new();
|
|
|
|
|
-// }
|
|
|
|
|
-//
|
|
|
|
|
-// fn get_request_delays(&self) -> Vec<i64> {
|
|
|
|
|
-// warn!("gate_spot:该交易所方法未实现");
|
|
|
|
|
-// return vec![];
|
|
|
|
|
-// }
|
|
|
|
|
-//
|
|
|
|
|
-// fn get_request_avg_delay(&self) -> Decimal {
|
|
|
|
|
-// warn!("gate_spot:该交易所方法未实现");
|
|
|
|
|
-// return dec!(0);
|
|
|
|
|
-// }
|
|
|
|
|
-//
|
|
|
|
|
-// fn get_request_max_delay(&self) -> i64 {
|
|
|
|
|
-// warn!("gate_spot:该交易所方法未实现");
|
|
|
|
|
-// return 0;
|
|
|
|
|
-// }
|
|
|
|
|
-//
|
|
|
|
|
-// async fn get_server_time(&mut self) -> Result<String, Error> { Err(Error::new(ErrorKind::NotFound, "gate_spot:该交易所方法未实现".to_string())) }
|
|
|
|
|
-//
|
|
|
|
|
-// async fn get_account(&mut self) -> Result<Account, Error> { Err(Error::new(ErrorKind::NotFound, "gate_spot:该交易所方法未实现".to_string())) }
|
|
|
|
|
-//
|
|
|
|
|
-// async fn get_spot_account(&mut self) -> Result<Vec<Account>, Error> { Err(Error::new(ErrorKind::NotFound, "gate_spot:该交易所方法未实现".to_string())) }
|
|
|
|
|
-//
|
|
|
|
|
-// async fn get_position(&mut self) -> Result<Vec<Position>, Error> { Err(Error::new(ErrorKind::NotFound, "gate_spot:该交易所方法未实现".to_string())) }
|
|
|
|
|
-//
|
|
|
|
|
-// async fn get_positions(&mut self) -> Result<Vec<Position>, Error> { Err(Error::new(ErrorKind::NotFound, "gate_spot:该交易所方法未实现".to_string())) }
|
|
|
|
|
-//
|
|
|
|
|
-// async fn get_ticker(&mut self) -> Result<Ticker, Error> { Err(Error::new(ErrorKind::NotFound, "gate_spot:该交易所方法未实现".to_string())) }
|
|
|
|
|
-//
|
|
|
|
|
-// async fn get_ticker_symbol(&mut self, _symbol: String) -> Result<Ticker, Error> { Err(Error::new(ErrorKind::NotFound, "gate_spot:该交易所方法未实现".to_string())) }
|
|
|
|
|
-//
|
|
|
|
|
-// async fn get_market(&mut self) -> Result<Market, Error> { Err(Error::new(ErrorKind::NotFound, "gate_spot:该交易所方法未实现".to_string())) }
|
|
|
|
|
-//
|
|
|
|
|
-// async fn get_market_symbol(&mut self, _symbol: String) -> Result<Market, Error> { Err(Error::new(ErrorKind::NotFound, "gate_spot:该交易所方法未实现".to_string())) }
|
|
|
|
|
-//
|
|
|
|
|
-// async fn get_order_detail(&mut self, _order_id: &str, _custom_id: &str) -> Result<Order, Error> { Err(Error::new(ErrorKind::NotFound, "gate_spot:该交易所方法未实现".to_string())) }
|
|
|
|
|
-//
|
|
|
|
|
-// async fn get_orders_list(&mut self, _status: &str) -> Result<Vec<Order>, Error> { Err(Error::new(ErrorKind::NotFound, "gate_spot:该交易所方法未实现".to_string())) }
|
|
|
|
|
-//
|
|
|
|
|
-// async fn take_order(&mut self, _custom_id: &str, _origin_side: &str, _price: Decimal, _amount: Decimal) -> Result<Order, Error> { Err(Error::new(ErrorKind::NotFound, "gate_spot:该交易所方法未实现".to_string())) }
|
|
|
|
|
-//
|
|
|
|
|
-// async fn take_order_symbol(&mut self, _symbol: String, _ct_val: Decimal, _custom_id: &str, _origin_side: &str, _price: Decimal, _amount: Decimal) -> Result<Order, Error> { Err(Error::new(ErrorKind::NotFound, "gate_spot:该交易所方法未实现".to_string())) }
|
|
|
|
|
-//
|
|
|
|
|
-// async fn cancel_order(&mut self, _order_id: &str, _custom_id: &str) -> Result<Order, Error> { Err(Error::new(ErrorKind::NotFound, "gate_spot:该交易所方法未实现".to_string())) }
|
|
|
|
|
-//
|
|
|
|
|
-// async fn cancel_orders(&mut self) -> Result<Vec<Order>, Error> { Err(Error::new(ErrorKind::NotFound, "gate_spot:该交易所方法未实现".to_string())) }
|
|
|
|
|
-//
|
|
|
|
|
-// async fn cancel_orders_all(&mut self) -> Result<Vec<Order>, Error> { Err(Error::new(ErrorKind::NotFound, "gate_spot:该交易所方法未实现".to_string())) }
|
|
|
|
|
-//
|
|
|
|
|
-// async fn set_dual_mode(&mut self, _coin: &str, _is_dual_mode: bool) -> Result<String, Error> { Err(Error::new(ErrorKind::NotFound, "gate_spot:该交易所方法未实现".to_string())) }
|
|
|
|
|
-//
|
|
|
|
|
-// async fn set_dual_leverage(&mut self, _leverage: &str) -> Result<String, Error> { Err(Error::new(ErrorKind::NotFound, "gate_spot:该交易所方法未实现".to_string())) }
|
|
|
|
|
-//
|
|
|
|
|
-// async fn set_auto_deposit_status(&mut self, _status: bool) -> Result<String, Error> { Err(Error::new(ErrorKind::NotFound, "gate_spot:该交易所方法未实现".to_string())) }
|
|
|
|
|
-//
|
|
|
|
|
-// async fn wallet_transfers(&mut self, _coin: &str, _from: &str, _to: &str, _amount: Decimal) -> Result<String, Error> { Err(Error::new(ErrorKind::NotFound, "gate_spot:该交易所方法未实现".to_string())) }
|
|
|
|
|
-//
|
|
|
|
|
-// async fn command_order(&mut self, _order_command: OrderCommand, _trace_stack: TraceStack) { warn!("gate_spot:该交易所方法未实现"); }
|
|
|
|
|
-// }
|
|
|
|
|
|
|
+use std::collections::BTreeMap;
|
|
|
|
|
+use std::io::{Error, ErrorKind};
|
|
|
|
|
+use std::str::FromStr;
|
|
|
|
|
+use tokio::sync::mpsc::Sender;
|
|
|
|
|
+use async_trait::async_trait;
|
|
|
|
|
+use rust_decimal::Decimal;
|
|
|
|
|
+use rust_decimal_macros::dec;
|
|
|
|
|
+use tracing::{error, warn};
|
|
|
|
|
+use crate::{Platform, ExchangeEnum, Account, Position, Ticker, Market, Order};
|
|
|
|
|
+use exchanges::gate_spot_rest::GateSpotRest;
|
|
|
|
|
+use rust_decimal::prelude::FromPrimitive;
|
|
|
|
|
+use serde_json::{json, Value};
|
|
|
|
|
+
|
|
|
|
|
+#[allow(dead_code)]
|
|
|
|
|
+#[derive(Clone)]
|
|
|
|
|
+pub struct GateSpot {
|
|
|
|
|
+ exchange: ExchangeEnum,
|
|
|
|
|
+ symbol: String,
|
|
|
|
|
+ is_colo: bool,
|
|
|
|
|
+ params: BTreeMap<String, String>,
|
|
|
|
|
+ request: GateSpotRest,
|
|
|
|
|
+ market: Market,
|
|
|
|
|
+ order_sender: Sender<Order>,
|
|
|
|
|
+ error_sender: Sender<Error>,
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+impl GateSpot {
|
|
|
|
|
+ pub async fn new(symbol: String, is_colo: bool, params: BTreeMap<String, String>, order_sender: Sender<Order>, error_sender: Sender<Error>) -> GateSpot {
|
|
|
|
|
+ let market = Market::new();
|
|
|
|
|
+ let mut gate_spot = GateSpot {
|
|
|
|
|
+ exchange: ExchangeEnum::GateSpot,
|
|
|
|
|
+ symbol: symbol.to_uppercase(),
|
|
|
|
|
+ is_colo,
|
|
|
|
|
+ params: params.clone(),
|
|
|
|
|
+ request: GateSpotRest::new(is_colo, params.clone()),
|
|
|
|
|
+ market,
|
|
|
|
|
+ order_sender,
|
|
|
|
|
+ error_sender,
|
|
|
|
|
+ };
|
|
|
|
|
+ gate_spot.market = GateSpot::get_market(&mut gate_spot).await.unwrap_or(gate_spot.market);
|
|
|
|
|
+ return gate_spot;
|
|
|
|
|
+ }
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+#[async_trait]
|
|
|
|
|
+impl Platform for GateSpot {
|
|
|
|
|
+ // 克隆方法
|
|
|
|
|
+ fn clone_box(&self) -> Box<dyn Platform + Send + Sync> { Box::new(self.clone()) }
|
|
|
|
|
+ // 获取交易所模式
|
|
|
|
|
+ fn get_self_exchange(&self) -> ExchangeEnum {
|
|
|
|
|
+ ExchangeEnum::GateSpot
|
|
|
|
|
+ }
|
|
|
|
|
+ // 获取交易对
|
|
|
|
|
+ fn get_self_symbol(&self) -> String { self.symbol.clone() }
|
|
|
|
|
+ // 获取是否使用高速通道
|
|
|
|
|
+ fn get_self_is_colo(&self) -> bool {
|
|
|
|
|
+ self.is_colo
|
|
|
|
|
+ }
|
|
|
|
|
+ // 获取params信息
|
|
|
|
|
+ fn get_self_params(&self) -> BTreeMap<String, String> {
|
|
|
|
|
+ self.params.clone()
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ fn get_self_market(&self) -> Market {
|
|
|
|
|
+ warn!("gate_spot:该交易所方法未实现");
|
|
|
|
|
+ return Market::new();
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ fn get_request_delays(&self) -> Vec<i64> {
|
|
|
|
|
+ warn!("gate_spot:该交易所方法未实现");
|
|
|
|
|
+ return vec![];
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ fn get_request_avg_delay(&self) -> Decimal {
|
|
|
|
|
+ warn!("gate_spot:该交易所方法未实现");
|
|
|
|
|
+ return dec!(0);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ fn get_request_max_delay(&self) -> i64 {
|
|
|
|
|
+ warn!("gate_spot:该交易所方法未实现");
|
|
|
|
|
+ return 0;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ async fn get_server_time(&mut self) -> Result<String, Error> { Err(Error::new(ErrorKind::NotFound, "gate_spot:该交易所方法未实现".to_string())) }
|
|
|
|
|
+
|
|
|
|
|
+ async fn get_account(&mut self) -> Result<Account, Error> { Err(Error::new(ErrorKind::NotFound, "gate_spot:该交易所方法未实现".to_string())) }
|
|
|
|
|
+
|
|
|
|
|
+ async fn get_spot_account(&mut self) -> Result<Vec<Account>, Error> { Err(Error::new(ErrorKind::NotFound, "gate_spot:该交易所方法未实现".to_string())) }
|
|
|
|
|
+
|
|
|
|
|
+ async fn get_position(&mut self) -> Result<Vec<Position>, Error> { Err(Error::new(ErrorKind::NotFound, "gate_spot:该交易所方法未实现".to_string())) }
|
|
|
|
|
+
|
|
|
|
|
+ async fn get_positions(&mut self) -> Result<Vec<Position>, Error> { Err(Error::new(ErrorKind::NotFound, "gate_spot:该交易所方法未实现".to_string())) }
|
|
|
|
|
+
|
|
|
|
|
+ async fn get_ticker(&mut self) -> Result<Ticker, Error> { Err(Error::new(ErrorKind::NotFound, "gate_spot:该交易所方法未实现".to_string())) }
|
|
|
|
|
+
|
|
|
|
|
+ async fn get_ticker_symbol(&mut self, _symbol: String) -> Result<Ticker, Error> { Err(Error::new(ErrorKind::NotFound, "gate_spot:该交易所方法未实现".to_string())) }
|
|
|
|
|
+
|
|
|
|
|
+ async fn get_market(&mut self) -> Result<Market, Error> {
|
|
|
|
|
+ let params = json!({});
|
|
|
|
|
+ let res_data = self.request.get_market_details(params).await;
|
|
|
|
|
+ if res_data.code == 200 {
|
|
|
|
|
+ let res_data_json = res_data.data.as_array().unwrap();
|
|
|
|
|
+ let market_info = res_data_json.iter().find(|item| item["id"].as_str().unwrap() == self.symbol);
|
|
|
|
|
+ match market_info {
|
|
|
|
|
+ None => {
|
|
|
|
|
+ error!("gate_swap:获取Market信息错误!\nget_market:res_data={:?}", res_data);
|
|
|
|
|
+ Err(Error::new(ErrorKind::Other, res_data.to_string()))
|
|
|
|
|
+ }
|
|
|
|
|
+ Some(value) => {
|
|
|
|
|
+ let symbol = value["id"].as_str().unwrap().to_string();
|
|
|
|
|
+ let base_asset = value["base"].as_str().unwrap().to_string();
|
|
|
|
|
+ let quote_asset = value["quote"].as_str().unwrap().to_string();
|
|
|
|
|
+ let tick_size = dec!(-1);
|
|
|
|
|
+ let amount_size = dec!(-1);
|
|
|
|
|
+ let price_precision = Decimal::from_f64(value["precision"].as_f64().unwrap()).unwrap();
|
|
|
|
|
+ let amount_precision = Decimal::from_f64(value["amount_precision"].as_f64().unwrap()).unwrap();
|
|
|
|
|
+ let min_qty = Decimal::from_str(value["min_base_amount"].as_str().unwrap()).unwrap();
|
|
|
|
|
+ let max_qty = Decimal::from_str(value["max_base_amount"].as_str().unwrap()).unwrap();
|
|
|
|
|
+ let min_notional = dec!(-1);
|
|
|
|
|
+ let max_notional = dec!(-1);
|
|
|
|
|
+ let ct_val = Decimal::ONE;
|
|
|
|
|
+
|
|
|
|
|
+ let result = Market {
|
|
|
|
|
+ symbol,
|
|
|
|
|
+ base_asset,
|
|
|
|
|
+ quote_asset,
|
|
|
|
|
+ tick_size,
|
|
|
|
|
+ amount_size,
|
|
|
|
|
+ price_precision,
|
|
|
|
|
+ amount_precision,
|
|
|
|
|
+ min_qty,
|
|
|
|
|
+ max_qty,
|
|
|
|
|
+ min_notional,
|
|
|
|
|
+ max_notional,
|
|
|
|
|
+ ct_val,
|
|
|
|
|
+ };
|
|
|
|
|
+ Ok(result)
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ } else {
|
|
|
|
|
+ Err(Error::new(ErrorKind::Other, res_data.to_string()))
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ async fn get_market_symbol(&mut self, _symbol: String) -> Result<Market, Error> { Err(Error::new(ErrorKind::NotFound, "gate_spot:该交易所方法未实现".to_string())) }
|
|
|
|
|
+
|
|
|
|
|
+ async fn get_order_detail(&mut self, _order_id: &str, _custom_id: &str) -> Result<Order, Error> { Err(Error::new(ErrorKind::NotFound, "gate_spot:该交易所方法未实现".to_string())) }
|
|
|
|
|
+
|
|
|
|
|
+ async fn get_orders_list(&mut self, _status: &str) -> Result<Vec<Order>, Error> { Err(Error::new(ErrorKind::NotFound, "gate_spot:该交易所方法未实现".to_string())) }
|
|
|
|
|
+
|
|
|
|
|
+ async fn take_order(&mut self, _custom_id: &str, _origin_side: &str, _price: Decimal, _amount: Decimal) -> Result<Order, Error> { Err(Error::new(ErrorKind::NotFound, "gate_spot:该交易所方法未实现".to_string())) }
|
|
|
|
|
+
|
|
|
|
|
+ async fn take_order_symbol(&mut self, _symbol: String, _ct_val: Decimal, _custom_id: &str, _origin_side: &str, _price: Decimal, _amount: Decimal) -> Result<Order, Error> { Err(Error::new(ErrorKind::NotFound, "gate_spot:该交易所方法未实现".to_string())) }
|
|
|
|
|
+
|
|
|
|
|
+ async fn cancel_order(&mut self, _order_id: &str, _custom_id: &str) -> Result<Order, Error> { Err(Error::new(ErrorKind::NotFound, "gate_spot:该交易所方法未实现".to_string())) }
|
|
|
|
|
+
|
|
|
|
|
+ async fn cancel_orders(&mut self) -> Result<Vec<Order>, Error> { Err(Error::new(ErrorKind::NotFound, "gate_spot:该交易所方法未实现".to_string())) }
|
|
|
|
|
+
|
|
|
|
|
+ async fn cancel_orders_all(&mut self) -> Result<Vec<Order>, Error> { Err(Error::new(ErrorKind::NotFound, "gate_spot:该交易所方法未实现".to_string())) }
|
|
|
|
|
+
|
|
|
|
|
+ async fn set_dual_mode(&mut self, _coin: &str, _is_dual_mode: bool) -> Result<String, Error> { Err(Error::new(ErrorKind::NotFound, "gate_spot:该交易所方法未实现".to_string())) }
|
|
|
|
|
+
|
|
|
|
|
+ async fn set_dual_leverage(&mut self, _leverage: &str) -> Result<String, Error> { Err(Error::new(ErrorKind::NotFound, "gate_spot:该交易所方法未实现".to_string())) }
|
|
|
|
|
+
|
|
|
|
|
+ async fn set_auto_deposit_status(&mut self, _status: bool) -> Result<String, Error> { Err(Error::new(ErrorKind::NotFound, "gate_spot:该交易所方法未实现".to_string())) }
|
|
|
|
|
+
|
|
|
|
|
+ async fn wallet_transfers(&mut self, _coin: &str, _from: &str, _to: &str, _amount: Decimal) -> Result<String, Error> { Err(Error::new(ErrorKind::NotFound, "gate_spot:该交易所方法未实现".to_string())) }
|
|
|
|
|
+
|
|
|
|
|
+ async fn take_stop_loss_order(&mut self, _stop_price: Decimal, _price: Decimal, _side: &str) -> Result<Value, Error> { Err(Error::new(ErrorKind::NotFound, "gate_spot:该交易所方法未实现".to_string())) }
|
|
|
|
|
+
|
|
|
|
|
+ async fn cancel_stop_loss_order(&mut self, _order_id: &str) -> Result<Value, Error> { Err(Error::new(ErrorKind::NotFound, "gate_spot:该交易所方法未实现".to_string())) }
|
|
|
|
|
+}
|