gate_spot.rs 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  1. // use std::collections::BTreeMap;
  2. // use std::io::{Error, ErrorKind};
  3. // use std::str::FromStr;
  4. // use tokio::sync::mpsc::Sender;
  5. // use async_trait::async_trait;
  6. // use rust_decimal::Decimal;
  7. // use rust_decimal_macros::dec;
  8. // use tracing::{error, warn};
  9. // use crate::{Platform, ExchangeEnum, Account, Position, Ticker, Market, Order};
  10. // use exchanges::gate_spot_rest::GateSpotRest;
  11. // use rust_decimal::prelude::FromPrimitive;
  12. // use serde_json::{json, Value};
  13. //
  14. // #[allow(dead_code)]
  15. // #[derive(Clone)]
  16. // pub struct GateSpot {
  17. // exchange: ExchangeEnum,
  18. // symbol: String,
  19. // is_colo: bool,
  20. // params: BTreeMap<String, String>,
  21. // request: GateSpotRest,
  22. // market: Market,
  23. // order_sender: Sender<Order>,
  24. // error_sender: Sender<Error>,
  25. // }
  26. //
  27. // impl GateSpot {
  28. // pub async fn new(symbol: String, is_colo: bool, params: BTreeMap<String, String>, order_sender: Sender<Order>, error_sender: Sender<Error>) -> GateSpot {
  29. // let market = Market::new();
  30. // let mut gate_spot = GateSpot {
  31. // exchange: ExchangeEnum::GateSpot,
  32. // symbol: symbol.to_uppercase(),
  33. // is_colo,
  34. // params: params.clone(),
  35. // request: GateSpotRest::new(is_colo, params.clone()),
  36. // market,
  37. // order_sender,
  38. // error_sender,
  39. // };
  40. // gate_spot.market = GateSpot::get_market(&mut gate_spot).await.unwrap_or(gate_spot.market);
  41. // return gate_spot;
  42. // }
  43. // }
  44. //
  45. // #[async_trait]
  46. // impl Platform for GateSpot {
  47. // // 克隆方法
  48. // fn clone_box(&self) -> Box<dyn Platform + Send + Sync> { Box::new(self.clone()) }
  49. // // 获取交易所模式
  50. // fn get_self_exchange(&self) -> ExchangeEnum {
  51. // ExchangeEnum::GateSpot
  52. // }
  53. // // 获取交易对
  54. // fn get_self_symbol(&self) -> String { self.symbol.clone() }
  55. // // 获取是否使用高速通道
  56. // fn get_self_is_colo(&self) -> bool {
  57. // self.is_colo
  58. // }
  59. // // 获取params信息
  60. // fn get_self_params(&self) -> BTreeMap<String, String> {
  61. // self.params.clone()
  62. // }
  63. //
  64. // fn get_self_market(&self) -> Market {
  65. // warn!("gate_spot:该交易所方法未实现");
  66. // return Market::new();
  67. // }
  68. //
  69. // fn get_request_delays(&self) -> Vec<i64> {
  70. // warn!("gate_spot:该交易所方法未实现");
  71. // return vec![];
  72. // }
  73. //
  74. // fn get_request_avg_delay(&self) -> Decimal {
  75. // warn!("gate_spot:该交易所方法未实现");
  76. // return dec!(0);
  77. // }
  78. //
  79. // fn get_request_max_delay(&self) -> i64 {
  80. // warn!("gate_spot:该交易所方法未实现");
  81. // return 0;
  82. // }
  83. //
  84. // async fn get_server_time(&mut self) -> Result<String, Error> { Err(Error::new(ErrorKind::NotFound, "gate_spot:该交易所方法未实现".to_string())) }
  85. //
  86. // async fn get_account(&mut self) -> Result<Account, Error> { Err(Error::new(ErrorKind::NotFound, "gate_spot:该交易所方法未实现".to_string())) }
  87. //
  88. // async fn get_spot_account(&mut self) -> Result<Vec<Account>, Error> { Err(Error::new(ErrorKind::NotFound, "gate_spot:该交易所方法未实现".to_string())) }
  89. //
  90. // async fn get_position(&mut self) -> Result<Vec<Position>, Error> { Err(Error::new(ErrorKind::NotFound, "gate_spot:该交易所方法未实现".to_string())) }
  91. //
  92. // async fn get_positions(&mut self) -> Result<Vec<Position>, Error> { Err(Error::new(ErrorKind::NotFound, "gate_spot:该交易所方法未实现".to_string())) }
  93. //
  94. // async fn get_ticker(&mut self) -> Result<Ticker, Error> { Err(Error::new(ErrorKind::NotFound, "gate_spot:该交易所方法未实现".to_string())) }
  95. //
  96. // async fn get_ticker_symbol(&mut self, _symbol: String) -> Result<Ticker, Error> { Err(Error::new(ErrorKind::NotFound, "gate_spot:该交易所方法未实现".to_string())) }
  97. //
  98. // async fn get_market(&mut self) -> Result<Market, Error> {
  99. // let params = json!({});
  100. // let res_data = self.request.get_market_details(params).await;
  101. // if res_data.code == 200 {
  102. // let res_data_json = res_data.data.as_array().unwrap();
  103. // let market_info = res_data_json.iter().find(|item| item["id"].as_str().unwrap() == self.symbol);
  104. // match market_info {
  105. // None => {
  106. // error!("gate_swap:获取Market信息错误!\nget_market:res_data={:?}", res_data);
  107. // Err(Error::new(ErrorKind::Other, res_data.to_string()))
  108. // }
  109. // Some(value) => {
  110. // let symbol = value["id"].as_str().unwrap().to_string();
  111. // let base_asset = value["base"].as_str().unwrap().to_string();
  112. // let quote_asset = value["quote"].as_str().unwrap().to_string();
  113. // let tick_size = dec!(-1);
  114. // let amount_size = dec!(-1);
  115. // let price_precision = Decimal::from_f64(value["precision"].as_f64().unwrap()).unwrap();
  116. // let amount_precision = Decimal::from_f64(value["amount_precision"].as_f64().unwrap()).unwrap();
  117. // let min_qty = Decimal::from_str(value["min_base_amount"].as_str().unwrap()).unwrap();
  118. // let max_qty = Decimal::from_str(value["max_base_amount"].as_str().unwrap()).unwrap();
  119. // let min_notional = dec!(-1);
  120. // let max_notional = dec!(-1);
  121. // let ct_val = Decimal::ONE;
  122. //
  123. // let result = Market {
  124. // symbol,
  125. // base_asset,
  126. // quote_asset,
  127. // tick_size,
  128. // amount_size,
  129. // price_precision,
  130. // amount_precision,
  131. // min_qty,
  132. // max_qty,
  133. // min_notional,
  134. // max_notional,
  135. // ct_val,
  136. // };
  137. // Ok(result)
  138. // }
  139. // }
  140. // } else {
  141. // Err(Error::new(ErrorKind::Other, res_data.to_string()))
  142. // }
  143. // }
  144. //
  145. // async fn get_market_symbol(&mut self, _symbol: String) -> Result<Market, Error> { Err(Error::new(ErrorKind::NotFound, "gate_spot:该交易所方法未实现".to_string())) }
  146. //
  147. // 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())) }
  148. //
  149. // async fn get_orders_list(&mut self, _status: &str) -> Result<Vec<Order>, Error> { Err(Error::new(ErrorKind::NotFound, "gate_spot:该交易所方法未实现".to_string())) }
  150. //
  151. // 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())) }
  152. //
  153. // 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())) }
  154. //
  155. // async fn cancel_order(&mut self, _order_id: &str, _custom_id: &str) -> Result<Order, Error> { Err(Error::new(ErrorKind::NotFound, "gate_spot:该交易所方法未实现".to_string())) }
  156. //
  157. // async fn cancel_orders(&mut self) -> Result<Vec<Order>, Error> { Err(Error::new(ErrorKind::NotFound, "gate_spot:该交易所方法未实现".to_string())) }
  158. //
  159. // async fn cancel_orders_all(&mut self) -> Result<Vec<Order>, Error> { Err(Error::new(ErrorKind::NotFound, "gate_spot:该交易所方法未实现".to_string())) }
  160. //
  161. // 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())) }
  162. //
  163. // async fn set_dual_leverage(&mut self, _leverage: &str) -> Result<String, Error> { Err(Error::new(ErrorKind::NotFound, "gate_spot:该交易所方法未实现".to_string())) }
  164. //
  165. // async fn set_auto_deposit_status(&mut self, _status: bool) -> Result<String, Error> { Err(Error::new(ErrorKind::NotFound, "gate_spot:该交易所方法未实现".to_string())) }
  166. //
  167. // 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())) }
  168. //
  169. // 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())) }
  170. //
  171. // async fn cancel_stop_loss_order(&mut self, _order_id: &str) -> Result<Value, Error> { Err(Error::new(ErrorKind::NotFound, "gate_spot:该交易所方法未实现".to_string())) }
  172. // }