Skip to content

Commit 5b3b8c5

Browse files
committed
chore: clippy + fmt cleanup
Drives the tree to a `cargo clippy --all-targets -- -D warnings`-clean and `cargo fmt --check`-clean state for the v0.4.0 release. Clippy fixes: - Drop unused symbols: `OrderBlock::is_our_order_mask`/`_pad`, `GlobalOrderPool::reset`, `QueuePtrs::total_qty`, `WINDOW_MASK`, `QTY_EPSILON_U64`, `KMeans::batch_indices`, `BufferedTrade::{price_ticks, is_buyer_maker}`, the `x86_64::*` and `Trade` imports, and the `Duration` import in benches. - Mark `AppMessage::{SpotApiKeyRequired, NetworkWarning}` `symbol`/ `market` fields with `#[allow(dead_code)]` (intentional API metadata the UI does not currently surface). - Add `Default` for `Bitset`, derive `Default` on `TwapView`, add the `# Safety` doc to `remove_order_by_size_simd`, switch `i64::abs() as usize` to `unsigned_abs()`, and replace `map_or(true|false, …)` with `is_none_or` / `is_some_and`. - Use `is_multiple_of(50)` instead of `% 50 == 0`, type-annotate the `2.0_f32` literal in twap_view, and rewrite the centroid-order initialisation as `iter_mut().take(k).enumerate()`. - Collapse 7 nested `if … { if … }` blocks across `client.rs`, `app.rs`, `heatmap.rs`, `kmeans.rs`, `order_book.rs` into combined `if … && let … && …` forms. - `#[allow(clippy::field_reassign_with_default)]` on the order_book test module (those tests deliberately mutate fields after `default()` to bypass the snapshot path). Plus a full `cargo fmt` pass (whitespace, import ordering, multi-line expression formatting). 13 lib tests still pass.
1 parent 3ca885e commit 5b3b8c5

19 files changed

Lines changed: 522 additions & 274 deletions

benches/order_book_bench.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
1-
use criterion::{black_box, criterion_group, criterion_main, Criterion};
2-
use rand::{Rng, SeedableRng};
1+
use criterion::{Criterion, black_box, criterion_group, criterion_main};
32
use rand::rngs::StdRng;
4-
use std::time::Duration;
3+
use rand::{Rng, SeedableRng};
54

65
use binance_l3_est::engine::order_book::OrderBook;
76
use binance_l3_est::types::{DepthUpdate, OrderBookSnapshot};

benches/order_book_comparison.rs

Lines changed: 69 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
use criterion::{black_box, criterion_group, criterion_main, Criterion};
2-
use rand::{Rng, SeedableRng};
1+
use criterion::{Criterion, black_box, criterion_group, criterion_main};
32
use rand::rngs::StdRng;
3+
use rand::{Rng, SeedableRng};
44
use std::collections::{BTreeMap, HashMap, VecDeque};
55

66
use binance_l3_est::engine::order_book::OrderBook;
@@ -16,10 +16,15 @@ type BookSide = BTreeMap<i64, (f64, OrderQueue)>;
1616
const QTY_EPSILON: f64 = 1e-12;
1717

1818
#[derive(Debug, PartialEq, Eq)]
19-
pub enum OldOrderBookError { SequenceGap }
19+
pub enum OldOrderBookError {
20+
SequenceGap,
21+
}
2022

2123
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
22-
pub enum OldDepthUpdateStatus { Applied, IgnoredStale }
24+
pub enum OldDepthUpdateStatus {
25+
Applied,
26+
IgnoredStale,
27+
}
2328

