Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,6 @@ Cargo.lock

*.fmt
*.iml
.env
.env
.idea
.envrc
54 changes: 27 additions & 27 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,34 +23,34 @@ name = "binance_async"
path = "src/lib.rs"

[dependencies]
failure = "0.1"
tracing = "0.1"

tungstenite = "0.10"
tokio-tungstenite = { version = "0.10", features = ["tls"] }

url = "2"
futures = "0.3"
headers = "0.3"
http = "0.2"
maplit = "1"
once_cell = "1"
reqwest = { version = "0.10", features = ["json"] }
reqwest-ext = { git = "https://github.com/vorot93/reqwest-ext" }
snafu = "0.6"
streamunordered = "0.5"
tokio = { version = "0.2", features = ["tcp"] }

chrono = { version = "0.4", features = ["serde"] }

serde = { version = "1", features = ["derive"] }
serde_json = "1"

hex = "0.4"
failure = "0.1.8"
tracing = "0.1.25"

tungstenite = "0.13.0"
tokio-tungstenite = { version = "0.13.0", features = ["tls"] }

url = "2.2.1"
futures = "0.3.13"
headers = "0.3.4"
http = "0.2.4"
maplit = "1.0.2"
once_cell = "1.7.2"
reqwest = { version = "0.11.2", features = ["json"] }
reqwest-ext = { git = "https://github.com/utx0/reqwest-ext" }
snafu = "0.6.10"
streamunordered = "0.5.2"
tokio = { version = "1.4.0", features = ["full"] }

chrono = { version = "0.4.19", features = ["serde"] }

serde = { version = "1.0.125", features = ["derive"] }
serde_json = "1.0.64"

hex = "0.4.3"
sha2 = "0.8"
hmac = "0.7"

