|
|
@@ -29,7 +29,7 @@ pub enum BinanceSwapSubscribeType {
|
|
|
|
|
|
PrAccount,
|
|
|
PrBalance,
|
|
|
- PrPosition
|
|
|
+ PrPosition,
|
|
|
}
|
|
|
|
|
|
//账号信息
|
|
|
@@ -40,13 +40,7 @@ pub struct BinanceSwapLogin {
|
|
|
pub api_secret: String,
|
|
|
}
|
|
|
|
|
|
-//login
|
|
|
-#[derive(Clone)]
|
|
|
-#[allow(dead_code)]
|
|
|
-pub struct BinanceSwapLoginLinLink {
|
|
|
- listenKey: String,
|
|
|
- out_time: i64,
|
|
|
-}
|
|
|
+
|
|
|
|
|
|
#[derive(Clone)]
|
|
|
#[allow(dead_code)]
|
|
|
@@ -57,8 +51,6 @@ pub struct BinanceSwapWs {
|
|
|
address_url: String,
|
|
|
//账号
|
|
|
login_param: Option<BinanceSwapLogin>,
|
|
|
- //link _param
|
|
|
- link_param: BinanceSwapLoginLinLink,
|
|
|
//币对
|
|
|
symbol_s: Vec<String>,
|
|
|
//订阅
|
|
|
@@ -76,10 +68,6 @@ impl BinanceSwapWs {
|
|
|
return BinanceSwapWs::new_label("default-BinanceSwapWs".to_string(), is_colo, login_param, ws_type).await;
|
|
|
}
|
|
|
pub async fn new_label(label: String, is_colo: bool, login_param: Option<BinanceSwapLogin>, ws_type: BinanceSwapWsType) -> BinanceSwapWs {
|
|
|
- let mut link_param = BinanceSwapLoginLinLink {
|
|
|
- listenKey: "".to_string(),
|
|
|
- out_time: 0,
|
|
|
- };
|
|
|
/*******公共频道-私有频道数据组装*/
|
|
|
let address_url = match ws_type {
|
|
|
BinanceSwapWsType::Public => {
|
|
|
@@ -88,30 +76,6 @@ impl BinanceSwapWs {
|
|
|
}
|
|
|
BinanceSwapWsType::Private => {
|
|
|
"wss://fstream.binance.com/ws/".to_string()
|
|
|
- // match login_param.clone() {
|
|
|
- // None => {
|
|
|
- // "wss://fstream.binance.com/stream".to_string()
|
|
|
- // }
|
|
|
- // Some(dto) => {
|
|
|
- // let mut btree_map: BTreeMap<String, String> = BTreeMap::new();
|
|
|
- // btree_map.insert("access_key".to_string(), dto.api_key.clone());
|
|
|
- // btree_map.insert("secret_key".to_string(), dto.api_secret.clone());
|
|
|
- //
|
|
|
- // let mut ba_exc = BinanceSwapRest::new(false, btree_map);
|
|
|
- // let rep_data = ba_exc.close_listen_key(json!({ })).await;
|
|
|
- // if (rep_data.code == 200) {
|
|
|
- // let listenKey = rep_data.data["listenKey"].as_str().unwrap();
|
|
|
- // trace!("拿到-data:{}",rep_data.data.clone());
|
|
|
- // trace!("拿到-listenKey:{}",listenKey.clone());
|
|
|
- // link_param.listenKey = listenKey.to_string();
|
|
|
- // link_param.out_time = chrono::Utc::now().timestamp_millis() + (1000 * 60 * 55);
|
|
|
- // format!("wss://fstream.binance.com/ws/{}", listenKey)
|
|
|
- // } else {
|
|
|
- // error!("binance_usdt_swap socket get listenKey, is error");
|
|
|
- // "".to_string()
|
|
|
- // }
|
|
|
- // }
|
|
|
- // }
|
|
|
}
|
|
|
};
|
|
|
|
|
|
@@ -125,7 +89,6 @@ impl BinanceSwapWs {
|
|
|
label,
|
|
|
address_url,
|
|
|
login_param,
|
|
|
- link_param,
|
|
|
symbol_s: vec![],
|
|
|
subscribe_types: vec![],
|
|
|
heartbeat_time: 1000 * 20,
|
|
|
@@ -160,7 +123,7 @@ impl BinanceSwapWs {
|
|
|
|
|
|
BinanceSwapSubscribeType::PrAccount => { true }
|
|
|
BinanceSwapSubscribeType::PrBalance => { true }
|
|
|
- BinanceSwapSubscribeType::PrPosition => {true}
|
|
|
+ BinanceSwapSubscribeType::PrPosition => { true }
|
|
|
} {
|
|
|
return true;
|
|
|
}
|
|
|
@@ -222,13 +185,13 @@ impl BinanceSwapWs {
|
|
|
for symbol in &self.symbol_s {
|
|
|
for subscribe_type in &self.subscribe_types {
|
|
|
let ty_str = Self::enum_to_string_pu(symbol.clone(), subscribe_type.clone());
|
|
|
- if (ty_str != "".to_string()) {
|
|
|
+ if ty_str != "".to_string() {
|
|
|
params.push(ty_str);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- if (params.len() > 0) {
|
|
|
+ if params.len() > 0 {
|
|
|
let str = json!({
|
|
|
"method": "SUBSCRIBE",
|
|
|
"params": params,
|
|
|
@@ -243,7 +206,7 @@ impl BinanceSwapWs {
|
|
|
let mut params = vec![];
|
|
|
for subscribe_type in &self.subscribe_types {
|
|
|
let ty_str = Self::enum_to_string_pr(subscribe_type.clone());
|
|
|
- if (ty_str != "".to_string()) {
|
|
|
+ if ty_str != "".to_string() {
|
|
|
params.push(ty_str);
|
|
|
}
|
|
|
}
|
|
|
@@ -270,17 +233,16 @@ impl BinanceSwapWs {
|
|
|
handle_function: F,
|
|
|
_write_tx_am: &Arc<Mutex<UnboundedSender<Message>>>,
|
|
|
write_to_socket_rx: UnboundedReceiver<Message>) -> Result<(), Error>
|
|
|
- where
|
|
|
- F: Fn(ResponseData) -> Future + Clone + Send + 'static + Sync,
|
|
|
- Future: std::future::Future<Output=()> + Send + 'static, // 确保 Fut 是一个 Future,且输出类型为 ()
|
|
|
+ where
|
|
|
+ F: Fn(ResponseData) -> Future + Clone + Send + 'static + Sync,
|
|
|
+ Future: std::future::Future<Output=()> + Send + 'static, // 确保 Fut 是一个 Future,且输出类型为 ()
|
|
|
{
|
|
|
let login_is = self.contains_pr();
|
|
|
- let link_param = self.link_param.clone();
|
|
|
let subscription_pu = self.get_subscription_pu();
|
|
|
let subscription_pr = self.get_subscription_pr();
|
|
|
let address_url = self.address_url.clone();
|
|
|
let label = self.label.clone();
|
|
|
- let heartbeat_time = self.heartbeat_time.clone();
|
|
|
+ // let heartbeat_time: u64 = self.heartbeat_time.clone();
|
|
|
let login_param_dto = self.login_param.clone();
|
|
|
|
|
|
|
|
|
@@ -318,13 +280,13 @@ impl BinanceSwapWs {
|
|
|
|
|
|
let mut ba_exc = BinanceSwapRest::new(false, btree_map);
|
|
|
let rep_data = ba_exc.get_listen_key(json!({ })).await;
|
|
|
- trace!("拿到-rep_data:{:?}",rep_data) ;
|
|
|
- if (rep_data.code == 200) {
|
|
|
- let listenKey = rep_data.data["listenKey"].as_str().unwrap();
|
|
|
- trace!("拿到-data:{}",rep_data.data.clone());
|
|
|
- trace!("拿到-listenKey:{}",listenKey.clone());
|
|
|
+ trace!("拿到-rep_data:{:?}",rep_data);
|
|
|
+ if rep_data.code == 200 {
|
|
|
+ let listen_key_str = rep_data.data["listenKey"].as_str().unwrap();
|
|
|
+ // trace!("拿到-data:{}",rep_data.data.clone());
|
|
|
+ // trace!("拿到-listenKey:{}",listen_key_str.clone());
|
|
|
// format!("{}{}", address_url.clone(), listenKey
|
|
|
- listenKey.to_string()
|
|
|
+ listen_key_str.to_string()
|
|
|
} else {
|
|
|
"".to_string()
|
|
|
}
|
|
|
@@ -401,8 +363,8 @@ impl BinanceSwapWs {
|
|
|
}
|
|
|
//数据解析
|
|
|
pub fn ok_text(text: String) -> ResponseData {
|
|
|
- trace!("原始数据");
|
|
|
- trace!(?text);
|
|
|
+ // trace!("原始数据");
|
|
|
+ // trace!(?text);
|
|
|
let mut res_data = ResponseData::new("".to_string(), 200, "success".to_string(), Value::Null);
|
|
|
let json_value: Value = serde_json::from_str(&text).unwrap();
|
|
|
|