diff --git a/examples/binance_save_all_trades.rs b/examples/binance_save_all_trades.rs index fe711775..d065a9dd 100644 --- a/examples/binance_save_all_trades.rs +++ b/examples/binance_save_all_trades.rs @@ -17,7 +17,7 @@ fn save_all_trades_websocket() { impl WebSocketHandler { pub fn new(local_wrt: Writer) -> Self { - WebSocketHandler { wrt: local_wrt } + Self { wrt: local_wrt } } // serialize DayTickerEvent as CSV records diff --git a/src/api.rs b/src/api.rs index 17169a33..b663e606 100644 --- a/src/api.rs +++ b/src/api.rs @@ -91,7 +91,7 @@ pub enum Futures { impl From for String { fn from(item: API) -> Self { - String::from(match item { + Self::from(match item { API::Spot(route) => match route { Spot::Ping => "/api/v3/ping", Spot::Time => "/api/v3/time", @@ -170,28 +170,28 @@ pub trait Binance { } impl Binance for General { - fn new(api_key: Option, secret_key: Option) -> General { + fn new(api_key: Option, secret_key: Option) -> Self { Self::new_with_config(api_key, secret_key, &Config::default()) } fn new_with_config( api_key: Option, secret_key: Option, config: &Config, - ) -> General { - General { + ) -> Self { + Self { client: Client::new(api_key, secret_key, config.rest_api_endpoint.clone()), } } } impl Binance for Account { - fn new(api_key: Option, secret_key: Option) -> Account { + fn new(api_key: Option, secret_key: Option) -> Self { Self::new_with_config(api_key, secret_key, &Config::default()) } fn new_with_config( api_key: Option, secret_key: Option, config: &Config, - ) -> Account { - Account { + ) -> Self { + Self { client: Client::new(api_key, secret_key, config.rest_api_endpoint.clone()), recv_window: config.recv_window, } @@ -214,14 +214,14 @@ impl Binance for Savings { } impl Binance for Market { - fn new(api_key: Option, secret_key: Option) -> Market { + fn new(api_key: Option, secret_key: Option) -> Self { Self::new_with_config(api_key, secret_key, &Config::default()) } fn new_with_config( api_key: Option, secret_key: Option, config: &Config, - ) -> Market { - Market { + ) -> Self { + Self { client: Client::new(api_key, secret_key, config.rest_api_endpoint.clone()), recv_window: config.recv_window, } @@ -229,14 +229,14 @@ impl Binance for Market { } impl Binance for UserStream { - fn new(api_key: Option, secret_key: Option) -> UserStream { + fn new(api_key: Option, secret_key: Option) -> Self { Self::new_with_config(api_key, secret_key, &Config::default()) } fn new_with_config( api_key: Option, secret_key: Option, config: &Config, - ) -> UserStream { - UserStream { + ) -> Self { + Self { client: Client::new(api_key, secret_key, config.rest_api_endpoint.clone()), recv_window: config.recv_window, } @@ -248,14 +248,14 @@ impl Binance for UserStream { // ***************************************************** impl Binance for FuturesGeneral { - fn new(api_key: Option, secret_key: Option) -> FuturesGeneral { + fn new(api_key: Option, secret_key: Option) -> Self { Self::new_with_config(api_key, secret_key, &Config::default()) } fn new_with_config( api_key: Option, secret_key: Option, config: &Config, - ) -> FuturesGeneral { - FuturesGeneral { + ) -> Self { + Self { client: Client::new( api_key, secret_key, @@ -266,14 +266,14 @@ impl Binance for FuturesGeneral { } impl Binance for FuturesMarket { - fn new(api_key: Option, secret_key: Option) -> FuturesMarket { + fn new(api_key: Option, secret_key: Option) -> Self { Self::new_with_config(api_key, secret_key, &Config::default()) } fn new_with_config( api_key: Option, secret_key: Option, config: &Config, - ) -> FuturesMarket { - FuturesMarket { + ) -> Self { + Self { client: Client::new( api_key, secret_key, @@ -304,14 +304,14 @@ impl Binance for FuturesAccount { } impl Binance for FuturesUserStream { - fn new(api_key: Option, secret_key: Option) -> FuturesUserStream { + fn new(api_key: Option, secret_key: Option) -> Self { Self::new_with_config(api_key, secret_key, &Config::default()) } fn new_with_config( api_key: Option, secret_key: Option, config: &Config, - ) -> FuturesUserStream { - FuturesUserStream { + ) -> Self { + Self { client: Client::new( api_key, secret_key, diff --git a/src/client.rs b/src/client.rs index 35032262..4c3dfe42 100644 --- a/src/client.rs +++ b/src/client.rs @@ -19,7 +19,7 @@ pub struct Client { impl Client { pub fn new(api_key: Option, secret_key: Option, host: String) -> Self { - Client { + Self { api_key: api_key.unwrap_or_default(), secret_key: secret_key.unwrap_or_default(), host, diff --git a/src/futures/account.rs b/src/futures/account.rs index 7066669c..f06ce490 100644 --- a/src/futures/account.rs +++ b/src/futures/account.rs @@ -29,11 +29,11 @@ pub enum ContractType { impl From for String { fn from(item: ContractType) -> Self { match item { - ContractType::Perpetual => String::from("PERPETUAL"), - ContractType::CurrentMonth => String::from("CURRENT_MONTH"), - ContractType::NextMonth => String::from("NEXT_MONTH"), - ContractType::CurrentQuarter => String::from("CURRENT_QUARTER"), - ContractType::NextQuarter => String::from("NEXT_QUARTER"), + ContractType::Perpetual => Self::from("PERPETUAL"), + ContractType::CurrentMonth => Self::from("CURRENT_MONTH"), + ContractType::NextMonth => Self::from("NEXT_MONTH"), + ContractType::CurrentQuarter => Self::from("CURRENT_QUARTER"), + ContractType::NextQuarter => Self::from("NEXT_QUARTER"), } } } diff --git a/src/futures/websockets.rs b/src/futures/websockets.rs index 4fe76ff8..a8619aa1 100755 --- a/src/futures/websockets.rs +++ b/src/futures/websockets.rs @@ -37,13 +37,13 @@ impl FuturesWebsocketAPI { }; match self { - FuturesWebsocketAPI::Default => { + Self::Default => { format!("{}/ws/{}", baseurl, subscription) } - FuturesWebsocketAPI::MultiStream => { + Self::MultiStream => { format!("{}/stream?streams={}", baseurl, subscription) } - FuturesWebsocketAPI::Custom(url) => url, + Self::Custom(url) => url, } } } diff --git a/src/lib.rs b/src/lib.rs index 2b8e4396..75343bff 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -12,7 +12,8 @@ clippy::manual_string_new, clippy::single_match_else, clippy::implicit_clone, - clippy::semicolon_if_nothing_returned + clippy::semicolon_if_nothing_returned, + clippy::use_self )] mod client; diff --git a/src/model.rs b/src/model.rs index 3dfc1812..0abc7510 100644 --- a/src/model.rs +++ b/src/model.rs @@ -250,8 +250,8 @@ pub struct Bids { } impl Bids { - pub fn new(price: f64, qty: f64) -> Bids { - Bids { price, qty } + pub fn new(price: f64, qty: f64) -> Self { + Self { price, qty } } } diff --git a/src/websockets.rs b/src/websockets.rs index 0ed7fb2f..99f02466 100644 --- a/src/websockets.rs +++ b/src/websockets.rs @@ -25,12 +25,12 @@ enum WebsocketAPI { impl WebsocketAPI { fn params(self, subscription: &str) -> String { match self { - WebsocketAPI::Default => format!("wss://stream.binance.com:9443/ws/{}", subscription), - WebsocketAPI::MultiStream => format!( + Self::Default => format!("wss://stream.binance.com:9443/ws/{}", subscription), + Self::MultiStream => format!( "wss://stream.binance.com:9443/stream?streams={}", subscription ), - WebsocketAPI::Custom(url) => format!("{}/{}", url, subscription), + Self::Custom(url) => format!("{}/{}", url, subscription), } } }