diff --git a/src/api.rs b/src/api.rs index b69c9cc6..acb9c8b8 100644 --- a/src/api.rs +++ b/src/api.rs @@ -51,6 +51,8 @@ pub enum Sapi { AssetDetail, DepositAddress, SpotFuturesTransfer, + TradeFee, + Withdraw, } pub enum Futures { @@ -128,6 +130,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", diff --git a/src/model.rs b/src/model.rs index baedc33f..14e5c804 100644 --- a/src/model.rs +++ b/src/model.rs @@ -1327,6 +1327,23 @@ pub struct DepositAddress { pub url: String, } +#[derive(Debug, Serialize, Deserialize, Clone)] +pub struct WithdrawResponse { + pub msg: String, + pub success: bool, + pub id: String, +} + +#[derive(Debug, Serialize, Deserialize, Clone)] +#[serde(rename_all = "camelCase")] +pub struct TradeFee { + pub symbol: String, + #[serde(with = "string_or_float")] + pub maker_commission: f64, + #[serde(with = "string_or_float")] + pub taker_commission: f64, +} + pub(crate) mod string_or_float { use std::fmt; diff --git a/src/savings.rs b/src/savings.rs index fbde1279..8f79381e 100644 --- a/src/savings.rs +++ b/src/savings.rs @@ -1,5 +1,8 @@ use crate::util::build_signed_request; -use crate::model::{AssetDetail, CoinInfo, DepositAddress, SpotFuturesTransferType, TransactionId}; +use crate::model::{ + AssetDetail, CoinInfo, DepositAddress, SpotFuturesTransferType, TradeFee, TransactionId, + WithdrawResponse, +}; use crate::client::Client; use crate::errors::Result; use std::collections::BTreeMap; @@ -31,6 +34,17 @@ impl Savings { .get_signed(API::Savings(Sapi::AssetDetail), Some(request)) } + /// Maker and Taker trade fees for an asset pair + pub fn get_trade_fee(&self, symbol: Option) -> Result> { + let mut parameters: BTreeMap = BTreeMap::new(); + if let Some(symbol) = symbol { + parameters.insert("symbol".into(), symbol); + } + 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 +77,23 @@ 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 let Some(address_tag) = address_tag { + parameters.insert("addressTag".into(), address_tag.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)) + } }