[dev-dependencies]
csv = "1"
tokio = { version = "0.2", features = ["full"] }
tracing-subscriber = "0.2"
csv = "1.1.6"
tokio = { version = "1.4.0", features = ["full"] }
tracing-subscriber = "0.2.17"
38 changes: 19 additions & 19 deletions examples/endpoints.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,95 +13,95 @@ async fn main() -> Fallible<()> {
let bn = Binance::with_credential(&api_key, &secret_key);

// General
match bn.ping()?.await {
match bn.ping().await {
Ok(answer) => println!("{:?}", answer),
Err(e) => println!("Error: {}", e),
}

match bn.get_server_time()?.await {
match bn.get_server_time().await {
Ok(answer) => println!("Server Time: {}", answer.server_time),
Err(e) => println!("Error: {}", e),
}

// Account
match bn.get_account()?.await {
match bn.get_account().await {
Ok(answer) => println!("{:?}", answer.balances),
Err(e) => println!("Error: {}", e),
}

match bn.get_open_orders("WTCETH")?.await {
match bn.get_open_orders("BTCUSDT").await {
Ok(answer) => println!("{:?}", answer),
Err(e) => println!("Error: {}", e),
}

match bn.limit_buy("ETHBTC", 1., 0.1)?.await {
match bn.limit_buy("BTCUSDT", 1., 0.1).await {
Ok(answer) => println!("{:?}", answer),
Err(e) => println!("Error: {}", e),
}

match bn.market_buy("WTCETH", 5.)?.await {
match bn.market_buy("BTCUSDT", 5.).await {
Ok(answer) => println!("{:?}", answer),
Err(e) => println!("Error: {}", e),
}

match bn.limit_sell("WTCETH", 10., 0.035_000)?.await {
match bn.limit_sell("BTCUSDT", 10., 0.035_000).await {
Ok(answer) => println!("{:?}", answer),
Err(e) => println!("Error: {}", e),
}

match bn.market_sell("WTCETH", 5.)?.await {
match bn.market_sell("BTCUSDT", 5.).await {
Ok(answer) => println!("{:?}", answer),
Err(e) => println!("Error: {}", e),
}

match bn.order_status("WTCETH", 1_957_528)?.await {
match bn.order_status("BTCUSDT", 1_957_528).await {
Ok(answer) => println!("{:?}", answer),
Err(e) => println!("Error: {}", e),
}

match bn.cancel_order("WTCETH", 1_957_528)?.await {
match bn.cancel_order("BTCUSDT", 1_957_528).await {
Ok(answer) => println!("{:?}", answer),
Err(e) => println!("Error: {}", e),
}

match bn.get_balance("KNC")?.await {
match bn.get_balance("BTC").await {
Ok(answer) => println!("{:?}", answer),
Err(e) => println!("Error: {}", e),
}

match bn.trade_history("WTCETH")?.await {
match bn.trade_history("BTCUSDT").await {
Ok(answer) => println!("{:?}", answer),
Err(e) => println!("Error: {}", e),
}

// Market

// Order book
match bn.get_depth("BNBETH", None)?.await {
match bn.get_depth("BTCUSDT", None).await {
Ok(answer) => println!("{:?}", answer),
Err(e) => println!("Error: {}", e),
}

// Latest price for ALL symbols
match bn.get_all_prices()?.await {
match bn.get_all_prices().await {
Ok(answer) => println!("{:?}", answer),
Err(e) => println!("Error: {}", e),
}

// Latest price for ONE symbol
match bn.get_price("KNCETH")?.await {
match bn.get_price("BTCUSDT").await {
Ok(answer) => println!("{:?}", answer),
Err(e) => println!("Error: {}", e),
}

// Best price/qty on the order book for ALL symbols
match bn.get_all_book_tickers()?.await {
match bn.get_all_book_tickers().await {
Ok(answer) => println!("{:?}", answer),
Err(e) => println!("Error: {}", e),
}

// Best price/qty on the order book for ONE symbol
match bn.get_book_ticker("BNBETH")?.await {
match bn.get_book_ticker("BTCUSDT").await {
Ok(answer) => println!(
"Bid Price: {}, Ask Price: {}",
answer.bid_price, answer.ask_price
Expand All @@ -110,7 +110,7 @@ async fn main() -> Fallible<()> {
}

// 24hr ticker price change statistics
match bn.get_24h_price_stats("BNBETH")?.await {
match bn.get_24h_price_stats("BTCUSDT").await {
Ok(answer) => println!(
"Open Price: {}, Higher Price: {}, Lower Price: {:?}",
answer.open_price, answer.high_price, answer.low_price
Expand All @@ -119,7 +119,7 @@ async fn main() -> Fallible<()> {
}

// last 10 5min klines (candlesticks) for a symbol:
match bn.get_klines("BNBETH", "5m", 10, None, None)?.await {
match bn.get_klines("BTCUSDT", "5m", 10, None, None).await {
Ok(answer) => println!("{:?}", answer),
Err(e) => println!("Error: {}", e),
}
Expand Down
21 changes: 21 additions & 0 deletions examples/new_endpoints.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
use crate::binance::Binance;
use binance_async as binance;
use failure::Fallible;
use std::env::var;

#[tokio::main]
async fn main() -> Fallible<()> {
tracing::subscriber::set_global_default(tracing_subscriber::FmtSubscriber::new()).unwrap();

let api_key = var("BINANCE_KEY")?;
let secret_key = var("BINANCE_SECRET")?;

let bn = Binance::with_credential(&api_key, &secret_key);

match bn.get_historical_trades("BTCUSDT", 10, 963563573).await {
Ok(answer) => println!("{:?}", answer),
Err(e) => println!("Error: {}", e),
}

Ok(())
}
29 changes: 14 additions & 15 deletions examples/ws.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use crate::binance::{model::websocket::Subscription, Binance, BinanceWebsocket};
use binance_async as binance;
use failure::Fallible;
use futures::TryStreamExt;
use std::env::var;
use tokio::stream::StreamExt;

#[tokio::main]
async fn main() -> Fallible<()> {
Expand All @@ -12,30 +12,29 @@ async fn main() -> Fallible<()> {
let api_secret_user = var("BINANCE_SECRET")?;

let bn = Binance::with_credential(&api_key_user, &api_secret_user);
match bn.user_stream_start()?.await {
Ok(answer) => {
match bn.user_stream_start().await {
Ok(_) => {
println!("Data Stream Started ...");
let listen_key = answer.listen_key;

let mut ws = BinanceWebsocket::default();

for sub in vec![
Subscription::Ticker("ethbtc".to_string()),
Subscription::AggregateTrade("eosbtc".to_string()),
Subscription::Candlestick("ethbtc".to_string(), "1m".to_string()),
Subscription::Depth("xrpbtc".to_string()),
Subscription::MiniTicker("zrxbtc".to_string()),
Subscription::OrderBook("trxbtc".to_string(), 5),
Subscription::Trade("adabtc".to_string()),
Subscription::UserData(listen_key),
Subscription::MiniTickerAll,
Subscription::TickerAll,
// Subscription::Ticker("btcusdt.to_string()),
// Subscription::AggregateTrade("btcusdt.to_string()),
// Subscription::Candlestick("btcusdt".to_string(), "1m".to_string()),
// Subscription::Depth("btcusdt".to_string()),
// Subscription::MiniTicker("btcusdt".to_string()),
// Subscription::OrderBook("btcusdt".to_string(), 10),
Subscription::Trade("btcusdt".to_string()),
// Subscription::UserData(listen_key),
// Subscription::MiniTickerAll,
// Subscription::TickerAll,
] {
ws.subscribe(sub).await?;
}

while let Some(msg) = ws.try_next().await? {
println!("{:?}", msg)
println!("\n\n{:#?}", msg)
}
}
Err(e) => println!("Error obtaining userstream: {}", e),
Expand Down
Loading