|
|
@@ -2,7 +2,6 @@ use std::io::Read;
|
|
|
use std::sync::Arc;
|
|
|
use std::sync::atomic::AtomicBool;
|
|
|
use std::time::Duration;
|
|
|
-
|
|
|
use flate2::read::GzDecoder;
|
|
|
use futures_channel::mpsc::{UnboundedReceiver, UnboundedSender};
|
|
|
use serde_json::json;
|
|
|
@@ -12,7 +11,7 @@ use tokio_tungstenite::tungstenite::{Error, Message};
|
|
|
use tracing::{error, info, trace};
|
|
|
|
|
|
use crate::response_base::ResponseData;
|
|
|
-use crate::socket_tool::AbstractWsMode;
|
|
|
+use crate::socket_tool::{AbstractWsMode, HeartbeatType};
|
|
|
|
|
|
//类型
|
|
|
pub enum MexcSwapWsType {
|
|
|
@@ -107,7 +106,7 @@ impl MexcSwapWs {
|
|
|
ws_param,
|
|
|
symbol_s: vec![],
|
|
|
subscribe_types: vec![],
|
|
|
- heartbeat_time: 1000 * 18,
|
|
|
+ heartbeat_time: 1000 * 12,
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@@ -187,7 +186,7 @@ impl MexcSwapWs {
|
|
|
pub async fn ws_connect_async<F, Future>(&mut self,
|
|
|
is_shutdown_arc: Arc<AtomicBool>,
|
|
|
handle_function: F,
|
|
|
- _write_tx_am: &Arc<Mutex<UnboundedSender<Message>>>,
|
|
|
+ write_tx_am: &Arc<Mutex<UnboundedSender<Message>>>,
|
|
|
write_to_socket_rx: UnboundedReceiver<Message>) -> Result<(), Error>
|
|
|
where
|
|
|
F: Fn(ResponseData) -> Future + Clone + Send + 'static + Sync,
|
|
|
@@ -197,15 +196,18 @@ impl MexcSwapWs {
|
|
|
let subscription = self.get_subscription();
|
|
|
let address_url = self.address_url.clone();
|
|
|
let tag = self.tag.clone();
|
|
|
- // let heartbeat_time = self.ws_param.ws_ping_interval.clone();
|
|
|
+ let heartbeat_time = self.heartbeat_time.clone();
|
|
|
|
|
|
//心跳-- 方法内部线程启动
|
|
|
- // let write_tx_clone1 = write_tx_am.clone();
|
|
|
- // tokio::spawn(async move {
|
|
|
- // trace!("线程-异步心跳-开始");
|
|
|
- // AbstractWsMode::ping_or_pong(write_tx_clone1, HeartbeatType::Ping, heartbeat_time as u64).await;
|
|
|
- // trace!("线程-异步心跳-结束");
|
|
|
- // });
|
|
|
+ let write_tx_clone1 = Arc::clone(write_tx_am);
|
|
|
+ tokio::spawn(async move {
|
|
|
+ trace!("线程-异步心跳-开始");
|
|
|
+ let ping_str = json!({
|
|
|
+ "method": "ping"
|
|
|
+ });
|
|
|
+ AbstractWsMode::ping_or_pong(write_tx_clone1, HeartbeatType::Custom(ping_str.to_string()), heartbeat_time).await;
|
|
|
+ trace!("线程-异步心跳-结束");
|
|
|
+ });
|
|
|
|
|
|
|
|
|
//设置订阅
|