@@ -52,9 +52,9 @@ pub struct MarketUpdate {
5252 /// where score_X = liquidity_beyond_gap_X / (gap_distance_X + ε).
5353 ///
5454 /// Interpretation (contrarian):
55- /// > 0.5 → more resistance on ask side → price likely goes down
56- /// < 0.5 → more support on bid side → price likely goes up
57- /// ≈ 0.5 → balanced
55+ /// - above 0.5: more resistance on ask side → price likely goes down
56+ /// - below 0.5: more support on bid side → price likely goes up
57+ /// - near 0.5: balanced
5858 pub gap_prob_resistance_up : f64 ,
5959 pub gap_distance_up : u64 ,
6060 pub gap_distance_dn : u64 ,
@@ -91,8 +91,6 @@ struct LevelKey {
9191pub struct OrderBookState {
9292 book : OrderBook < ( ) > ,
9393 levels : HashMap < LevelKey , OrderId > ,
94- prev_best_bid : Option < u128 > ,
95- prev_best_ask : Option < u128 > ,
9694 /// Tick size in scaled integer units (price_f64 * PRICE_SCALE).
9795 tick_size_scaled : u128 ,
9896}
@@ -103,8 +101,6 @@ impl OrderBookState {
103101 Self {
104102 book : OrderBook :: < ( ) > :: new ( symbol) ,
105103 levels : HashMap :: new ( ) ,
106- prev_best_bid : None ,
107- prev_best_ask : None ,
108104 tick_size_scaled,
109105 }
110106 }
@@ -114,8 +110,6 @@ impl OrderBookState {
114110 * self = Self {
115111 book : OrderBook :: < ( ) > :: new ( symbol) ,
116112 levels : HashMap :: new ( ) ,
117- prev_best_bid : None ,
118- prev_best_ask : None ,
119113 tick_size_scaled,
120114 } ;
121115 }
@@ -162,15 +156,6 @@ impl OrderBookState {
162156 }
163157 }
164158
165- pub fn get_best_bid_ask ( & self ) -> Option < ( f64 , f64 ) > {
166- let best_bid = self . book . best_bid ( ) ?;
167- let best_ask = self . book . best_ask ( ) ?;
168- Some ( (
169- ( best_bid as f64 ) / PRICE_SCALE ,
170- ( best_ask as f64 ) / PRICE_SCALE ,
171- ) )
172- }
173-
174159 pub fn get_enriched_update (
175160 & self ,
176161 symbol : & str ,
@@ -308,15 +293,6 @@ impl OrderBookState {
308293 liquidity_dn,
309294 )
310295 }
311-
312- pub fn update_and_check_change ( & mut self ) -> bool {
313- let best_bid = self . book . best_bid ( ) ;
314- let best_ask = self . book . best_ask ( ) ;
315- let changed = self . prev_best_bid != best_bid || self . prev_best_ask != best_ask;
316- self . prev_best_bid = best_bid;
317- self . prev_best_ask = best_ask;
318- changed
319- }
320296}
321297
322298pub async fn start_bybit_streams ( symbol : & str ) -> Result < mpsc:: Receiver < BybitMessage > > {
@@ -577,16 +553,16 @@ mod tests {
577553 add_bid ( & mut state, 100.00 , 1.0 ) ;
578554 add_ask ( & mut state, 100.10 , 1.0 ) ;
579555
580- // Symmetrical gaps: 5 empty ticks then same liquidity on both sides
581- add_ask ( & mut state, 100.60 , 500.0 ) ; // 5 ticks gap up
582- add_bid ( & mut state, 99.50 , 500.0 ) ; // 5 ticks gap down
556+ // 4 empty ticks between best ask (100.10) and next ask (100.60)
557+ add_ask ( & mut state, 100.60 , 500.0 ) ; // 4 empty ticks above best ask
558+ add_bid ( & mut state, 99.50 , 500.0 ) ; // 4 empty ticks below best bid
583559
584560 let bid = state. book . best_bid ( ) . unwrap ( ) ;
585561 let ask = state. book . best_ask ( ) . unwrap ( ) ;
586562 let ( score, gap_up, gap_dn, liq_up, liq_dn) = state. calculate_gap_probability ( bid, ask) ;
587563
588- assert_eq ! ( gap_up, 5 , "should detect 5-tick gap up " ) ;
589- assert_eq ! ( gap_dn, 5 , "should detect 5-tick gap down " ) ;
564+ assert_eq ! ( gap_up, 4 , "should detect 4 empty ticks above best ask " ) ;
565+ assert_eq ! ( gap_dn, 4 , "should detect 4 empty ticks below best bid " ) ;
590566 assert ! ( liq_up > 0 ) ;
591567 assert ! ( liq_dn > 0 ) ;
592568 // Balanced → score ≈ 0.5
@@ -651,16 +627,20 @@ mod tests {
651627 add_bid ( & mut state, 3000.00 , 1.0 ) ;
652628 add_ask ( & mut state, 3000.01 , 1.0 ) ;
653629
654- // 10 tick gap up, 0 tick gap down (next level immediately)
630+ // 9 empty ticks between best ask (3000.01) and next ask (3000.11)
631+ // 0 empty ticks below best bid (2999.99 is immediately adjacent)
655632 add_ask ( & mut state, 3000.11 , 500.0 ) ;
656633 add_bid ( & mut state, 2999.99 , 500.0 ) ;
657634
658635 let bid = state. book . best_bid ( ) . unwrap ( ) ;
659636 let ask = state. book . best_ask ( ) . unwrap ( ) ;
660637 let ( _, gap_up, gap_dn, _, _) = state. calculate_gap_probability ( bid, ask) ;
661638
662- assert_eq ! ( gap_up, 10 , "should detect 10-tick gap with 0.01 tick size" ) ;
663- assert_eq ! ( gap_dn, 0 , "should detect 0-tick gap (immediate liquidity)" ) ;
639+ assert_eq ! ( gap_up, 9 , "should detect 9 empty ticks with 0.01 tick size" ) ;
640+ assert_eq ! (
641+ gap_dn, 0 ,
642+ "should detect 0 empty ticks (immediate liquidity)"
643+ ) ;
664644 }
665645
666646 #[ test]
0 commit comments