Files
wickra/examples/rust/src/bin/live_binance.rs
T
kingchenc 747d1a5b1b examples: move Rust examples into a top-level examples/rust/ crate
The three Rust examples (backtest, fetch_btcusdt, live_binance) used to
live each in their own crate's examples/ dir, splitting the example set
across crates and burying it inside the source tree. Move them into a new
workspace member crate at `examples/rust/` (package `wickra-examples`,
`publish = false`) so all language examples sit under one top-level
`examples/<lang>/` tree.

* `examples/rust/Cargo.toml` declares the per-binary deps (wickra,
  wickra-data with the `live-binance` feature always on, serde_json, tokio
  for the macro and current-thread runtime).
* `examples/rust/src/bin/{backtest,fetch_btcusdt,live_binance}.rs` are the
  three migrated binaries; their doc-comments and the fetch_btcusdt output
  path are updated for the new location and run command
  (`cargo run -p wickra-examples --bin <name>`).
* Workspace `Cargo.toml` lists the new member; the now-empty
  `[dev-dependencies]` extras (`wickra`, `tokio` in wickra-data and
  `serde_json` in wickra) that existed only for these examples are dropped.
* The `[[example]] live_binance` table is removed from wickra-data's
  manifest since the file moved out.
* README "Languages" + project-layout, examples/README.md, Quickstart-Rust
  and Data-Layer are pointed at the new paths and commands.

`cargo build -p wickra-examples` and `cargo run --release -p wickra-examples
--bin backtest -- examples/data/btcusdt-1d.csv` both succeed; the rest of
the workspace (core, data, wickra) builds, clippies (`--all-targets -D
warnings`) and tests (508 core + 28 data + 1 integration + 74+3+1
doctests) all stay green.
2026-05-23 00:07:07 +02:00

42 lines
1.2 KiB
Rust

//! Connect to Binance, run incremental RSI on the closed kline events.
//!
//! Build with:
//! ```text
//! cargo run --release -p wickra-examples --bin live_binance -- BTCUSDT
//! ```
//!
//! The example prints a line per bar close. Hit Ctrl+C to stop.
use std::env;
use wickra::{Indicator, Rsi};
use wickra_data::live::binance::{BinanceKlineStream, Interval};
#[tokio::main(flavor = "current_thread")]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let args: Vec<String> = env::args().collect();
let symbol = args
.get(1)
.cloned()
.unwrap_or_else(|| "BTCUSDT".to_string());
let mut stream =
BinanceKlineStream::connect(std::slice::from_ref(&symbol), Interval::OneMinute).await?;
let mut rsi = Rsi::new(14)?;
println!("Listening for {symbol} 1m closes…");
while let Some(event) = stream.next_event().await? {
if !event.is_closed {
continue;
}
let close = event.candle.close;
let v = rsi.update(close);
if let Some(value) = v {
println!("{} close={:.4} rsi={:.2}", event.symbol, close, value);
} else {
println!("{} close={:.4} rsi=…warmup", event.symbol, close);
}
}
Ok(())
}