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: 4 additions & 0 deletions src/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ pub enum Sapi {
AssetDetail,
DepositAddress,
SpotFuturesTransfer,
TradeFee,
Withdraw,
}

pub enum Futures {
Expand Down Expand Up @@ -128,6 +130,8 @@ impl From<API> 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",
Expand Down
17 changes: 17 additions & 0 deletions src/model.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
35 changes: 34 additions & 1 deletion src/savings.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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<String>) -> Result<Vec<TradeFee>> {
let mut parameters: BTreeMap<String, String> = 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`.
Expand Down Expand Up @@ -63,4 +77,23 @@ impl Savings {
self.client
.post_signed(API::Savings(Sapi::SpotFuturesTransfer), request)
}

// Withdraw currency
pub fn withdraw_currency<S>(
&self, asset: S, address: S, address_tag: Option<u64>, amount: f64,
) -> Result<WithdrawResponse>
where
S: Into<String>,
{
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))
}
}