tokio_binance/
lib.rs

1//! Unofficial async client for Binance.
2//!
3//! Simple and easy to use wrapper for the Binance API.
4//! ## Examples
5//!
6//! ### Client
7//! ```no_run
8//! use tokio_binance::{AccountClient, BINANCE_US_URL, ID};
9//! use serde_json::Value;
10//!
11//! #[tokio::main]
12//! async fn main() -> Result<(), Box<dyn std::error::Error>> {
13//!     let client = AccountClient::connect("<api-key>", "<secret-key>", BINANCE_US_URL)?;
14//!     let response = client
15//!         .get_order("BNBUSDT", ID::ClientOId("<uuid>"))
16//!         // optional: processing time for request; default is 5000, can't be above 60000.
17//!         .with_recv_window(8000)
18//!         //
19//!         .json::<Value>()
20//!         .await?;
21//!     Ok(())
22//! }
23//! ```
24//! ### Websocket
25//! ```no_run
26//! use tokio_binance::*;
27//! use tokio::time::Duration;
28//! use serde_json::Value;
29//!
30//! #[tokio::main]
31//! async fn main() -> Result<(), Box<dyn std::error::Error>> {
32//!     let client = UserDataClient::connect("<api-key>", BINANCE_US_URL)?;
33//!     let value = client.start_stream().json::<Value>().await?;
34//!
35//!     let listen_key = value["listenKey"].as_str().unwrap();
36//!     let listen_key_copy = listen_key.to_string();
37//!
38//!     tokio::spawn(async move {
39//!         loop {
40//!             std::thread::sleep(Duration::from_secs(30*60));
41//!             if let Err(e) = client.keep_alive(&listen_key_copy).text().await {
42//!                 eprintln!("{}", e);
43//!                 return
44//!             }
45//!         }
46//!     });
47//!
48//!     let channel = Channel::UserData(listen_key);
49//!     let mut stream = WebSocketStream::connect(channel, BINANCE_US_WSS_URL).await?;
50//!
51//!     while let Some(value) = stream.json::<Value>().await? {
52//!         if channel == value["stream"] {
53//!             println!("{}", serde_json::to_string_pretty(&value)?);
54//!         }
55//!     }
56//!     Ok(())
57//! }
58//! ```
59
60pub mod builder;
61mod client;
62pub mod error;
63mod param;
64pub mod types;
65mod ws_stream;
66
67pub use self::client::*;
68pub use self::param::*;
69pub use self::ws_stream::*;