gate_spot.rs 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. use std::collections::BTreeMap;
  2. use std::io::{Error, ErrorKind};
  3. use async_trait::async_trait;
  4. use rust_decimal::Decimal;
  5. use rust_decimal_macros::dec;
  6. use tracing::warn;
  7. use crate::{Platform, ExchangeEnum, Account, Position, Ticker, Market, Order, OrderCommand};
  8. use exchanges::gate_spot_rest::GateSpotRest;
  9. use global::trace_stack::TraceStack;
  10. #[allow(dead_code)]
  11. #[derive(Clone)]
  12. pub struct GateSpot {
  13. exchange: ExchangeEnum,
  14. symbol: String,
  15. is_colo: bool,
  16. params: BTreeMap<String, String>,
  17. request: GateSpotRest,
  18. }
  19. impl GateSpot {
  20. pub fn new(symbol: String, is_colo: bool, params: BTreeMap<String, String>) -> GateSpot {
  21. GateSpot {
  22. exchange: ExchangeEnum::GateSpot,
  23. symbol: symbol.to_uppercase(),
  24. is_colo,
  25. params: params.clone(),
  26. request: GateSpotRest::new(is_colo, params.clone()),
  27. }
  28. }
  29. }
  30. #[async_trait]
  31. impl Platform for GateSpot {
  32. // 克隆方法
  33. fn clone_box(&self) -> Box<dyn Platform + Send + Sync> { Box::new(self.clone()) }
  34. // 获取交易所模式
  35. fn get_self_exchange(&self) -> ExchangeEnum {
  36. ExchangeEnum::GateSpot
  37. }
  38. // 获取交易对
  39. fn get_self_symbol(&self) -> String { self.symbol.clone() }
  40. // 获取是否使用高速通道
  41. fn get_self_is_colo(&self) -> bool {
  42. self.is_colo
  43. }
  44. // 获取params信息
  45. fn get_self_params(&self) -> BTreeMap<String, String> {
  46. self.params.clone()
  47. }
  48. fn get_self_market(&self) -> Market {
  49. warn!("gate_spot:该交易所方法未实现");
  50. return Market::new();
  51. }
  52. fn get_request_delays(&self) -> Vec<i64> {
  53. warn!("gate_spot:该交易所方法未实现");
  54. return vec![];
  55. }
  56. fn get_request_avg_delay(&self) -> Decimal {
  57. warn!("gate_spot:该交易所方法未实现");
  58. return dec!(0);
  59. }
  60. fn get_request_max_delay(&self) -> i64 {
  61. warn!("gate_spot:该交易所方法未实现");
  62. return 0;
  63. }
  64. async fn get_server_time(&mut self) -> Result<String, Error> { Err(Error::new(ErrorKind::NotFound, "gate_spot:该交易所方法未实现".to_string())) }
  65. async fn get_account(&mut self) -> Result<Account, Error> { Err(Error::new(ErrorKind::NotFound, "gate_spot:该交易所方法未实现".to_string())) }
  66. async fn get_spot_account(&mut self) -> Result<Vec<Account>, Error> { Err(Error::new(ErrorKind::NotFound, "gate_spot:该交易所方法未实现".to_string())) }
  67. async fn get_position(&mut self) -> Result<Vec<Position>, Error> { Err(Error::new(ErrorKind::NotFound, "gate_spot:该交易所方法未实现".to_string())) }
  68. async fn get_positions(&mut self) -> Result<Vec<Position>, Error> { Err(Error::new(ErrorKind::NotFound, "gate_spot:该交易所方法未实现".to_string())) }
  69. async fn get_ticker(&mut self) -> Result<Ticker, Error> { Err(Error::new(ErrorKind::NotFound, "gate_spot:该交易所方法未实现".to_string())) }
  70. async fn get_ticker_symbol(&mut self, _symbol: String) -> Result<Ticker, Error> { Err(Error::new(ErrorKind::NotFound, "gate_spot:该交易所方法未实现".to_string())) }
  71. async fn get_market(&mut self) -> Result<Market, Error> { Err(Error::new(ErrorKind::NotFound, "gate_spot:该交易所方法未实现".to_string())) }
  72. async fn get_market_symbol(&mut self, _symbol: String) -> Result<Market, Error> { Err(Error::new(ErrorKind::NotFound, "gate_spot:该交易所方法未实现".to_string())) }
  73. 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())) }
  74. async fn get_orders_list(&mut self, _status: &str) -> Result<Vec<Order>, Error> { Err(Error::new(ErrorKind::NotFound, "gate_spot:该交易所方法未实现".to_string())) }
  75. 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())) }
  76. 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())) }
  77. async fn cancel_order(&mut self, _order_id: &str, _custom_id: &str) -> Result<Order, Error> { Err(Error::new(ErrorKind::NotFound, "gate_spot:该交易所方法未实现".to_string())) }
  78. async fn cancel_orders(&mut self) -> Result<Vec<Order>, Error> { Err(Error::new(ErrorKind::NotFound, "gate_spot:该交易所方法未实现".to_string())) }
  79. async fn cancel_orders_all(&mut self) -> Result<Vec<Order>, Error> { Err(Error::new(ErrorKind::NotFound, "gate_spot:该交易所方法未实现".to_string())) }
  80. 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())) }
  81. async fn set_dual_leverage(&mut self, _leverage: &str) -> Result<String, Error> { Err(Error::new(ErrorKind::NotFound, "gate_spot:该交易所方法未实现".to_string())) }
  82. async fn set_auto_deposit_status(&mut self, _status: bool) -> Result<String, Error> { Err(Error::new(ErrorKind::NotFound, "gate_spot:该交易所方法未实现".to_string())) }
  83. 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())) }
  84. async fn command_order(&mut self, _order_command: OrderCommand, _trace_stack: TraceStack) { warn!("gate_spot:该交易所方法未实现"); }
  85. }