|
@@ -60,6 +60,10 @@ impl ExtendedStreamClient {
|
|
|
Self::new(label, account_option, format!("orderbooks/{}?depth=1", symbol), is_testnet)
|
|
Self::new(label, account_option, format!("orderbooks/{}?depth=1", symbol), is_testnet)
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ pub fn account(label: &str, account_option: Option<ExtendedAccount>, is_testnet: bool) -> ExtendedStreamClient {
|
|
|
|
|
+ Self::new(label, account_option, "account".to_string(), is_testnet)
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
// 链接
|
|
// 链接
|
|
|
pub async fn ws_connect_async<F, Future>(&mut self,
|
|
pub async fn ws_connect_async<F, Future>(&mut self,
|
|
|
is_shutdown_arc: Arc<AtomicBool>,
|
|
is_shutdown_arc: Arc<AtomicBool>,
|
|
@@ -81,10 +85,6 @@ impl ExtendedStreamClient {
|
|
|
StreamUtils::ping_pong(write_tx_clone1, HeartbeatType::Custom(ping_obj.to_string()), heartbeat_time).await;
|
|
StreamUtils::ping_pong(write_tx_clone1, HeartbeatType::Custom(ping_obj.to_string()), heartbeat_time).await;
|
|
|
});
|
|
});
|
|
|
|
|
|
|
|
- if self.account_option.is_some() {
|
|
|
|
|
- // 登录相关
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
// 提取host
|
|
// 提取host
|
|
|
let parsed_uri: http::Uri = address_url.parse()?;
|
|
let parsed_uri: http::Uri = address_url.parse()?;
|
|
|
let host_domain = parsed_uri.host().ok_or("URI 缺少主机名").unwrap().to_string();
|
|
let host_domain = parsed_uri.host().ok_or("URI 缺少主机名").unwrap().to_string();
|
|
@@ -100,13 +100,16 @@ impl ExtendedStreamClient {
|
|
|
host_domain.to_string() // 没有端口或使用默认端口
|
|
host_domain.to_string() // 没有端口或使用默认端口
|
|
|
};
|
|
};
|
|
|
|
|
|
|
|
|
|
+ // 提前克隆需要的数据
|
|
|
|
|
+ let api_key_option = self.account_option.as_ref().map(|account| account.api_key.clone());
|
|
|
|
|
+
|
|
|
// 链接
|
|
// 链接
|
|
|
let t2 = tokio::spawn(async move {
|
|
let t2 = tokio::spawn(async move {
|
|
|
let write_to_socket_rx_arc = Arc::new(Mutex::new(write_to_socket_rx));
|
|
let write_to_socket_rx_arc = Arc::new(Mutex::new(write_to_socket_rx));
|
|
|
|
|
|
|
|
loop {
|
|
loop {
|
|
|
// 通过构建request的方式进行ws链接,可以携带header
|
|
// 通过构建request的方式进行ws链接,可以携带header
|
|
|
- let request = Request::builder()
|
|
|
|
|
|
|
+ let mut request_builder = Request::builder()
|
|
|
.method("GET")
|
|
.method("GET")
|
|
|
.uri(&address_url)
|
|
.uri(&address_url)
|
|
|
.header("Sec-WebSocket-Key", generate_key())
|
|
.header("Sec-WebSocket-Key", generate_key())
|
|
@@ -114,9 +117,13 @@ impl ExtendedStreamClient {
|
|
|
.header("Host", host_header_value.clone())
|
|
.header("Host", host_header_value.clone())
|
|
|
.header("User-Agent", "RustClient/1.0")
|
|
.header("User-Agent", "RustClient/1.0")
|
|
|
.header("Upgrade", "websocket")
|
|
.header("Upgrade", "websocket")
|
|
|
- .header("Connection", "Upgrade")
|
|
|
|
|
- .body(())
|
|
|
|
|
- .unwrap();
|
|
|
|
|
|
|
+ .header("Connection", "Upgrade");
|
|
|
|
|
+
|
|
|
|
|
+ if let Some(ref api_key) = api_key_option {
|
|
|
|
|
+ request_builder = request_builder.header("X-Api-Key", api_key.clone());
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ let request = request_builder.body(()).unwrap();
|
|
|
|
|
|
|
|
trace!("Extended_usdt_swap socket 连接中……");
|
|
trace!("Extended_usdt_swap socket 连接中……");
|
|
|
StreamUtils::ws_connect_async(is_shutdown_arc.clone(), handle_function.clone(), request,
|
|
StreamUtils::ws_connect_async(is_shutdown_arc.clone(), handle_function.clone(), request,
|