Skip to content

Commit ca76e40

Browse files
committed
style: apply rustfmt to fix CI cargo fmt --check failures
Made-with: Cursor
1 parent af50672 commit ca76e40

5 files changed

Lines changed: 293 additions & 140 deletions

File tree

rust_engine/src/bybit.rs

Lines changed: 64 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -300,7 +300,13 @@ impl OrderBookState {
300300
0.5
301301
};
302302

303-
(gap_prob_resistance_up, gap_up, gap_dn, liquidity_up, liquidity_dn)
303+
(
304+
gap_prob_resistance_up,
305+
gap_up,
306+
gap_dn,
307+
liquidity_up,
308+
liquidity_dn,
309+
)
304310
}
305311

306312
pub fn update_and_check_change(&mut self) -> bool {
@@ -320,7 +326,14 @@ pub async fn start_bybit_streams(symbol: &str) -> Result<mpsc::Receiver<BybitMes
320326
let symbol_spot = symbol.to_string();
321327
tokio::spawn(async move {
322328
loop {
323-
match connect_ws_with_reconnect(BYBIT_SPOT_WS, &symbol_spot, "bybit_spot", spot_tx.clone()).await {
329+
match connect_ws_with_reconnect(
330+
BYBIT_SPOT_WS,
331+
&symbol_spot,
332+
"bybit_spot",
333+
spot_tx.clone(),
334+
)
335+
.await
336+
{
324337
Ok(_) => eprintln!("[bybit_spot] Connection ended normally"),
325338
Err(e) => eprintln!("[bybit_spot] Connection error: {}", e),
326339
}
@@ -333,7 +346,14 @@ pub async fn start_bybit_streams(symbol: &str) -> Result<mpsc::Receiver<BybitMes
333346
let symbol_linear = symbol.to_string();
334347
tokio::spawn(async move {
335348
loop {
336-
match connect_ws_with_reconnect(BYBIT_LINEAR_WS, &symbol_linear, "bybit_linear_perp", linear_tx.clone()).await {
349+
match connect_ws_with_reconnect(
350+
BYBIT_LINEAR_WS,
351+
&symbol_linear,
352+
"bybit_linear_perp",
353+
linear_tx.clone(),
354+
)
355+
.await
356+
{
337357
Ok(_) => eprintln!("[bybit_linear_perp] Connection ended normally"),
338358
Err(e) => eprintln!("[bybit_linear_perp] Connection error: {}", e),
339359
}
@@ -355,12 +375,22 @@ pub async fn process_orderbook_updates(
355375

356376
while let Some(msg) = rx.recv().await {
357377
let (symbol, source, bids, asks, is_snapshot, timestamp) = match msg {
358-
BybitMessage::Snapshot { symbol, source, bids, asks, timestamp, .. } => {
359-
(symbol, source, bids, asks, true, timestamp)
360-
}
361-
BybitMessage::Delta { symbol, source, bids, asks, timestamp, .. } => {
362-
(symbol, source, bids, asks, false, timestamp)
363-
}
378+
BybitMessage::Snapshot {
379+
symbol,
380+
source,
381+
bids,
382+
asks,
383+
timestamp,
384+
..
385+
} => (symbol, source, bids, asks, true, timestamp),
386+
BybitMessage::Delta {
387+
symbol,
388+
source,
389+
bids,
390+
asks,
391+
timestamp,
392+
..
393+
} => (symbol, source, bids, asks, false, timestamp),
364394
};
365395

366396
let key = format!("{}:{}", source, symbol);
@@ -400,7 +430,8 @@ async fn connect_ws_with_reconnect(
400430

401431
{
402432
let mut w = write.lock().await;
403-
w.send(Message::Text(subscribe_msg.to_string().into())).await?;
433+
w.send(Message::Text(subscribe_msg.to_string().into()))
434+
.await?;
404435
}
405436
println!("[{}] Subscribed to orderbook.200.{}", source, symbol);
406437

@@ -412,7 +443,10 @@ async fn connect_ws_with_reconnect(
412443
interval.tick().await;
413444
let ping_msg = serde_json::json!({"op": "ping"});
414445
let mut w = write_ping.lock().await;
415-
if w.send(Message::Text(ping_msg.to_string().into())).await.is_err() {
446+
if w.send(Message::Text(ping_msg.to_string().into()))
447+
.await
448+
.is_err()
449+
{
416450
eprintln!("[{}] Failed to send ping", source_ping);
417451
break;
418452
}
@@ -545,7 +579,7 @@ mod tests {
545579

546580
// Symmetrical gaps: 5 empty ticks then same liquidity on both sides
547581
add_ask(&mut state, 100.60, 500.0); // 5 ticks gap up
548-
add_bid(&mut state, 99.50, 500.0); // 5 ticks gap down
582+
add_bid(&mut state, 99.50, 500.0); // 5 ticks gap down
549583

550584
let bid = state.book.best_bid().unwrap();
551585
let ask = state.book.best_ask().unwrap();
@@ -556,7 +590,11 @@ mod tests {
556590
assert!(liq_up > 0);
557591
assert!(liq_dn > 0);
558592
// Balanced → score ≈ 0.5
559-
assert!((score - 0.5).abs() < 0.01, "balanced book score should be ~0.5, got {}", score);
593+
assert!(
594+
(score - 0.5).abs() < 0.01,
595+
"balanced book score should be ~0.5, got {}",
596+
score
597+
);
560598
}
561599

562600
#[test]
@@ -569,13 +607,17 @@ mod tests {
569607

570608
// Much more liquidity on the ask side beyond the gap
571609
add_ask(&mut state, 100.60, 10_000.0); // 5 ticks gap, heavy resistance
572-
add_bid(&mut state, 99.50, 100.0); // 5 ticks gap, light support
610+
add_bid(&mut state, 99.50, 100.0); // 5 ticks gap, light support
573611

574612
let bid = state.book.best_bid().unwrap();
575613
let ask = state.book.best_ask().unwrap();
576614
let (score, _, _, _, _) = state.calculate_gap_probability(bid, ask);
577615

578-
assert!(score > 0.5, "ask-heavy book should score > 0.5, got {}", score);
616+
assert!(
617+
score > 0.5,
618+
"ask-heavy book should score > 0.5, got {}",
619+
score
620+
);
579621
}
580622

581623
#[test]
@@ -586,14 +628,18 @@ mod tests {
586628
add_bid(&mut state, 100.00, 1.0);
587629
add_ask(&mut state, 100.10, 1.0);
588630

589-
add_ask(&mut state, 100.60, 100.0); // light resistance
590-
add_bid(&mut state, 99.50, 10_000.0); // heavy support
631+
add_ask(&mut state, 100.60, 100.0); // light resistance
632+
add_bid(&mut state, 99.50, 10_000.0); // heavy support
591633

592634
let bid = state.book.best_bid().unwrap();
593635
let ask = state.book.best_ask().unwrap();
594636
let (score, _, _, _, _) = state.calculate_gap_probability(bid, ask);
595637

596-
assert!(score < 0.5, "bid-heavy book should score < 0.5, got {}", score);
638+
assert!(
639+
score < 0.5,
640+
"bid-heavy book should score < 0.5, got {}",
641+
score
642+
);
597643
}
598644

599645
#[test]

0 commit comments

Comments
 (0)