Skip to content

Commit

Permalink
Format code
Browse files Browse the repository at this point in the history
  • Loading branch information
wisespace-io committed Mar 7, 2024
1 parent 232301b commit ebcbe78
Show file tree
Hide file tree
Showing 13 changed files with 79 additions and 51 deletions.
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ error-chain = { version = "0.12.4", default-features = false }
reqwest = { version = "0.11.8", features = ["blocking", "json"] }
tungstenite = { version = "0.19.0", features = ["native-tls"] }
url = "2.4.0"
clap = "4.5.2"

[features]
vendored-tls = ["reqwest/native-tls-vendored", "tungstenite/native-tls-vendored"]
Expand Down
4 changes: 0 additions & 4 deletions examples/binance_websockets.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ use binance::userstream::*;
use binance::websockets::*;
use std::sync::atomic::{AtomicBool, Ordering};



fn main() {
//user_stream();
//user_stream_websocket();
Expand All @@ -15,8 +13,6 @@ fn main() {
//all_trades_websocket();
//last_price_for_one_symbol();
// multiple_streams();


}

fn user_stream() {
Expand Down
4 changes: 1 addition & 3 deletions src/account.rs
Original file line number Diff line number Diff line change
Expand Up @@ -724,9 +724,7 @@ impl Account {
.delete_signed(API::Spot(Spot::Order), Some(request))
}

pub fn cancel_order_with_client_id_rs<S>() {

}
pub fn cancel_order_with_client_id_rs<S>() {}
/// Place a test cancel order
///
/// This order is sandboxed: it is validated, but not sent to the matching engine.
Expand Down
4 changes: 3 additions & 1 deletion src/futures/account.rs
Original file line number Diff line number Diff line change
Expand Up @@ -421,7 +421,9 @@ impl FuturesAccount {
}

// Custom order for for professional traders
pub fn custom_batch_orders(&self, _order_count: u64, order_requests: Vec<CustomOrderRequest>) -> Result<Transaction> {
pub fn custom_batch_orders(
&self, _order_count: u64, order_requests: Vec<CustomOrderRequest>,
) -> Result<Transaction> {
let request = String::from("");
for order_request in order_requests {
let order = OrderRequest {
Expand Down
3 changes: 2 additions & 1 deletion src/futures/general.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ pub struct FuturesGeneral {
impl FuturesGeneral {
// Test connectivity
pub fn ping(&self) -> Result<String> {
self.client.get::<Empty>(API::Futures(Futures::Ping), None)?;
self.client
.get::<Empty>(API::Futures(Futures::Ping), None)?;
Ok("pong".into())
}

Expand Down
3 changes: 0 additions & 3 deletions src/futures/websockets.rs
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,4 @@ impl<'a> FuturesWebSockets<'a> {
}
bail!("running loop closed");
}


}

7 changes: 3 additions & 4 deletions src/websockets.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,9 @@ impl WebsocketAPI {
fn params(self, subscription: &str) -> String {
match self {
WebsocketAPI::Default => format!("wss://stream.binance.com/ws/{}", subscription),
WebsocketAPI::MultiStream => format!(
"wss://stream.binance.com/stream?streams={}",
subscription
),
WebsocketAPI::MultiStream => {
format!("wss://stream.binance.com/stream?streams={}", subscription)
}
WebsocketAPI::Custom(url) => format!("{}/{}", url, subscription),
}
}
Expand Down
42 changes: 28 additions & 14 deletions tests/account_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ mod tests {
#[test]
fn get_account() {
let mut server = Server::new();
let mock_get_account = server.mock("GET", "/api/v3/account")
let mock_get_account = server
.mock("GET", "/api/v3/account")
.with_header("content-type", "application/json;charset=UTF-8")
.match_query(Matcher::Regex(
"recvWindow=1234&timestamp=\\d+&signature=.*".into(),
Expand Down Expand Up @@ -53,7 +54,8 @@ mod tests {
#[test]
fn get_balance() {
let mut server = Server::new();
let mock_get_account = server.mock("GET", "/api/v3/account")
let mock_get_account = server
.mock("GET", "/api/v3/account")
.with_header("content-type", "application/json;charset=UTF-8")
.match_query(Matcher::Regex(
"recvWindow=1234&timestamp=\\d+&signature=.*".into(),
Expand All @@ -78,7 +80,8 @@ mod tests {
#[test]
fn get_open_orders() {
let mut server = Server::new();
let mock_open_orders = server.mock("GET", "/api/v3/openOrders")
let mock_open_orders = server
.mock("GET", "/api/v3/openOrders")
.with_header("content-type", "application/json;charset=UTF-8")
.match_query(Matcher::Regex(
"recvWindow=1234&symbol=LTCBTC&timestamp=\\d+".into(),
Expand Down Expand Up @@ -121,7 +124,8 @@ mod tests {
#[test]
fn get_all_open_orders() {
let mut server = Server::new();
let mock_open_orders = server.mock("GET", "/api/v3/openOrders")
let mock_open_orders = server
.mock("GET", "/api/v3/openOrders")
.with_header("content-type", "application/json;charset=UTF-8")
.match_query(Matcher::Regex("recvWindow=1234&timestamp=\\d+".into()))
.with_body_from_file("tests/mocks/account/get_open_orders.json")
Expand Down Expand Up @@ -162,7 +166,8 @@ mod tests {
#[test]
fn cancel_all_open_orders() {
let mut server = Server::new();
let mock_cancel_all_open_orders = server.mock("DELETE", "/api/v3/openOrders")
let mock_cancel_all_open_orders = server
.mock("DELETE", "/api/v3/openOrders")
.with_header("content-type", "application/json;charset=UTF-8")
.match_query(Matcher::Regex(
"recvWindow=1234&symbol=BTCUSDT&timestamp=\\d+".into(),
Expand Down Expand Up @@ -209,7 +214,8 @@ mod tests {
#[test]
fn order_status() {
let mut server = Server::new();
let mock_order_status = server.mock("GET", "/api/v3/order")
let mock_order_status = server
.mock("GET", "/api/v3/order")
.with_header("content-type", "application/json;charset=UTF-8")
.match_query(Matcher::Regex(
"orderId=1&recvWindow=1234&symbol=LTCBTC&timestamp=\\d+".into(),
Expand Down Expand Up @@ -249,7 +255,8 @@ mod tests {
#[test]
fn test_order_status() {
let mut server = Server::new();
let mock_test_order_status = server.mock("GET", "/api/v3/order/test")
let mock_test_order_status = server
.mock("GET", "/api/v3/order/test")
.with_header("content-type", "application/json;charset=UTF-8")
.match_query(Matcher::Regex(
"orderId=1&recvWindow=1234&symbol=LTCBTC&timestamp=\\d+".into(),
Expand Down Expand Up @@ -384,7 +391,8 @@ mod tests {
#[test]
fn market_buy() {
let mut server = Server::new();
let mock_market_buy = server.mock("POST", "/api/v3/order")
let mock_market_buy = server
.mock("POST", "/api/v3/order")
.with_header("content-type", "application/json;charset=UTF-8")
.match_query(Matcher::Regex(
"quantity=1&recvWindow=1234&side=BUY&symbol=LTCBTC&timestamp=\\d+&type=MARKET"
Expand Down Expand Up @@ -425,7 +433,8 @@ mod tests {
#[test]
fn test_market_buy() {
let mut server = Server::new();
let mock_test_market_buy = server.mock("POST", "/api/v3/order/test")
let mock_test_market_buy = server
.mock("POST", "/api/v3/order/test")
.with_header("content-type", "application/json;charset=UTF-8")
.match_query(Matcher::Regex(
"quantity=1&recvWindow=1234&side=BUY&symbol=LTCBTC&timestamp=\\d+&type=MARKET"
Expand Down Expand Up @@ -492,7 +501,8 @@ mod tests {
#[test]
fn market_sell() {
let mut server = Server::new();
let mock_market_sell = server.mock("POST", "/api/v3/order")
let mock_market_sell = server
.mock("POST", "/api/v3/order")
.with_header("content-type", "application/json;charset=UTF-8")
.match_query(Matcher::Regex(
"quantity=1&recvWindow=1234&side=SELL&symbol=LTCBTC&timestamp=\\d+&type=MARKET"
Expand Down Expand Up @@ -533,7 +543,8 @@ mod tests {
#[test]
fn test_market_sell() {
let mut server = Server::new();
let mock_test_market_sell = server.mock("POST", "/api/v3/order/test")
let mock_test_market_sell = server
.mock("POST", "/api/v3/order/test")
.with_header("content-type", "application/json;charset=UTF-8")
.match_query(Matcher::Regex(
"quantity=1&recvWindow=1234&side=SELL&symbol=LTCBTC&timestamp=\\d+&type=MARKET"
Expand Down Expand Up @@ -804,7 +815,8 @@ mod tests {
#[test]
fn cancel_order() {
let mut server = Server::new();
let mock_cancel_order = server.mock("DELETE", "/api/v3/order")
let mock_cancel_order = server
.mock("DELETE", "/api/v3/order")
.with_header("content-type", "application/json;charset=UTF-8")
.match_query(Matcher::Regex(
"orderId=1&recvWindow=1234&symbol=BTCUSDT&timestamp=\\d+".into(),
Expand All @@ -830,7 +842,8 @@ mod tests {
#[test]
fn test_cancel_order() {
let mut server = Server::new();
let mock_test_cancel_order = server.mock("DELETE", "/api/v3/order/test")
let mock_test_cancel_order = server
.mock("DELETE", "/api/v3/order/test")
.with_header("content-type", "application/json;charset=UTF-8")
.match_query(Matcher::Regex(
"orderId=1&recvWindow=1234&symbol=BTCUSDT&timestamp=\\d+".into(),
Expand All @@ -851,7 +864,8 @@ mod tests {
#[test]
fn trade_history() {
let mut server = Server::new();
let mock_trade_history = server.mock("GET", "/api/v3/myTrades")
let mock_trade_history = server
.mock("GET", "/api/v3/myTrades")
.with_header("content-type", "application/json;charset=UTF-8")
.match_query(Matcher::Regex(
"recvWindow=1234&symbol=BTCUSDT&timestamp=\\d+".into(),
Expand Down
12 changes: 8 additions & 4 deletions tests/futures_account_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ mod tests {
#[test]
fn change_initial_leverage() {
let mut server = Server::new();
let mock_change_leverage = server.mock("POST", "/fapi/v1/leverage")
let mock_change_leverage = server
.mock("POST", "/fapi/v1/leverage")
.with_header("content-type", "application/json;charset=UTF-8")
.match_query(Matcher::Regex(
"leverage=2&recvWindow=1234&symbol=LTCUSDT&timestamp=\\d+&signature=.*".into(),
Expand Down Expand Up @@ -43,7 +44,8 @@ mod tests {
#[test]
fn cancel_all_open_orders() {
let mut server = Server::new();
let mock = server.mock("DELETE", "/fapi/v1/allOpenOrders")
let mock = server
.mock("DELETE", "/fapi/v1/allOpenOrders")
.with_header("content-type", "application/json;charset=UTF-8")
.match_query(Matcher::Regex(
"recvWindow=1234&symbol=BTCUSDT&timestamp=\\d+&signature=.*".into(),
Expand All @@ -64,7 +66,8 @@ mod tests {
#[test]
fn change_position_mode() {
let mut server = Server::new();
let mock = server.mock("POST", "/fapi/v1/positionSide/dual")
let mock = server
.mock("POST", "/fapi/v1/positionSide/dual")
.with_header("content-type", "application/json;charset=UTF-8")
.match_query(Matcher::Regex(
"dualSidePosition=true&recvWindow=1234&timestamp=\\d+&signature=.*".into(),
Expand Down Expand Up @@ -176,7 +179,8 @@ mod tests {
#[test]
fn get_income() {
let mut server = Server::new();
let mock = server.mock("GET", "/fapi/v1/income")
let mock = server
.mock("GET", "/fapi/v1/income")
.with_header("content-type", "application/json;charset=UTF-8")
.match_query(Matcher::Regex(
"endTime=12345678910&incomeType=TRANSFER&limit=10\
Expand Down
5 changes: 3 additions & 2 deletions tests/futures_general_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ mod tests {
#[test]
fn ping() {
let mut server = Server::new();
let mock_ping = server.mock("GET", "/fapi/v1/ping")
let mock_ping = server
.mock("GET", "/fapi/v1/ping")
.with_header("content-type", "application/json;charset=UTF-8")
.with_body("{}")
.create();
Expand All @@ -24,4 +25,4 @@ mod tests {

assert_eq!(pong, "pong");
}
}
}
3 changes: 2 additions & 1 deletion tests/futures_market_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ mod tests {
#[test]
fn open_interest_statistics() {
let mut server = Server::new();
let mock_open_interest_statistics = server.mock("GET", "/futures/data/openInterestHist")
let mock_open_interest_statistics = server
.mock("GET", "/futures/data/openInterestHist")
.with_header("content-type", "application/json;charset=UTF-8")
.match_query(Matcher::Regex("limit=10&period=5m&symbol=BTCUSDT".into()))
.with_body_from_file("tests/mocks/futures/market/open_interest_statistics.json")
Expand Down
12 changes: 8 additions & 4 deletions tests/general_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ mod tests {
#[test]
fn ping() {
let mut server = Server::new();
let mock_ping = server.mock("GET", "/api/v3/ping")
let mock_ping = server
.mock("GET", "/api/v3/ping")
.with_header("content-type", "application/json;charset=UTF-8")
.with_body("{}")
.create();
Expand All @@ -29,7 +30,8 @@ mod tests {
#[test]
fn get_server_time() {
let mut server = Server::new();
let mock_server_time = server.mock("GET", "/api/v3/time")
let mock_server_time = server
.mock("GET", "/api/v3/time")
.with_header("content-type", "application/json;charset=UTF-8")
.with_body_from_file("tests/mocks/general/server_time.json")
.create();
Expand All @@ -46,7 +48,8 @@ mod tests {
#[test]
fn exchange_info() {
let mut server = Server::new();
let mock_exchange_info = server.mock("GET", "/api/v3/exchangeInfo")
let mock_exchange_info = server
.mock("GET", "/api/v3/exchangeInfo")
.with_header("content-type", "application/json;charset=UTF-8")
.with_body_from_file("tests/mocks/general/exchange_info.json")
.create();
Expand All @@ -63,7 +66,8 @@ mod tests {
#[test]
fn get_symbol_info() {
let mut server = Server::new();
let mock_exchange_info = server.mock("GET", "/api/v3/exchangeInfo")
let mock_exchange_info = server
.mock("GET", "/api/v3/exchangeInfo")
.with_header("content-type", "application/json;charset=UTF-8")
.with_body_from_file("tests/mocks/general/exchange_info.json")
.create();
Expand Down
Loading

0 comments on commit ebcbe78

Please sign in to comment.