2429
pub struct OldOrderBook {
2530
pub bids: BookSide,
@@ -64,15 +69,25 @@ impl OldOrderBook {
6469
self.bids.clear();
6570
self.asks.clear();
6671
for bid in &snap.bids {
67-
self.bids.insert(self.price_to_ticks(bid[0]), (bid[1], VecDeque::from([bid[1]])));
72+
self.bids.insert(
73+
self.price_to_ticks(bid[0]),
74+
(bid[1], VecDeque::from([bid[1]])),
75+
);
6876
}
6977
for ask in &snap.asks {
70-
self.asks.insert(self.price_to_ticks(ask[0]), (ask[1], VecDeque::from([ask[1]])));
78+
self.asks.insert(
79+
self.price_to_ticks(ask[0]),
80+
(ask[1], VecDeque::from([ask[1]])),
81+
);
7182
}
7283
self.last_applied_u = snap.last_update_id;
7384
}
7485

75-
pub fn process_update(&mut self, update: DepthUpdate, _mean: f64) -> Result<OldDepthUpdateStatus, OldOrderBookError> {
86+
pub fn process_update(
87+
&mut self,
88+
update: DepthUpdate,
89+
_mean: f64,
90+
) -> Result<OldDepthUpdateStatus, OldOrderBookError> {
7691
for bid in &update.b {
7792
self.process_level_change(self.price_to_ticks(bid[0]), bid[1], true);
7893
}
@@ -83,7 +98,11 @@ impl OldOrderBook {
8398
}
8499

85100
fn process_level_change(&mut self, price_ticks: i64, new_total_qty: f64, is_bid: bool) {
86-
let side = if is_bid { &mut self.bids } else { &mut self.asks };
101+
let side = if is_bid {
102+
&mut self.bids
103+
} else {
104+
&mut self.asks
105+
};
87106
if let Some((total_qty, queue)) = side.get_mut(&price_ticks) {
88107
if new_total_qty > *total_qty + QTY_EPSILON {
89108
queue.push_back(new_total_qty - *total_qty);
@@ -92,21 +111,35 @@ impl OldOrderBook {
92111
let mut to_rem = *total_qty - new_total_qty;
93112
while to_rem > QTY_EPSILON && !queue.is_empty() {
94113
let last = queue.len() - 1;
95-
if queue[last] <= to_rem + QTY_EPSILON { to_rem -= queue[last]; queue.pop_back(); }
96-
else { queue[last] -= to_rem; to_rem = 0.0; }
114+
if queue[last] <= to_rem + QTY_EPSILON {
115+
to_rem -= queue[last];
116+
queue.pop_back();
117+
} else {
118+
queue[last] -= to_rem;
119+
to_rem = 0.0;
120+
}
121+
}
122+
if new_total_qty <= QTY_EPSILON {
123+
side.remove(&price_ticks);
124+
} else {
125+
*total_qty = new_total_qty;
97126
}
98-
if new_total_qty <= QTY_EPSILON { side.remove(&price_ticks); }
99-
else { *total_qty = new_total_qty; }
100127
}
101128
} else if new_total_qty > QTY_EPSILON {
102-
side.insert(price_ticks, (new_total_qty, VecDeque::from([new_total_qty])));
129+
side.insert(
130+
price_ticks,
131+
(new_total_qty, VecDeque::from([new_total_qty])),
132+
);
103133
}
104134
}
105135
}
106136

107137
// --- BENCHMARK ---
108138

109-
fn generate_synthetic_data(num_updates: usize, tick_size: f64) -> (OrderBookSnapshot, Vec<DepthUpdate>) {
139+
fn generate_synthetic_data(
140+
num_updates: usize,
141+
tick_size: f64,
142+
) -> (OrderBookSnapshot, Vec<DepthUpdate>) {
110143
let mut rng = StdRng::seed_from_u64(42);
111144
let mut bids = Vec::new();
112145
let mut asks = Vec::new();
@@ -115,19 +148,35 @@ fn generate_synthetic_data(num_updates: usize, tick_size: f64) -> (OrderBookSnap
115148
bids.push([mid - (i as f64) * tick_size, rng.random_range(0.1..5.0)]);
116149
asks.push([mid + (i as f64) * tick_size, rng.random_range(0.1..5.0)]);
117150
}
118-
let snapshot = OrderBookSnapshot { last_update_id: 1000, bids, asks };
151+
let snapshot = OrderBookSnapshot {
152+
last_update_id: 1000,
153+
bids,
154+
asks,
155+
};
119156
let mut updates = Vec::new();
120157
for i in 0..num_updates {
121158
let mut b = Vec::new();
122159
let mut a = Vec::new();
123160
for _ in 0..2 {
124-
b.push([mid - (rng.random_range(1..=500) as f64) * tick_size, rng.random_range(0.0..6.0)]);
125-
a.push([mid + (rng.random_range(1..=500) as f64) * tick_size, rng.random_range(0.0..6.0)]);
161+
b.push([
162+
mid - (rng.random_range(1..=500) as f64) * tick_size,
163+
rng.random_range(0.0..6.0),
164+
]);
165+
a.push([
166+
mid + (rng.random_range(1..=500) as f64) * tick_size,
167+
rng.random_range(0.0..6.0),
168+
]);
126169
}
127170
updates.push(DepthUpdate {
128-
event_type: "depthUpdate".to_string(), event_time: 0, transaction_time: 0,
129-
symbol: SymbolStr::from("BTCUSDT"), capital_u: 0, small_u: 1001 + i as u64,
130-
pu: None, b, a,
171+
event_type: "depthUpdate".to_string(),
172+
event_time: 0,
173+
transaction_time: 0,
174+
symbol: SymbolStr::from("BTCUSDT"),
175+
capital_u: 0,
176+
small_u: 1001 + i as u64,
177+
pu: None,
178+
b,
179+
a,
131180
});
132181
}
133182
(snapshot, updates)

benches/order_book_update_bench.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
use criterion::{black_box, criterion_group, criterion_main, Criterion};
2-
use rand::{Rng, SeedableRng};
1+
use criterion::{Criterion, black_box, criterion_group, criterion_main};
32
use rand::rngs::StdRng;
3+
use rand::{Rng, SeedableRng};
44

55
use binance_l3_est::engine::order_book::OrderBook;
66
use binance_l3_est::types::{DepthUpdate, OrderBookSnapshot};
@@ -49,7 +49,7 @@ fn generate_synthetic_data(
4949
for _ in 0..2 {
5050
let offset = rng.random_range(1..=500);
5151
let price = mid_price - (offset as f64) * tick_size;
52-
let qty = rng.random_range(0.0..6.0);
52+
let qty = rng.random_range(0.0..6.0);
5353
b.push([price, qty]);
5454
}
5555

0 commit comments

Comments
 (0)