@@ -13,29 +13,32 @@ use tokio::{
13
13
} ;
14
14
use tokio_tungstenite:: {
15
15
connect_async,
16
- tungstenite:: { client:: IntoClientRequest , Message } ,
16
+ tungstenite:: { client:: IntoClientRequest , Bytes , Message , Utf8Bytes } ,
17
17
} ;
18
18
use tracing:: { error, warn} ;
19
19
20
20
pub async fn connect (
21
21
url : & str ,
22
22
topics : Vec < String > ,
23
- ws_tx : UnboundedSender < ( DateTime < Utc > , String ) > ,
23
+ ws_tx : UnboundedSender < ( DateTime < Utc > , Utf8Bytes ) > ,
24
24
) -> Result < ( ) , anyhow:: Error > {
25
25
let request = url. into_client_request ( ) ?;
26
26
let ( ws_stream, _) = connect_async ( request) . await ?;
27
27
let ( mut write, mut read) = ws_stream. split ( ) ;
28
28
let ( tx, mut rx) = unbounded_channel :: < ( ) > ( ) ;
29
29
30
30
write
31
- . send ( Message :: Text ( format ! (
32
- r#"{{"req_id": "subscribe", "op": "subscribe", "args": [{}]}}"# ,
33
- topics
34
- . iter( )
35
- . map( |s| format!( "\" {s}\" " ) )
36
- . collect:: <Vec <_>>( )
37
- . join( "," )
38
- ) ) )
31
+ . send ( Message :: Text (
32
+ format ! (
33
+ r#"{{"req_id": "subscribe", "op": "subscribe", "args": [{}]}}"# ,
34
+ topics
35
+ . iter( )
36
+ . map( |s| format!( "\" {s}\" " ) )
37
+ . collect:: <Vec <_>>( )
38
+ . join( "," )
39
+ )
40
+ . into ( ) ,
41
+ ) )
39
42
. await ?;
40
43
41
44
tokio:: spawn ( async move {
@@ -45,7 +48,7 @@ pub async fn connect(
45
48
result = rx. recv( ) => {
46
49
match result {
47
50
Some ( _) => {
48
- if write. send( Message :: Pong ( Vec :: new ( ) ) ) . await . is_err( ) {
51
+ if write. send( Message :: Pong ( Bytes :: default ( ) ) ) . await . is_err( ) {
49
52
return ;
50
53
}
51
54
}
@@ -56,7 +59,7 @@ pub async fn connect(
56
59
}
57
60
_ = ping_interval. tick( ) => {
58
61
if write. send(
59
- Message :: Text ( r#"{"req_id": "ping", "op": "ping"}"# . to_string ( ) )
62
+ Message :: Text ( r#"{"req_id": "ping", "op": "ping"}"# . into ( ) )
60
63
) . await . is_err( ) {
61
64
return ;
62
65
}
@@ -100,7 +103,7 @@ pub async fn connect(
100
103
pub async fn keep_connection (
101
104
topics : Vec < String > ,
102
105
symbol_list : Vec < String > ,
103
- ws_tx : UnboundedSender < ( DateTime < Utc > , String ) > ,
106
+ ws_tx : UnboundedSender < ( DateTime < Utc > , Utf8Bytes ) > ,
104
107
) {
105
108
let mut error_count = 0 ;
106
109
loop {
0 commit comments