Skip to content

Commit 978b6d3

Browse files
committed
fix: resolve all CI failures (clippy, E0282, dead code, Windows poetry)
Made-with: Cursor
1 parent ca76e40 commit 978b6d3

6 files changed

Lines changed: 40 additions & 49 deletions

File tree

.github/workflows/ci.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,11 @@ jobs:
4848
key: venv-${{ matrix.os }}-${{ matrix.python-version }}-${{ hashFiles('poetry.lock') }}
4949

5050
- name: Install Python dependencies
51+
shell: bash
5152
run: poetry install --with dev
5253

5354
- name: Build Rust extension (release)
55+
shell: bash
5456
working-directory: rust_engine
5557
run: poetry run maturin develop --release
5658

@@ -71,10 +73,13 @@ jobs:
7173
# ── Python checks ─────────────────────────────────────────────────────
7274

7375
- name: Ruff lint
76+
shell: bash
7477
run: poetry run ruff check src/ tests/
7578

7679
- name: Ruff format check
80+
shell: bash
7781
run: poetry run ruff format --check src/ tests/
7882

7983
- name: pytest (unit + integration)
84+
shell: bash
8085
run: poetry run pytest tests/ -v --tb=short

rust_engine/src/bybit.rs

Lines changed: 15 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -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.5more 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 {
9191
pub 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

322298
pub 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]

rust_engine/src/execution.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,7 @@ impl PositionState {
154154
self.positions.get(symbol).map(|r| r.value().clone())
155155
}
156156

157+
#[allow(dead_code)]
157158
pub fn update_position(&self, position: Position) {
158159
self.positions.insert(position.symbol.clone(), position);
159160
}
@@ -504,6 +505,7 @@ struct BybitResponse<T> {
504505
}
505506

506507
#[derive(Debug, Deserialize)]
508+
#[allow(dead_code)]
507509
pub struct SubmitOrderResponse {
508510
#[serde(rename = "orderId")]
509511
pub order_id: String,
@@ -512,6 +514,7 @@ pub struct SubmitOrderResponse {
512514
}
513515

514516
#[derive(Debug, Deserialize)]
517+
#[allow(dead_code)]
515518
pub struct AmendOrderResponse {
516519
#[serde(rename = "orderId")]
517520
pub order_id: String,
@@ -520,6 +523,7 @@ pub struct AmendOrderResponse {
520523
}
521524

522525
#[derive(Debug, Deserialize)]
526+
#[allow(dead_code)]
523527
pub struct CancelOrderResponse {
524528
#[serde(rename = "orderId")]
525529
pub order_id: String,
@@ -567,6 +571,7 @@ pub struct ExecutionEngine {
567571
}
568572

569573
impl ExecutionEngine {
574+
#[allow(clippy::too_many_arguments)]
570575
pub fn new(
571576
api_key: String,
572577
api_secret: String,

rust_engine/src/lib.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -168,11 +168,11 @@ impl TradingNode {
168168
}
169169

170170
fn __repr__(&self) -> String {
171-
format!("TradingNode()")
171+
"TradingNode()".to_string()
172172
}
173173

174174
fn __str__(&self) -> String {
175-
format!("TradingNode for Bybit orderbook streaming")
175+
"TradingNode for Bybit orderbook streaming".to_string()
176176
}
177177
}
178178

@@ -192,6 +192,7 @@ struct ExecutionNode {
192192
#[pymethods]
193193
impl ExecutionNode {
194194
#[new]
195+
#[allow(clippy::too_many_arguments)]
195196
fn new(
196197
api_key: String,
197198
api_secret: String,
@@ -430,11 +431,11 @@ impl ExecutionNode {
430431
}
431432

432433
fn __repr__(&self) -> String {
433-
format!("ExecutionNode()")
434+
"ExecutionNode()".to_string()
434435
}
435436

436437
fn __str__(&self) -> String {
437-
format!("ExecutionNode for Bybit order execution")
438+
"ExecutionNode for Bybit order execution".to_string()
438439
}
439440
}
440441

rust_engine/src/main.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
mod bybit;
22

33
use anyhow::Result;
4-
use bybit::{process_orderbook_updates, start_bybit_streams};
4+
use bybit::{process_orderbook_updates, start_bybit_streams, MarketUpdate};
55
use rustls::crypto::ring;
66

77
#[tokio::main]
@@ -11,7 +11,7 @@ async fn main() -> Result<()> {
1111

1212
let rx = start_bybit_streams("BTCUSDT").await?;
1313

14-
process_orderbook_updates(rx, |update| {
14+
process_orderbook_updates(rx, 0.1, |update: MarketUpdate| {
1515
println!(
1616
"[{}] {} | Best Bid: {:.2} | Best Ask: {:.2} | Spread: {:.2}",
1717
update.source, update.symbol, update.bid, update.ask, update.spread

rust_engine/src/private_ws.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ pub struct ExecutionReport {
3939
}
4040

4141
#[derive(Debug, Clone)]
42+
#[allow(dead_code)]
4243
pub struct FillEvent {
4344
pub symbol: String,
4445
pub order_id: String,
@@ -53,6 +54,7 @@ pub struct FillEvent {
5354
}
5455

5556
#[derive(Debug, Deserialize)]
57+
#[allow(dead_code)]
5658
struct PrivateMessage {
5759
topic: String,
5860
#[serde(rename = "creationTime")]
@@ -142,14 +144,12 @@ async fn connect_and_stream(
142144
eprintln!("Sent authentication request...");
143145

144146
// Wait for auth response
145-
if let Some(Ok(msg)) = read.next().await {
146-
if let Message::Text(text) = msg {
147-
eprintln!("Auth response: {}", text);
148-
if text.contains("\"success\":true") {
149-
eprintln!("✓ Authentication successful");
150-
} else {
151-
return Err(anyhow::anyhow!("Authentication failed: {}", text));
152-
}
147+
if let Some(Ok(Message::Text(text))) = read.next().await {
148+
eprintln!("Auth response: {}", text);
149+
if text.contains("\"success\":true") {
150+
eprintln!("✓ Authentication successful");
151+
} else {
152+
return Err(anyhow::anyhow!("Authentication failed: {}", text));
153153
}
154154
}
155155

0 commit comments

Comments
 (0)