1
+ use arrayvec:: ArrayVec ;
1
2
use std:: error:: Error ;
2
3
use std:: { pin:: Pin , task:: Poll } ;
3
4
@@ -34,7 +35,8 @@ pin_project! {
34
35
pub client_name: String ,
35
36
pub exchange_name: u8 ,
36
37
pub snapshot_enabled: bool ,
37
- pub websocket_depth_buffer: Vec <DepthUpdate >,
38
+ // todo: update webssocket_depth_buffer take the array vecs size by pragma or something similar -- it should be configurable
39
+ pub websocket_depth_buffer: ArrayVec <DepthUpdate , 1000 >,
38
40
pub pull_retry_count: u8 ,
39
41
pub http_snapshot_uri: String ,
40
42
pub buffer_websocket_depths: bool ,
@@ -46,8 +48,9 @@ pin_project! {
46
48
47
49
pub snapshot_sync: Option <stateSync<( ) >>,
48
50
51
+ // todo: update webssocket_depth_buffer take the array vecs size by pragma or something similar -- it should be configurable
49
52
#[ pin]
50
- buffer : Vec <DepthUpdate >,
53
+ depth_update_buffer : ArrayVec <DepthUpdate , 1000 >,
51
54
#[ pin]
52
55
ws_connection_orderbook: Option <WebSocketStream <MaybeTlsStream <TcpStream >>>,
53
56
#[ pin]
@@ -75,9 +78,7 @@ impl ExchangeStream {
75
78
client_name : exchange_config. client_name . clone ( ) ,
76
79
exchange_name : exchange_config. exchange_name ,
77
80
snapshot_sync : Some ( snapshot_sync) ,
78
- websocket_depth_buffer : Vec :: with_capacity (
79
- exchange_config. ws_presequenced_depth_buffer ,
80
- ) ,
81
+ websocket_depth_buffer : ArrayVec :: new ( ) ,
81
82
buffer_websocket_depths : false ,
82
83
snapshot_enabled : exchange_config. snapshot_enabled ,
83
84
pull_retry_count : 5 ,
@@ -88,7 +89,7 @@ impl ExchangeStream {
88
89
watched_pair : exchange_config. watched_pair . clone ( ) ,
89
90
stream_count : 0 ,
90
91
ws_connection_orderbook : None :: < WebSocketStream < MaybeTlsStream < TcpStream > > > ,
91
- buffer : Vec :: with_capacity ( exchange_config . buffer_size ) ,
92
+ depth_update_buffer : ArrayVec :: new ( ) ,
92
93
ws_connection_orderbook_reader : None ,
93
94
depths_producer : orders_producer,
94
95
http_client,
@@ -133,7 +134,7 @@ impl ExchangeStream {
133
134
match pull_result {
134
135
Ok ( mut depths) => {
135
136
while let Some ( depth) = depths. next ( ) {
136
- self . buffer . push ( depth) ;
137
+ self . depth_update_buffer . push ( depth) ;
137
138
// we must keep processing snapshot depths and depths from the websocket
138
139
// but this time the websocket depths are stored in their own buffer
139
140
// to be sequenced aftr snapshot depths are processed
@@ -155,7 +156,7 @@ impl ExchangeStream {
155
156
156
157
pub async fn push_buffered_ws_depths ( & mut self ) {
157
158
while let Some ( websocket_depth) = self . websocket_depth_buffer . pop ( ) {
158
- self . buffer . push ( websocket_depth) ;
159
+ self . depth_update_buffer . push ( websocket_depth) ;
159
160
}
160
161
self . buffer_websocket_depths = false ;
161
162
}
@@ -421,12 +422,12 @@ impl Stream for ExchangeStream {
421
422
let woven_depths = interleave ( depths. 0 , depths. 1 ) ;
422
423
if * this. buffer_websocket_depths {
423
424
for depth in woven_depths {
424
- this. buffer . push ( depth) ;
425
+ this. depth_update_buffer . push ( depth) ;
425
426
}
426
427
continue ;
427
428
} else {
428
429
for depth in woven_depths {
429
- this. buffer . push ( depth) ;
430
+ this. depth_update_buffer . push ( depth) ;
430
431
}
431
432
}
432
433
}
@@ -436,12 +437,12 @@ impl Stream for ExchangeStream {
436
437
let woven_depths = interleave ( depths. 0 , depths. 1 ) ;
437
438
if * this. buffer_websocket_depths {
438
439
for depth in woven_depths {
439
- this. buffer . push ( depth) ;
440
+ this. depth_update_buffer . push ( depth) ;
440
441
}
441
442
continue ;
442
443
}
443
444
for depth in woven_depths {
444
- this. buffer . push ( depth) ;
445
+ this. depth_update_buffer . push ( depth) ;
445
446
}
446
447
} else {
447
448
warn ! ( "failed to deserialize the object." ) ;
0 commit comments