Skip to content

Commit

Permalink
add missing withdraw method to Sapi and remove deprecated Wapi
Browse files Browse the repository at this point in the history
  • Loading branch information
JoshuaBatty committed Mar 20, 2023
1 parent 56954f8 commit 161a5e0
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 118 deletions.
22 changes: 1 addition & 21 deletions examples/binance_endpoints.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

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

pub enum Futures {
Expand Down Expand Up @@ -95,13 +95,6 @@ pub enum Futures {
Income,
}

pub enum Wapi {
TradeFee,
AssetDetail,
DepositAddress,
Withdraw,
}

impl From<API> for String {
fn from(item: API) -> Self {
String::from(match item {
Expand Down Expand Up @@ -135,6 +128,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 Expand Up @@ -175,12 +170,6 @@ impl From<API> 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",
},
})
}
}
Expand Down Expand Up @@ -266,21 +255,6 @@ impl Binance for UserStream {
}
}

impl Binance for Withdraw {
fn new(api_key: Option<String>, secret_key: Option<String>) -> Withdraw {
Self::new_with_config(api_key, secret_key, &Config::default())
}

fn new_with_config(
api_key: Option<String>, secret_key: Option<String>, config: &Config,
) -> Withdraw {
Withdraw {
client: Client::new(api_key, secret_key, config.rest_api_endpoint.clone()),
recv_window: config.recv_window,
}
}
}

// *****************************************************
// Binance Futures API
// *****************************************************
Expand Down
1 change: 0 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,5 @@ pub mod market;
pub mod savings;
pub mod userstream;
pub mod websockets;
pub mod withdraw;

pub mod futures;
8 changes: 0 additions & 8 deletions src/model.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1265,14 +1265,6 @@ pub struct AssetDetail {
pub deposit_tip: Option<String>,
}

#[derive(Debug, Serialize, Deserialize, Clone)]
#[serde(rename_all = "camelCase")]
pub struct AssetDetails {
pub success: bool,
#[serde(rename = "assetDetail")]
pub asset_details: std::collections::HashMap<String, AssetDetail>,
}

#[derive(Debug, Serialize, Deserialize, Clone)]
pub struct DepositAddress {
pub address: String,
Expand Down
25 changes: 24 additions & 1 deletion src/savings.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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<TradeFees> {
let parameters: BTreeMap<String, String> = 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`.
Expand Down Expand Up @@ -63,4 +70,20 @@ 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 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))
}
}
57 changes: 0 additions & 57 deletions src/withdraw.rs

This file was deleted.

0 comments on commit 161a5e0

Please sign in to comment.