Unofficial async client for Binance.
Add this in your Cargo.toml
:
toml
[dependencies]
tokio-binance = "0.2"
serde_json = "1.0"
tokio = { version = "0.2", features = ["macros", "time"] }
```rust use tokiobinance::{AccountClient, BINANCEUSURL, ID}; use serdejson::Value;
async fn main() -> Result<(), Box
```rust use tokiobinance::*; use tokio::time::{delayfor, Duration}; use serde_json::Value;
async fn main() -> Result<(), Box
let listen_key = value["listenKey"].as_str().unwrap();
let listen_key_copy = listen_key.to_string();
tokio::spawn(async move {
loop {
delay_for(Duration::from_secs(30*60)).await;
if let Err(e) = client.keep_alive(&listen_key_copy).text().await {
eprintln!("{}", e);
return
}
}
});
let channel = Channel::UserData(listen_key);
let mut stream = WebSocketStream::connect(channel, BINANCE_US_WSS_URL).await?;
while let Some(value) = stream.json::<Value>().await? {
if channel == value["stream"] {
println!("{}", serde_json::to_string_pretty(&value)?);
}
}
Ok(())
} ```
Licensed under either of
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.