Skip to content

Commit

Permalink
Add support for consulting withdraw and deposit history.
Browse files Browse the repository at this point in the history
  • Loading branch information
joaopsilva committed Oct 19, 2017
1 parent 341d9cd commit fef98d5
Show file tree
Hide file tree
Showing 15 changed files with 477 additions and 14 deletions.
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
package com.binance.api.client;

import com.binance.api.client.domain.account.Account;
import com.binance.api.client.domain.account.DepositHistory;
import com.binance.api.client.domain.account.NewOrder;
import com.binance.api.client.domain.account.NewOrderResponse;
import com.binance.api.client.domain.account.Order;
import com.binance.api.client.domain.account.WithdrawHistory;
import com.binance.api.client.domain.account.request.AllOrdersRequest;
import com.binance.api.client.domain.account.request.CancelOrderRequest;
import com.binance.api.client.domain.account.request.OrderRequest;
Expand Down Expand Up @@ -173,6 +175,32 @@ public interface BinanceApiAsyncRestClient {
*/
void getAccount(BinanceApiCallback<Account> callback);

/**
* Submit a withdraw request.
*
* Enable Withdrawals option has to be active in the API settings.
*
* @param asset asset symbol to withdraw
* @param address address to withdraw to
* @param amount amount to withdraw
* @param name description/alias of the address
*/
void withdraw(String asset, String address, String amount, String name, BinanceApiCallback<Void> callback);

/**
* Fetch account deposit history.
*
* @param callback the callback that handles the response and returns the deposit history
*/
void getDepositHistory(String asset, BinanceApiCallback<DepositHistory> callback);

/**
* Fetch account withdraw history.
*
* @param callback the callback that handles the response and returns the withdraw history
*/
void getWithdrawHistory(String asset, BinanceApiCallback<WithdrawHistory> callback);

// User stream endpoints

/**
Expand Down
30 changes: 30 additions & 0 deletions src/main/java/com/binance/api/client/BinanceApiRestClient.java
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
package com.binance.api.client;

import com.binance.api.client.domain.account.Account;
import com.binance.api.client.domain.account.DepositHistory;
import com.binance.api.client.domain.account.NewOrder;
import com.binance.api.client.domain.account.NewOrderResponse;
import com.binance.api.client.domain.account.Order;
import com.binance.api.client.domain.account.WithdrawHistory;
import com.binance.api.client.domain.account.request.AllOrdersRequest;
import com.binance.api.client.domain.account.request.CancelOrderRequest;
import com.binance.api.client.domain.account.request.OrderRequest;
Expand All @@ -15,6 +17,8 @@
import com.binance.api.client.domain.market.OrderBook;
import com.binance.api.client.domain.market.TickerPrice;
import com.binance.api.client.domain.market.TickerStatistics;
import retrofit2.Call;
import retrofit2.http.Query;

import java.util.List;

Expand Down Expand Up @@ -162,6 +166,32 @@ public interface BinanceApiRestClient {
*/
Account getAccount();

/**
* Submit a withdraw request.
*
* Enable Withdrawals option has to be active in the API settings.
*
* @param asset asset symbol to withdraw
* @param address address to withdraw to
* @param amount amount to withdraw
* @param name description/alias of the address
*/
void withdraw(String asset, String address, String amount, String name);

/**
* Fetch account deposit history.
*
* @return deposit history, containing a list of deposits
*/
DepositHistory getDepositHistory(String asset);

/**
* Fetch account withdraw history.
*
* @return withdraw history, containing a list of withdrawals
*/
WithdrawHistory getWithdrawHistory(String asset);

// User stream endpoints

/**
Expand Down
60 changes: 60 additions & 0 deletions src/main/java/com/binance/api/client/domain/account/Deposit.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
package com.binance.api.client.domain.account;

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import org.apache.commons.lang3.builder.ToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle;

/**
* A deposit that was done to a Binance account.
*/
@JsonIgnoreProperties(ignoreUnknown = true)
public class Deposit {

/**
* Amount deposited.
*/
private String amount;

/**
* Symbol.
*/
private String asset;

/**
* Deposit time.
*/
private String insertTime;

public String getAmount() {
return amount;
}

public void setAmount(String amount) {
this.amount = amount;
}

public String getAsset() {
return asset;
}

public void setAsset(String asset) {
this.asset = asset;
}

public String getInsertTime() {
return insertTime;
}

public void setInsertTime(String insertTime) {
this.insertTime = insertTime;
}

@Override
public String toString() {
return new ToStringBuilder(this, ToStringStyle.SHORT_PREFIX_STYLE)
.append("amount", amount)
.append("asset", asset)
.append("insertTime", insertTime)
.toString();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package com.binance.api.client.domain.account;

import com.fasterxml.jackson.annotation.JsonProperty;
import org.apache.commons.lang3.builder.ToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle;

import java.util.List;

/**
* History of account deposits.
*
* @see Deposit
*/
public class DepositHistory {

@JsonProperty("withdrawList")
private List<Deposit> depositList;

private boolean success;

public List<Deposit> getDepositList() {
return depositList;
}

public void setDepositList(List<Deposit> depositList) {
this.depositList = depositList;
}

public boolean isSuccess() {
return success;
}

public void setSuccess(boolean success) {
this.success = success;
}

@Override
public String toString() {
return new ToStringBuilder(this, ToStringStyle.SHORT_PREFIX_STYLE)
.append("depositList", depositList)
.append("success", success)
.toString();
}
}
110 changes: 110 additions & 0 deletions src/main/java/com/binance/api/client/domain/account/Withdraw.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
package com.binance.api.client.domain.account;

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import org.apache.commons.lang3.builder.ToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle;

/**
* A withdraw that was done to a Binance account.
*/
@JsonIgnoreProperties(ignoreUnknown = true)
public class Withdraw {

/**
* Amount withdrawn.
*/
private String amount;

/**
* Destination address.
*/
private String address;

/**
* Symbol.
*/
private String asset;

private String applyTime;

private String successTime;

/**
* Ethereum transaction id.
*/
private String txId;

/**
* Id.
*/
private String id;

public String getAmount() {
return amount;
}

public void setAmount(String amount) {
this.amount = amount;
}

public String getAddress() {
return address;
}

public void setAddress(String address) {
this.address = address;
}

public String getAsset() {
return asset;
}

public void setAsset(String asset) {
this.asset = asset;
}

public String getApplyTime() {
return applyTime;
}

public void setApplyTime(String applyTime) {
this.applyTime = applyTime;
}

public String getSuccessTime() {
return successTime;
}

public void setSuccessTime(String successTime) {
this.successTime = successTime;
}

public String getTxId() {
return txId;
}

public void setTxId(String txId) {
this.txId = txId;
}

public String getId() {
return id;
}

public void setId(String id) {
this.id = id;
}

@Override
public String toString() {
return new ToStringBuilder(this, ToStringStyle.SHORT_PREFIX_STYLE)
.append("amount", amount)
.append("address", address)
.append("asset", asset)
.append("applyTime", applyTime)
.append("successTime", successTime)
.append("txId", txId)
.append("id", id)
.toString();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package com.binance.api.client.domain.account;

import org.apache.commons.lang3.builder.ToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle;

import java.util.List;

/**
* History of account withdrawals.
*
* @see Withdraw
*/
public class WithdrawHistory {

private List<Withdraw> withdrawList;

private boolean success;

public List<Withdraw> getWithdrawList() {
return withdrawList;
}

public void setWithdrawList(List<Withdraw> withdrawList) {
this.withdrawList = withdrawList;
}

public boolean isSuccess() {
return success;
}

public void setSuccess(boolean success) {
this.success = success;
}

@Override
public String toString() {
return new ToStringBuilder(this, ToStringStyle.SHORT_PREFIX_STYLE)
.append("withdrawList", withdrawList)
.append("success", success)
.toString();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@
import com.binance.api.client.BinanceApiCallback;
import com.binance.api.client.constant.BinanceApiConstants;
import com.binance.api.client.domain.account.Account;
import com.binance.api.client.domain.account.DepositHistory;
import com.binance.api.client.domain.account.NewOrder;
import com.binance.api.client.domain.account.NewOrderResponse;
import com.binance.api.client.domain.account.Order;
import com.binance.api.client.domain.account.WithdrawHistory;
import com.binance.api.client.domain.account.request.AllOrdersRequest;
import com.binance.api.client.domain.account.request.CancelOrderRequest;
import com.binance.api.client.domain.account.request.OrderRequest;
Expand Down Expand Up @@ -144,6 +146,24 @@ public void getAccount(BinanceApiCallback<Account> callback) {
binanceApiService.getAccount(BinanceApiConstants.DEFAULT_RECEIVING_WINDOW, timestamp).enqueue(new BinanceApiCallbackAdapter<>(callback));
}

@Override
public void withdraw(String asset, String address, String amount, String name, BinanceApiCallback<Void> callback) {
binanceApiService.withdraw(asset, address, amount, name, BinanceApiConstants.DEFAULT_RECEIVING_WINDOW, System.currentTimeMillis())
.enqueue(new BinanceApiCallbackAdapter<>(callback));
}

@Override
public void getDepositHistory(String asset, BinanceApiCallback<DepositHistory> callback) {
binanceApiService.getDepositHistory(asset, BinanceApiConstants.DEFAULT_RECEIVING_WINDOW, System.currentTimeMillis())
.enqueue(new BinanceApiCallbackAdapter<>(callback));
}

@Override
public void getWithdrawHistory(String asset, BinanceApiCallback<WithdrawHistory> callback) {
binanceApiService.getWithdrawHistory(asset, BinanceApiConstants.DEFAULT_RECEIVING_WINDOW, System.currentTimeMillis())
.enqueue(new BinanceApiCallbackAdapter<>(callback));
}

// User stream endpoints

@Override
Expand Down
Loading

0 comments on commit fef98d5

Please sign in to comment.