Explorar o código

bitmart接入提交 暂未通

JiahengHe hai 1 ano
pai
achega
535f9f2860

+ 2 - 2
exchanges/src/bitmart_swap_rest.rs

@@ -242,8 +242,8 @@ impl BitMartSwapRest {
         if self.login_param.contains_key("secret_key") {
             secret_key = self.login_param.get("secret_key").unwrap().to_string();
         }
-        if self.login_param.contains_key("api_memo") {
-            api_memo = self.login_param.get("api_memo").unwrap().to_string();
+        if self.login_param.contains_key("pass_key") {
+            api_memo = self.login_param.get("pass_key").unwrap().to_string();
         }
         let mut is_login_param = true;
         if access_key == "" || secret_key == "" {

+ 1 - 0
global/src/public_params.rs

@@ -31,4 +31,5 @@ pub const BITGET_USDT_SWAP_LIMIT:i64 = 10;
 pub const BITGET_USDT_SPOT_LIMIT:i64 = 100;
 pub const BYBIT_USDT_SWAP_LIMIT:i64 = 10;
 pub const MEXC_SPOT_LIMIT:i64 = 333;
+pub const BITMART_USDT_SWAP_LIMIT:i64 = 12;
 pub const RATIO:i64 = 4;

+ 25 - 3
standard/src/bitmart_swap.rs

@@ -12,7 +12,7 @@ use serde_json::json;
 use serde_json::Value::Null;
 use tokio::spawn;
 use tokio::time::Instant;
-use tracing::{error, info};
+use tracing::{error, info, trace};
 use global::trace_stack::TraceStack;
 use crate::exchange::ExchangeEnum;
 use crate::{Account, Market, Order, OrderCommand, Platform, Position, PositionModeEnum, Ticker, utils};
@@ -177,8 +177,29 @@ impl Platform for BitmartSwap {
         return self.get_ticker_symbol(self.symbol.clone()).await;
     }
 
-    async fn get_ticker_symbol(&mut self, _symbol: String) -> Result<Ticker, Error> {
-        Err(Error::new(ErrorKind::NotFound, "bitmart_swap get_ticker_symbol:该交易所方法未实现".to_string()))
+    async fn get_ticker_symbol(&mut self, symbol: String) -> Result<Ticker, Error> {
+        let symbol_format = utils::format_symbol(symbol, "");
+        let params = json!({
+            "symbol": symbol_format
+        });
+        let response = self.request.get_depth(params).await;
+        if response.code != 200 {
+            return Err(Error::new(ErrorKind::NotFound, format!("bitmart_swap 获取Ticker异常{:?}", response).to_string()));
+        }
+        let res_data_json = response.data;
+        let ask = Decimal::from_str(res_data_json["asks"][0][0].as_str().unwrap()).unwrap();
+        let bid =  Decimal::from_str(res_data_json["bids"][0][0].as_str().unwrap()).unwrap();
+        let time = res_data_json["timestamp"].as_i64().unwrap();
+        Ok(Ticker{
+            time,
+            high: Default::default(),
+            low: Default::default(),
+            sell: ask,
+            buy: bid,
+            last: Default::default(),
+            volume: Default::default(),
+        })
+
     }
 
     async fn get_market(&mut self) -> Result<Market, Error> {
@@ -373,6 +394,7 @@ impl Platform for BitmartSwap {
         let params = json!({
             "symbol": symbol_format,
         });
+        trace!("撤销所有订单参数 {}", params);
         let response = self.request.cancel_price_order(params).await;
         if response.code != 200 {
             return Err(Error::new(ErrorKind::NotFound, format!("bitmart_swap 撤销所有订单异常{:?}", response).to_string()));

+ 4 - 1
strategy/src/core.rs

@@ -22,7 +22,7 @@ use global::public_params::{ASK_PRICE_INDEX, BID_PRICE_INDEX, LENGTH};
 use global::trace_stack::TraceStack;
 use standard::{Account, Market, Order, OrderCommand, Platform, Position, PositionModeEnum, SpecialTicker, Ticker};
 use standard::exchange::{Exchange};
-use standard::exchange::ExchangeEnum::{BinanceSwap, BitgetSwap, BybitSwap, CoinexSwap, GateSwap, KucoinSwap};
+use standard::exchange::ExchangeEnum::{BinanceSwap, BitgetSwap, BitmartSwap, BybitSwap, CoinexSwap, GateSwap, KucoinSwap};
 
 use crate::model::{LocalPosition, OrderInfo, TokenParam};
 use crate::predictor::Predictor;
@@ -233,6 +233,9 @@ impl Core {
                 "coinex_usdt_swap" => {
                     Exchange::new(CoinexSwap, symbol, params.colo != 0i8, exchange_params, order_sender, error_sender).await
                 }
+                "bitmart_usdt_swap" => {
+                    Exchange::new(BitmartSwap, symbol, params.colo != 0i8, exchange_params, order_sender, error_sender).await
+                }
                 _ => {
                     error!("203未找到对应的交易所rest枚举!");
                     panic!("203未找到对应的交易所rest枚举!");

+ 8 - 8
strategy/src/exchange_disguise.rs

@@ -31,7 +31,7 @@ pub async fn run_transactional_exchange(is_shutdown_arc :Arc<AtomicBool>,
     match exchange_name.as_str() {
         "gate_usdt_swap" => {
             gate_swap_run(is_shutdown_arc, true, core_arc, name, symbols, is_colo, exchange_params).await;
-        }
+        },
         "kucoin_usdt_swap" => {
             kucoin_swap_run(is_shutdown_arc, true, core_arc, name, symbols, is_colo, exchange_params).await;
         },
@@ -43,17 +43,17 @@ pub async fn run_transactional_exchange(is_shutdown_arc :Arc<AtomicBool>,
         // },
         "bitget_usdt_swap" => {
             bitget_usdt_swap_run(is_shutdown_arc, true, core_arc, name, symbols, is_colo, exchange_params).await;
-        }
+        },
         "bybit_usdt_swap" => {
             bybit_swap_run(is_shutdown_arc,true, core_arc, name, symbols, is_colo, exchange_params).await;
-        }
+        },
         "coinex_usdt_swap" => {
             tokio::time::sleep(Duration::from_secs(1)).await;
             coinex_swap_run(is_shutdown_arc,true, core_arc, name, symbols, is_colo, exchange_params).await;
-        }
+        },
         "bitmart_usdt_sawp" => {
             bitmart_usdt_swap_run(is_shutdown_arc, true, core_arc, name, symbols, is_colo, exchange_params).await;
-        }
+        },
         _ => {
             let msg = format!("不支持的交易交易所:{}", exchange_name);
             panic!("{}", msg);
@@ -93,16 +93,16 @@ pub async fn run_reference_exchange(is_shutdown_arc: Arc<AtomicBool>,
         // },
         "bitget_usdt_swap" => {
             bitget_usdt_swap_run(is_shutdown_arc, false, core_arc, name, symbols, is_colo, exchange_params).await;
-        }
+        },
         "bybit_usdt_swap" => {
             bybit_swap_run(is_shutdown_arc, false, core_arc, name, symbols, is_colo, exchange_params).await;
         },
         "coinex_usdt_swap" => {
             coinex_swap_run(is_shutdown_arc,false, core_arc, name, symbols, is_colo, exchange_params).await;
-        }
+        },
         "bitmart_usdt_sawp" => {
             bitmart_usdt_swap_run(is_shutdown_arc, false, core_arc, name, symbols, is_colo, exchange_params).await;
-        }
+        },
         _ => {
             let msg = format!("不支持的参考交易所:{}", exchange_name);
             panic!("{}", msg);

+ 4 - 0
strategy/src/utils.rs

@@ -69,6 +69,8 @@ pub fn get_limit_requests_num_per_second(exchange: String) -> i64 {
         return public_params::BITGET_USDT_SWAP_LIMIT * public_params::RATIO;
     } else if exchange.eq("bybit_usdt_swap"){
         return public_params::BYBIT_USDT_SWAP_LIMIT * public_params::RATIO;
+    } else if exchange.eq("bitmart_usdt_swap"){
+        return public_params::BITMART_USDT_SWAP_LIMIT * public_params::RATIO;
     } else {
         error!("限频规则(ratio)未找到,请检查配置!");
         panic!("限频规则(ratio)未找到,请检查配置!");
@@ -101,6 +103,8 @@ pub fn get_limit_order_requests_num_per_second(exchange: String) -> i64 {
         return public_params::BITGET_USDT_SWAP_LIMIT
     } else if exchange.eq("bybit_usdt_swap") {
         return public_params::BYBIT_USDT_SWAP_LIMIT
+    } else if exchange.eq("bitmart_usdt_swap") {
+        return public_params::BITMART_USDT_SWAP_LIMIT;
     } else {
         error!("限频规则(limit)未找到,请检查配置!");
         panic!("限频规则(limit)未找到,请检查配置!");