1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
  
//! Unofficial async client for Binance.
//!
//! Simple and easy to use wrapper for the Binance API.
//! ## Examples
//!
//! ### Client
//! ```no_run
//! use tokio_binance::{AccountClient, BINANCE_US_URL, ID};
//! use serde_json::Value;
//! 
//! #[tokio::main]
//! async fn main() -> Result<(), Box<dyn std::error::Error>> {
//!     let client = AccountClient::connect("<api-key>", "<secret-key>", BINANCE_US_URL)?;
//!     let response = client
//!         .get_order("BNBUSDT", ID::ClientOId("<uuid>"))
//!         // optional: processing time for request; default is 5000, can't be above 60000.
//!         .with_recv_window(8000)
//!         //
//!         .json::<Value>()
//!         .await?;
//!     Ok(())
//! }
//! ```
//! ### Websocket
//! ```no_run
//! use tokio_binance::*;
//! use tokio::time::{delay_for, Duration};
//! use serde_json::Value;
//! 
//! #[tokio::main]
//! async fn main() -> Result<(), Box<dyn std::error::Error>> {
//!     let client = UserDataClient::connect("<api-key>", BINANCE_US_URL)?;
//!     let value = client.start_stream().json::<Value>().await?;
//! 
//!     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(())
//! }
//! ```

mod param;
pub mod builder;
pub mod error;
mod client;
pub mod types;
mod ws_stream;

pub use self::ws_stream::*;
pub use self::param::*;
pub use self::client::*;