|
|
@@ -1,5 +1,4 @@
|
|
|
use std::collections::BTreeMap;
|
|
|
-use std::str::FromStr;
|
|
|
use std::sync::Arc;
|
|
|
use std::sync::atomic::AtomicBool;
|
|
|
use std::time::Duration;
|
|
|
@@ -12,7 +11,7 @@ use tokio::time::sleep;
|
|
|
use tracing::{error, info};
|
|
|
use exchanges::binance_spot_ws::{BinanceSpotSubscribeType, BinanceSpotWs, BinanceSpotWsType};
|
|
|
use exchanges::binance_swap_ws::{BinanceSubscribeType, BinanceSwapWs, BinanceWsType};
|
|
|
-use exchanges::bitget_spot_ws::{BitgetSpotWs, BitgetSubscribeType};
|
|
|
+use exchanges::bitget_spot_ws::{BitgetSpotWs, BitgetSubscribeType, BitgetWsType};
|
|
|
use exchanges::gate_swap_rest::GateSwapRest;
|
|
|
use exchanges::gate_swap_ws::{GateSubscribeType, GateSwapWs, GateWsType};
|
|
|
use exchanges::kucoin_swap_ws::{KucoinSubscribeType, KucoinSwapWs, KucoinWsType};
|
|
|
@@ -68,7 +67,10 @@ pub async fn run_reference_exchange(bool_v1 :Arc<AtomicBool>, exchange_name: Str
|
|
|
async fn gate_swap_run(bool_v1 :Arc<AtomicBool>, type_num: i8, quant_arc: Arc<Mutex<Quant>>, name: String, symbols: Vec<String>, exchange_params: BTreeMap<String, String>){
|
|
|
let (tx, mut rx) = channel(100);
|
|
|
let mut gate_exc = GateSwapRest::new(false, exchange_params.clone());
|
|
|
- let user_id;
|
|
|
+ let mut user_id= "".to_string();
|
|
|
+ let symbols_one = symbols.clone();
|
|
|
+
|
|
|
+ // 交易
|
|
|
if type_num == 1{
|
|
|
// 获取user_id
|
|
|
let res_data = gate_exc.wallet_fee().await;
|
|
|
@@ -79,21 +81,6 @@ async fn gate_swap_run(bool_v1 :Arc<AtomicBool>, type_num: i8, quant_arc: Arc<Mu
|
|
|
user_id = wallet_obj["user_id"].to_string();
|
|
|
}
|
|
|
|
|
|
- let symbols_one = symbols.clone();
|
|
|
- // 获取乘数(计价货币兑换为结算货币的乘数)
|
|
|
- let response = gate_exc.get_market_details("usdt".to_string()).await;
|
|
|
- assert_eq!(response.code, "200", "获取gate交易所参数 multiplier 失败, 启动失败!");
|
|
|
-
|
|
|
- let contract_obj :Vec<Value> = parse_json_array(&response.data).unwrap();
|
|
|
- let mut multiplier = Decimal::ZERO;
|
|
|
- for val in contract_obj {
|
|
|
- if symbols[0].to_uppercase() == val["name"].as_str().unwrap(){
|
|
|
- let num = val["quanto_multiplier"].as_str().unwrap();
|
|
|
- multiplier = Decimal::from_str(num).unwrap();
|
|
|
- }
|
|
|
- }
|
|
|
- assert_ne!(multiplier, Decimal::ZERO, "获取gate交易所参数 multiplier 为0!");
|
|
|
-
|
|
|
spawn( async move {
|
|
|
let mut gate_exc = GateSwapWs::new_label(name, false, exchange_params,
|
|
|
GateWsType::PublicAndPrivate("usdt".to_string()), tx);
|
|
|
@@ -116,6 +103,7 @@ async fn gate_swap_run(bool_v1 :Arc<AtomicBool>, type_num: i8, quant_arc: Arc<Mu
|
|
|
});
|
|
|
spawn(async move {
|
|
|
let bot_arc_clone = Arc::clone(&quant_arc);
|
|
|
+ let multiplier = bot_arc_clone.lock().await.platform_rest.get_self_market().amount_size;
|
|
|
let run_symbol = symbols.clone()[0].clone();
|
|
|
// trade
|
|
|
let mut max_buy = Decimal::ZERO;
|
|
|
@@ -548,23 +536,28 @@ async fn reference_binance_swap_run(bool_v1 :Arc<AtomicBool>, quant_arc: Arc<Mut
|
|
|
|
|
|
async fn bitget_spot_run(bool_v1 :Arc<AtomicBool>, type_num: i8, quant_arc: Arc<Mutex<Quant>>, name: String, symbols: Vec<String>, exchange_params: BTreeMap<String, String>) {
|
|
|
let (tx, mut rx) = channel(100);
|
|
|
+ let symbols_1 = symbols.clone();
|
|
|
spawn( async move {
|
|
|
- let mut bit_exc = BitgetSpotWs::new_label(name, false, exchange_params, BitgetSpot::PublicAndPrivate, tx);
|
|
|
+ let mut bit_exc_public = BitgetSpotWs::new_label(name.clone(), false, exchange_params.clone(), BitgetWsType::Public, tx.clone());
|
|
|
+ let mut bit_exc_private = BitgetSpotWs::new_label(name, false, exchange_params, BitgetWsType::Private, tx);
|
|
|
// 交易
|
|
|
if type_num == 1 {
|
|
|
- bit_exc.set_subscribe(vec![
|
|
|
- BitgetSubscribeType::PuTrade,
|
|
|
- BitgetSubscribeType::PuBooks5,
|
|
|
+ bit_exc_private.set_subscribe(vec![
|
|
|
BitgetSubscribeType::PrAccount,
|
|
|
BitgetSubscribeType::PrOrders
|
|
|
]);
|
|
|
+ bit_exc_public.set_subscribe(vec![
|
|
|
+ BitgetSubscribeType::PuTrade,
|
|
|
+ BitgetSubscribeType::PuBooks5
|
|
|
+ ]);
|
|
|
} else { // 参考
|
|
|
- bit_exc.set_subscribe(vec![
|
|
|
+ bit_exc_public.set_subscribe(vec![
|
|
|
BitgetSubscribeType::PuTrade,
|
|
|
BitgetSubscribeType::PuBooks5
|
|
|
]);
|
|
|
}
|
|
|
- bit_exc.custom_subscribe(bool_v1, symbols.clone()).await;
|
|
|
+ bit_exc_public.custom_subscribe(bool_v1.clone(), symbols_1.clone()).await;
|
|
|
+ bit_exc_private.custom_subscribe(bool_v1, symbols_1).await;
|
|
|
});
|
|
|
spawn(async move {
|
|
|
let bot_arc_clone = Arc::clone(&quant_arc);
|
|
|
@@ -660,10 +653,4 @@ async fn bitget_spot_run(bool_v1 :Arc<AtomicBool>, type_num: i8, quant_arc: Arc<
|
|
|
}
|
|
|
}
|
|
|
});
|
|
|
-}
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-fn parse_json_array(json: &str) -> serde_json::Result<Vec<Value>> {
|
|
|
- serde_json::from_str(json)
|
|
|
}
|