diff --git a/README.md b/README.md index 0b6d5f684..abe0f7c6d 100644 --- a/README.md +++ b/README.md @@ -250,6 +250,19 @@ DepositHistory[depositList=[Deposit[amount=0.100000000000000000,asset=ETH,insert ``` +#### Get deposit address +```java +DepositAddress depositAddress = client.getDepositAddress("ETH"); +System.out.println(depositAddress); +``` +
+ View Response + + ```java +DepositAddress[address=0x99...,success=true,addressTag=,asset=ETH] +``` +
+ ### User stream endpoints #### Start user data stream, keepalive, and close data stream diff --git a/src/main/java/com/binance/api/client/BinanceApiAsyncRestClient.java b/src/main/java/com/binance/api/client/BinanceApiAsyncRestClient.java index 55f5748ed..3a77e85c9 100644 --- a/src/main/java/com/binance/api/client/BinanceApiAsyncRestClient.java +++ b/src/main/java/com/binance/api/client/BinanceApiAsyncRestClient.java @@ -1,6 +1,7 @@ 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; @@ -229,6 +230,13 @@ public interface BinanceApiAsyncRestClient { */ void getWithdrawHistory(String asset, BinanceApiCallback callback); + /** + * Fetch deposit address. + * + * @param callback the callback that handles the response and returns the deposit address + */ + void getDepositAddress(String asset, BinanceApiCallback callback); + // User stream endpoints /** diff --git a/src/main/java/com/binance/api/client/BinanceApiRestClient.java b/src/main/java/com/binance/api/client/BinanceApiRestClient.java index 3031a41a6..df4749a2e 100644 --- a/src/main/java/com/binance/api/client/BinanceApiRestClient.java +++ b/src/main/java/com/binance/api/client/BinanceApiRestClient.java @@ -1,6 +1,7 @@ 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; @@ -218,6 +219,13 @@ public interface BinanceApiRestClient { */ WithdrawHistory getWithdrawHistory(String asset); + /** + * Fetch deposit address. + * + * @return deposit address for a given asset. + */ + DepositAddress getDepositAddress(String asset); + // User stream endpoints /** diff --git a/src/main/java/com/binance/api/client/domain/account/DepositAddress.java b/src/main/java/com/binance/api/client/domain/account/DepositAddress.java new file mode 100644 index 000000000..9279bb76a --- /dev/null +++ b/src/main/java/com/binance/api/client/domain/account/DepositAddress.java @@ -0,0 +1,60 @@ +package com.binance.api.client.domain.account; + +import org.apache.commons.lang3.builder.ToStringBuilder; +import org.apache.commons.lang3.builder.ToStringStyle; + +/** + * A deposit address for a given asset. + */ +public class DepositAddress { + + private String address; + + private boolean success; + + private String addressTag; + + private String asset; + + public String getAddress() { + return address; + } + + public void setAddress(String address) { + this.address = address; + } + + public boolean isSuccess() { + return success; + } + + public void setSuccess(boolean success) { + this.success = success; + } + + public String getAddressTag() { + return addressTag; + } + + public void setAddressTag(String addressTag) { + this.addressTag = addressTag; + } + + public String getAsset() { + return asset; + } + + public void setAsset(String asset) { + this.asset = asset; + } + + @Override + public String toString() { + return new ToStringBuilder(this, ToStringStyle.SHORT_PREFIX_STYLE) + .append("address", address) + .append("success", success) + .append("addressTag", addressTag) + .append("asset", asset) + .toString(); + } +} \ No newline at end of file diff --git a/src/main/java/com/binance/api/client/impl/BinanceApiAsyncRestClientImpl.java b/src/main/java/com/binance/api/client/impl/BinanceApiAsyncRestClientImpl.java index fcd165bd3..73a70c5da 100644 --- a/src/main/java/com/binance/api/client/impl/BinanceApiAsyncRestClientImpl.java +++ b/src/main/java/com/binance/api/client/impl/BinanceApiAsyncRestClientImpl.java @@ -4,6 +4,7 @@ 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.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; @@ -180,6 +181,12 @@ public void getWithdrawHistory(String asset, BinanceApiCallback .enqueue(new BinanceApiCallbackAdapter<>(callback)); } + @Override + public void getDepositAddress(String asset, BinanceApiCallback callback) { + binanceApiService.getDepositAddress(asset, BinanceApiConstants.DEFAULT_RECEIVING_WINDOW, System.currentTimeMillis()) + .enqueue(new BinanceApiCallbackAdapter<>(callback)); + } + // User stream endpoints @Override diff --git a/src/main/java/com/binance/api/client/impl/BinanceApiRestClientImpl.java b/src/main/java/com/binance/api/client/impl/BinanceApiRestClientImpl.java index e41b55b24..a536c7666 100644 --- a/src/main/java/com/binance/api/client/impl/BinanceApiRestClientImpl.java +++ b/src/main/java/com/binance/api/client/impl/BinanceApiRestClientImpl.java @@ -3,6 +3,7 @@ import com.binance.api.client.BinanceApiRestClient; 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; @@ -173,6 +174,11 @@ public WithdrawHistory getWithdrawHistory(String asset) { return executeSync(binanceApiService.getWithdrawHistory(asset, BinanceApiConstants.DEFAULT_RECEIVING_WINDOW, System.currentTimeMillis())); } + @Override + public DepositAddress getDepositAddress(String asset) { + return executeSync(binanceApiService.getDepositAddress(asset, BinanceApiConstants.DEFAULT_RECEIVING_WINDOW, System.currentTimeMillis())); + } + // User stream endpoints @Override diff --git a/src/main/java/com/binance/api/client/impl/BinanceApiService.java b/src/main/java/com/binance/api/client/impl/BinanceApiService.java index d84e1ec6d..10ae03c3f 100644 --- a/src/main/java/com/binance/api/client/impl/BinanceApiService.java +++ b/src/main/java/com/binance/api/client/impl/BinanceApiService.java @@ -5,6 +5,7 @@ import com.binance.api.client.domain.OrderType; import com.binance.api.client.domain.TimeInForce; 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.NewOrderResponse; import com.binance.api.client.domain.account.Order; @@ -123,6 +124,10 @@ Call withdraw(@Query("asset") String asset, @Query("address") String addre @GET("/wapi/v3/withdrawHistory.html") Call getWithdrawHistory(@Query("asset") String asset, @Query("recvWindow") Long recvWindow, @Query("timestamp") Long timestamp); + @Headers(BinanceApiConstants.ENDPOINT_SECURITY_TYPE_SIGNED_HEADER) + @GET("/wapi/v3/depositAddress.html") + Call getDepositAddress(@Query("asset") String asset, @Query("recvWindow") Long recvWindow, @Query("timestamp") Long timestamp); + // User stream endpoints @Headers(BinanceApiConstants.ENDPOINT_SECURITY_TYPE_APIKEY_HEADER) diff --git a/src/test/java/com/binance/api/examples/AccountEndpointsExample.java b/src/test/java/com/binance/api/examples/AccountEndpointsExample.java index 5f96bc89b..bdbaf7469 100644 --- a/src/test/java/com/binance/api/examples/AccountEndpointsExample.java +++ b/src/test/java/com/binance/api/examples/AccountEndpointsExample.java @@ -31,6 +31,9 @@ public static void main(String[] args) { // Get deposit history System.out.println(client.getDepositHistory("ETH")); + // Get deposit address + System.out.println(client.getDepositAddress("ETH")); + // Withdraw client.withdraw("ETH", "0x123", "0.1", null); }