diff --git a/examples/binance_endpoints.rs b/examples/binance_endpoints.rs index e417a93e..8ea7bc6d 100644 --- a/examples/binance_endpoints.rs +++ b/examples/binance_endpoints.rs @@ -4,7 +4,6 @@ use binance::config::*; use binance::general::*; use binance::account::*; use binance::market::*; -use binance::withdraw::*; use binance::model::KlineSummary; use binance::errors::ErrorKind as BinanceLibErrorKind; @@ -17,11 +16,10 @@ fn main() { // The market data API endpoint market_data(); - // The account data, withdrawal, and savings API endpoint examples need an API key. Change those lines locally + // The account data API and savings API endpoint examples need an API key. Change those lines locally // and uncomment the line below (and do not commit your api key :)). //account(); //savings(); - //withdrawal() } fn general(use_testnet: bool) { @@ -158,24 +156,6 @@ fn savings() { } } -#[allow(dead_code)] -fn withdrawal() { - let api_key = Some("YOUR_API_KEY".into()); - let secret_key = Some("YOUR_SECRET_KEY".into()); - - let wapi: Withdraw = Binance::new(api_key, secret_key); - - match wapi.get_trade_fees() { - Ok(answer) => println!("{:#?}", answer), - Err(e) => println!("Error: {}", e), - } - - match wapi.get_asset_details() { - Ok(answer) => println!("{:#?}", answer), - Err(e) => println!("Error: {}", e), - } -} - #[allow(dead_code)] fn market_data() { let market: Market = Binance::new(None, None); diff --git a/src/api.rs b/src/api.rs index 08a6b717..e95ff911 100644 --- a/src/api.rs +++ b/src/api.rs @@ -9,14 +9,12 @@ use crate::general::General; use crate::market::Market; use crate::userstream::UserStream; use crate::savings::Savings; -use crate::withdraw::Withdraw; #[allow(clippy::all)] pub enum API { Spot(Spot), Savings(Sapi), Futures(Futures), - Withdraw(Wapi), } /// Endpoint for production and test orders. @@ -53,6 +51,8 @@ pub enum Sapi { AssetDetail, DepositAddress, SpotFuturesTransfer, + TradeFee, + Withdraw, } pub enum Futures { @@ -95,13 +95,6 @@ pub enum Futures { Income, } -pub enum Wapi { - TradeFee, - AssetDetail, - DepositAddress, - Withdraw, -} - impl From for String { fn from(item: API) -> Self { String::from(match item { @@ -135,6 +128,8 @@ impl From for String { Sapi::AssetDetail => "/sapi/v1/asset/assetDetail", Sapi::DepositAddress => "/sapi/v1/capital/deposit/address", Sapi::SpotFuturesTransfer => "/sapi/v1/futures/transfer", + Sapi::TradeFee => "/sapi/v1/asset/tradeFee", + Sapi::Withdraw => "/sapi/v1/capital/withdraw/apply", }, API::Futures(route) => match route { Futures::Ping => "/fapi/v1/ping", @@ -175,12 +170,6 @@ impl From for String { Futures::UserDataStream => "/fapi/v1/listenKey", Futures::Income => "/fapi/v1/income", }, - API::Withdraw(route) => match route { - Wapi::TradeFee => "/wapi/v3/tradeFee", - Wapi::AssetDetail => "/wapi/v3/assetDetail", - Wapi::DepositAddress => "/wapi/v3/depositAddress", - Wapi::Withdraw => "/wapi/v3/withdraw", - }, }) } } @@ -266,21 +255,6 @@ impl Binance for UserStream { } } -impl Binance for Withdraw { - fn new(api_key: Option, secret_key: Option) -> Withdraw { - Self::new_with_config(api_key, secret_key, &Config::default()) - } - - fn new_with_config( - api_key: Option, secret_key: Option, config: &Config, - ) -> Withdraw { - Withdraw { - client: Client::new(api_key, secret_key, config.rest_api_endpoint.clone()), - recv_window: config.recv_window, - } - } -} - // ***************************************************** // Binance Futures API // ***************************************************** diff --git a/src/lib.rs b/src/lib.rs index 98a7de03..2b8e4396 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -29,6 +29,5 @@ pub mod market; pub mod savings; pub mod userstream; pub mod websockets; -pub mod withdraw; pub mod futures; diff --git a/src/model.rs b/src/model.rs index f51ecba1..9c86b834 100644 --- a/src/model.rs +++ b/src/model.rs @@ -1265,14 +1265,6 @@ pub struct AssetDetail { pub deposit_tip: Option, } -#[derive(Debug, Serialize, Deserialize, Clone)] -#[serde(rename_all = "camelCase")] -pub struct AssetDetails { - pub success: bool, - #[serde(rename = "assetDetail")] - pub asset_details: std::collections::HashMap, -} - #[derive(Debug, Serialize, Deserialize, Clone)] pub struct DepositAddress { pub address: String, diff --git a/src/savings.rs b/src/savings.rs index fbde1279..ae6dd250 100644 --- a/src/savings.rs +++ b/src/savings.rs @@ -1,5 +1,5 @@ use crate::util::build_signed_request; -use crate::model::{AssetDetail, CoinInfo, DepositAddress, SpotFuturesTransferType, TransactionId}; +use crate::model::{AssetDetail, CoinInfo, DepositAddress, SpotFuturesTransferType, TradeFees, TransactionId, WithdrawResponse}; use crate::client::Client; use crate::errors::Result; use std::collections::BTreeMap; @@ -31,6 +31,13 @@ impl Savings { .get_signed(API::Savings(Sapi::AssetDetail), Some(request)) } + // Maker and Taker trade fees for each asset pair + pub fn get_trade_fees(&self) -> Result { + let parameters: BTreeMap = BTreeMap::new(); + let request = build_signed_request(parameters, self.recv_window)?; + self.client.get_signed(API::Savings(Sapi::TradeFee), Some(request)) + } + /// Fetch deposit address with network. /// /// You can get the available networks using `get_all_coins`. @@ -63,4 +70,20 @@ impl Savings { self.client .post_signed(API::Savings(Sapi::SpotFuturesTransfer), request) } + + // Withdraw currency + pub fn withdraw_currency(&self, asset: S, address: S, address_tag: Option, amount: f64) -> Result + where + S: Into, + { + let mut parameters = BTreeMap::new(); + parameters.insert("asset".into(), asset.into()); + parameters.insert("address".into(), address.into()); + if address_tag.is_some() { + parameters.insert("addressTag".into(), address_tag.unwrap().to_string()); + } + parameters.insert("amount".into(), amount.to_string()); + let request = build_signed_request(parameters, self.recv_window)?; + self.client.get_signed(API::Savings(Sapi::Withdraw), Some(request)) + } } diff --git a/src/withdraw.rs b/src/withdraw.rs deleted file mode 100644 index a77f6cbb..00000000 --- a/src/withdraw.rs +++ /dev/null @@ -1,57 +0,0 @@ -use crate::{ - util::build_signed_request, - model::{TradeFees, AssetDetails, DepositAddress, WithdrawResponse}, - client::Client, - errors::Result, - api::{API, Wapi}, -}; -use std::collections::BTreeMap; - -#[derive(Clone)] -pub struct Withdraw { - pub client: Client, - pub recv_window: u64, -} - -impl Withdraw { - // Maker and Taker trade fees for each asset pair - pub fn get_trade_fees(&self) -> Result { - let parameters: BTreeMap = BTreeMap::new(); - let request = build_signed_request(parameters, self.recv_window)?; - self.client.get_signed(API::Withdraw(Wapi::TradeFee), Some(request)) - } - - // Fetch asset details: min_withdraw_amount, deposit_status, withdraw_fee, withdraw_status, Option - pub fn get_asset_details(&self) -> Result { - let parameters: BTreeMap = BTreeMap::new(); - let request = build_signed_request(parameters, self.recv_window)?; - self.client.get_signed(API::Withdraw(Wapi::AssetDetail), Some(request)) - } - - // Depoist Address to given Asset - pub fn get_deposit_address(&self, asset: S) -> Result - where - S: Into, - { - let mut parameters = BTreeMap::new(); - parameters.insert("asset".into(), asset.into()); - let request = build_signed_request(parameters, self.recv_window)?; - self.client.get_signed(API::Withdraw(Wapi::DepositAddress), Some(request)) - } - - // Withdraw currency - pub fn withdraw_currency(&self, asset: S, address: S, address_tag: Option, amount: f64) -> Result - where - S: Into, - { - let mut parameters = BTreeMap::new(); - parameters.insert("asset".into(), asset.into()); - parameters.insert("address".into(), address.into()); - if address_tag.is_some() { - parameters.insert("addressTag".into(), address_tag.unwrap().to_string()); - } - parameters.insert("amount".into(), amount.to_string()); - let request = build_signed_request(parameters, self.recv_window)?; - self.client.get_signed(API::Withdraw(Wapi::Withdraw), Some(request)) - } -} \ No newline at end of file