Skip to content
This repository has been archived by the owner on Oct 30, 2023. It is now read-only.

Update wallet endpoints #397

Open
wants to merge 17 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 9 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
23 changes: 21 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@
</licenses>

<properties>
<java.version>11</java.version>
<spring-boot.repackage.skip>true</spring-boot.repackage.skip>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<com.squareup.retrofit2.version>2.4.0</com.squareup.retrofit2.version>
</properties>

Expand Down Expand Up @@ -52,11 +56,26 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.7.0</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
<source>${java.version}</source>
<target>${java.version}</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
<version>3.2.1</version>
<executions>
<execution>
<id>attach-sources</id>
<phase>verify</phase>
<goals>
<goal>jar-no-fork</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>

Expand Down
37 changes: 23 additions & 14 deletions src/main/java/com/binance/api/client/BinanceApiAsyncRestClient.java
Original file line number Diff line number Diff line change
@@ -1,15 +1,6 @@
package com.binance.api.client;

import com.binance.api.client.domain.account.Account;
import com.binance.api.client.domain.account.DepositAddress;
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.Trade;
import com.binance.api.client.domain.account.TradeHistoryItem;
import com.binance.api.client.domain.account.WithdrawHistory;
import com.binance.api.client.domain.account.WithdrawResult;
import com.binance.api.client.domain.account.*;
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.CancelOrderResponse;
Expand Down Expand Up @@ -264,28 +255,46 @@ public interface BinanceApiAsyncRestClient {
* @param name description/alias of the address
* @param addressTag Secondary address identifier for coins like XRP,XMR etc.
*/
void withdraw(String asset, String address, String amount, String name, String addressTag, BinanceApiCallback<WithdrawResult> callback);
void withdraw(String coin, String clientOrderId, String network, String address, String addressTag,
String amount, Boolean feeFlag, String name, BinanceApiCallback<WithdrawResult> 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);
void getDepositHistory(String coin, BinanceApiCallback<List<Deposit>> callback);


/**
* Fetch account deposit history.
*
* @param callback the callback that handles the response and returns the deposit history
*/
void getDepositHistory(String coin, int status, Long startTime, Long endTime,
int offset, int limit, BinanceApiCallback<List<Deposit>> callback);

/**
* Fetch account withdraw history.
*
* @param callback the callback that handles the response and returns the withdraw history
*/
void getWithdrawHistory(String coin, BinanceApiCallback<List<Withdraw>> 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);
void getWithdrawHistory(String coin, int status, Long startTime, Long endTime,
int offset, int limit, BinanceApiCallback<List<Withdraw>> callback);

/**
* Fetch deposit address.
*
* @param callback the callback that handles the response and returns the deposit address
*/
void getDepositAddress(String asset, BinanceApiCallback<DepositAddress> callback);
void getDepositAddress(String asset, String network, BinanceApiCallback<DepositAddress> callback);

// User stream endpoints

Expand Down
44 changes: 28 additions & 16 deletions src/main/java/com/binance/api/client/BinanceApiRestClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,9 @@

import com.binance.api.client.domain.account.*;
import com.binance.api.client.domain.account.request.*;
import com.binance.api.client.domain.general.ExchangeInfo;
import com.binance.api.client.domain.general.Asset;
import com.binance.api.client.domain.market.AggTrade;
import com.binance.api.client.domain.market.BookTicker;
import com.binance.api.client.domain.market.Candlestick;
import com.binance.api.client.domain.market.CandlestickInterval;
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 com.binance.api.client.domain.general.ExchangeInfo;
import com.binance.api.client.domain.market.*;

import java.util.List;

Expand Down Expand Up @@ -265,13 +259,14 @@ public interface BinanceApiRestClient {
*
* Enable Withdrawals option has to be active in the API settings.
*
* @param asset asset symbol to withdraw
* @param coin asset symbol to withdraw
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not all params documented

* @param address address to withdraw to
* @param amount amount to withdraw
* @param name description/alias of the address
* @param addressTag Secondary address identifier for coins like XRP,XMR etc.
*/
WithdrawResult withdraw(String asset, String address, String amount, String name, String addressTag);
WithdrawResult withdraw(String coin, String clientOrderId, String network, String address, String amount,
String name, String addressTag, Boolean feeFlag);

/**
* Conver a list of assets to BNB
Expand All @@ -284,14 +279,30 @@ public interface BinanceApiRestClient {
*
* @return deposit history, containing a list of deposits
*/
DepositHistory getDepositHistory(String asset);
List<Deposit> getDepositHistory(String coin);

/**
* Fetch account deposit history.
*
* @return deposit history, containing a list of deposits
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Param description missing

*/
List<Deposit> getDepositHistory(String coin, int status, Long startTime, Long endTime,
int offset, int limit);

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

/**
* Fetch account withdraw history.
*
* @return withdraw history, containing a list of withdrawals
*/
List<Withdraw> getWithdrawHistory(String coin, int status, Long startTime, Long endTime,
int offset, int limit);

/**
* Fetch sub-account transfer history.
Expand All @@ -301,11 +312,12 @@ public interface BinanceApiRestClient {
List<SubAccountTransfer> getSubAccountTransfers();

/**
* Fetch deposit address.
*
* @return deposit address for a given asset.
* Fetch deposit address supported network.
* @param asset coin property
* @param network network property
* @return deposit address for given network and asset
*/
DepositAddress getDepositAddress(String asset);
DepositAddress getDepositAddress(String asset, String network);

// User stream endpoints

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,7 @@
import com.binance.api.client.BinanceApiCallback;
import com.binance.api.client.config.BinanceApiConfig;
import com.binance.api.client.constant.BinanceApiConstants;
import com.binance.api.client.domain.account.Account;
import com.binance.api.client.domain.account.DepositAddress;
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.Trade;
import com.binance.api.client.domain.account.TradeHistoryItem;
import com.binance.api.client.domain.account.WithdrawHistory;
import com.binance.api.client.domain.account.WithdrawResult;
import com.binance.api.client.domain.account.*;
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.CancelOrderResponse;
Expand Down Expand Up @@ -209,26 +200,47 @@ public void getMyTrades(String symbol, BinanceApiCallback<List<Trade>> callback)
}

@Override
public void withdraw(String asset, String address, String amount, String name, String addressTag, BinanceApiCallback<WithdrawResult> callback) {
binanceApiService.withdraw(asset, address, amount, name, addressTag, BinanceApiConstants.DEFAULT_RECEIVING_WINDOW, System.currentTimeMillis())
public void withdraw(String coin, String clientOrderId, String network, String address, String addressTag,
String amount, Boolean feeFlag, String name, BinanceApiCallback<WithdrawResult> callback) {
binanceApiService.withdraw(coin, clientOrderId, network, address, addressTag, amount, feeFlag, name,
BinanceApiConstants.DEFAULT_RECEIVING_WINDOW, System.currentTimeMillis())
.enqueue(new BinanceApiCallbackAdapter<>(callback));
}


@Override
public void getDepositHistory(String coin, BinanceApiCallback<List<Deposit>> callback) {
binanceApiService.getDepositHistory(coin, 0, null, null, 0, 1000,

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The second parameter uses 0 (status) which will result in getting only those deposits, which status is 0 = pending. One should use null instead to get all deposits. For that you should update BinanceApiService interface and use Integer for status field in order to provide null value.
Another way of defaulting would by setting status to 1. This way you will get successful deposits defaultly.

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())
public void getDepositHistory(String coin, int status, Long startTime, Long endTime,
int offset, int limit, BinanceApiCallback<List<Deposit>> callback) {
binanceApiService.getDepositHistory(coin, status, startTime, endTime, offset, limit,
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())
public void getWithdrawHistory(String coin, BinanceApiCallback<List<Withdraw>> callback) {
binanceApiService.getWithdrawHistory(coin, 0, null, null, 0, 1000,

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same thing as with deposit history. Additionally the new withdrawOrderId is missing. Would be nice to have this in the branch. https://binance-docs.github.io/apidocs/spot/en/#withdraw-history-supporting-network-user_data

BinanceApiConstants.DEFAULT_RECEIVING_WINDOW, System.currentTimeMillis())
.enqueue(new BinanceApiCallbackAdapter<>(callback));
}

@Override
public void getWithdrawHistory(String coin, int status, Long startTime, Long endTime,
int offset, int limit, BinanceApiCallback<List<Withdraw>> callback) {
binanceApiService.getWithdrawHistory(coin, status, startTime, endTime, offset, limit,
BinanceApiConstants.DEFAULT_RECEIVING_WINDOW, System.currentTimeMillis())
.enqueue(new BinanceApiCallbackAdapter<>(callback));
}

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -229,8 +229,10 @@ public List<Trade> getMyTrades(String symbol, Long fromId) {
}

@Override
public WithdrawResult withdraw(String asset, String address, String amount, String name, String addressTag) {
return executeSync(binanceApiService.withdraw(asset, address, amount, name, addressTag,
public WithdrawResult withdraw(String coin, String clientOrderId, String network, String address, String amount,
String name, String addressTag, Boolean feeFlag) {
return executeSync(binanceApiService.withdraw(coin, clientOrderId, network, address,
addressTag, amount, feeFlag, name,
BinanceApiConstants.DEFAULT_RECEIVING_WINDOW, System.currentTimeMillis()));
}

Expand All @@ -240,15 +242,29 @@ public DustTransferResponse dustTranfer(List<String> asset) {
}

@Override
public DepositHistory getDepositHistory(String asset) {
return executeSync(binanceApiService.getDepositHistory(asset, BinanceApiConstants.DEFAULT_RECEIVING_WINDOW,
System.currentTimeMillis()));
public List<Deposit> getDepositHistory(String coin) {
return executeSync(binanceApiService.getDepositHistory(coin, 0, null, null, 0, 1000,
BinanceApiConstants.DEFAULT_RECEIVING_WINDOW, System.currentTimeMillis()));
}

@Override
public WithdrawHistory getWithdrawHistory(String asset) {
return executeSync(binanceApiService.getWithdrawHistory(asset, BinanceApiConstants.DEFAULT_RECEIVING_WINDOW,
System.currentTimeMillis()));
public List<Deposit> getDepositHistory(String coin, int status, Long startTime, Long endTime,
int offset, int limit) {
return executeSync(binanceApiService.getDepositHistory(coin, status, startTime, endTime, offset, limit,
BinanceApiConstants.DEFAULT_RECEIVING_WINDOW, System.currentTimeMillis()));
}

@Override
public List<Withdraw> getWithdrawHistory(String coin) {
return executeSync(binanceApiService.getWithdrawHistory(coin, 0, null, null, 0, 1000,
BinanceApiConstants.DEFAULT_RECEIVING_WINDOW, System.currentTimeMillis()));
}

@Override
public List<Withdraw> getWithdrawHistory(String coin, int status, Long startTime, Long endTime,
int offset, int limit) {
return executeSync(binanceApiService.getWithdrawHistory(coin, status, startTime, endTime, offset, limit,
BinanceApiConstants.DEFAULT_RECEIVING_WINDOW, System.currentTimeMillis()));
}

@Override
Expand All @@ -257,8 +273,8 @@ public List<SubAccountTransfer> getSubAccountTransfers() {
}

@Override
public DepositAddress getDepositAddress(String asset) {
return executeSync(binanceApiService.getDepositAddress(asset, BinanceApiConstants.DEFAULT_RECEIVING_WINDOW,
public DepositAddress getDepositAddress(String asset, String network) {
return executeSync(binanceApiService.getDepositAddress(asset, network, BinanceApiConstants.DEFAULT_RECEIVING_WINDOW,
System.currentTimeMillis()));
}

Expand Down
25 changes: 17 additions & 8 deletions src/main/java/com/binance/api/client/impl/BinanceApiService.java
Original file line number Diff line number Diff line change
Expand Up @@ -152,22 +152,31 @@ Call<List<Trade>> getMyTrades(@Query("symbol") String symbol, @Query("limit") In
@Query("recvWindow") Long recvWindow, @Query("timestamp") Long timestamp);

@Headers(BinanceApiConstants.ENDPOINT_SECURITY_TYPE_SIGNED_HEADER)
@POST("/wapi/v3/withdraw.html")
Call<WithdrawResult> withdraw(@Query("asset") String asset, @Query("address") String address, @Query("amount") String amount, @Query("name") String name, @Query("addressTag") String addressTag,
@POST("/sapi/v1/capital/withdraw/apply")
Call<WithdrawResult> withdraw(@Query("coin") String coin,@Query("withdrawOrderId") String clientOrderId,
@Query("network") String network, @Query("address") String address,
@Query("addressTag") String addressTag, @Query("amount") String amount,
@Query("transactionFeeFlag") Boolean feeFlag, @Query("name") String name,
@Query("recvWindow") Long recvWindow, @Query("timestamp") Long timestamp);


@Headers(BinanceApiConstants.ENDPOINT_SECURITY_TYPE_SIGNED_HEADER)
@GET("/wapi/v3/depositHistory.html")
Call<DepositHistory> getDepositHistory(@Query("asset") String asset, @Query("recvWindow") Long recvWindow, @Query("timestamp") Long timestamp);
@GET("/sapi/v1/capital/deposit/hisrec")
Call<List<Deposit>> getDepositHistory(@Query("coin") String coin, @Query("status") int status,
@Query("startTime") Long startTime, @Query("endTime") Long endTime,
@Query("offset") int offset, @Query("limit") int limit,
@Query("recvWindow") Long recvWindow, @Query("timestamp") Long timestamp);

@Headers(BinanceApiConstants.ENDPOINT_SECURITY_TYPE_SIGNED_HEADER)
@GET("/wapi/v3/withdrawHistory.html")
Call<WithdrawHistory> getWithdrawHistory(@Query("asset") String asset, @Query("recvWindow") Long recvWindow, @Query("timestamp") Long timestamp);
@GET("/sapi/v1/capital/withdraw/history")
Call<List<Withdraw>> getWithdrawHistory(@Query("coin") String coin, @Query("status") int status,
@Query("startTime") Long startTime, @Query("endTime") Long endTime,
@Query("offset") int offset, @Query("limit") int limit,
@Query("recvWindow") Long recvWindow, @Query("timestamp") Long timestamp);

@Headers(BinanceApiConstants.ENDPOINT_SECURITY_TYPE_SIGNED_HEADER)
@GET("/wapi/v3/depositAddress.html")
Call<DepositAddress> getDepositAddress(@Query("asset") String asset, @Query("recvWindow") Long recvWindow, @Query("timestamp") Long timestamp);
@GET("/sapi/v1/capital/deposit/address")
Call<DepositAddress> getDepositAddress(@Query("coin") String asset, @Query("network") String network, @Query("recvWindow") Long recvWindow, @Query("timestamp") Long timestamp);

@Headers(BinanceApiConstants.ENDPOINT_SECURITY_TYPE_SIGNED_HEADER)
@POST("/sapi/v1/asset/dust")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,9 @@ public static void main(String[] args) {
System.out.println(client.getDepositHistory("ETH"));

// Get deposit address
System.out.println(client.getDepositAddress("ETH"));
System.out.println(client.getDepositAddress("ETH", null));

// Withdraw
client.withdraw("ETH", "0x123", "0.1", null, null);
client.withdraw("ETH", null, "ERC20", "0x123", "0.1", null, null, false);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,6 @@ public static void main(String[] args) {
client.getDepositHistory("ETH", response -> System.out.println(response));

// Withdraw (async)
client.withdraw("ETH", "0x123", "0.1", null, null, response -> {});
client.withdraw("ETH", null, "ERC20", "0x123", null, "0.1", false, null, response -> {});
}
}