Skip to content

Commit

Permalink
Add support for fetching a deposit address.
Browse files Browse the repository at this point in the history
  • Loading branch information
joaopsilva committed Nov 19, 2017
1 parent 4b265fe commit 3748d49
Show file tree
Hide file tree
Showing 8 changed files with 110 additions and 0 deletions.
13 changes: 13 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,19 @@ DepositHistory[depositList=[Deposit[amount=0.100000000000000000,asset=ETH,insert
```
</details>

#### Get deposit address
```java
DepositAddress depositAddress = client.getDepositAddress("ETH");
System.out.println(depositAddress);
```
<details>
<summary>View Response</summary>

```java
DepositAddress[address=0x99...,success=true,addressTag=,asset=ETH]
```
</details>

### User stream endpoints

#### Start user data stream, keepalive, and close data stream
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -229,6 +230,13 @@ public interface BinanceApiAsyncRestClient {
*/
void getWithdrawHistory(String asset, BinanceApiCallback<WithdrawHistory> callback);

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

// User stream endpoints

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -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();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -180,6 +181,12 @@ public void getWithdrawHistory(String asset, BinanceApiCallback<WithdrawHistory>
.enqueue(new BinanceApiCallbackAdapter<>(callback));
}

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

// User stream endpoints

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -123,6 +124,10 @@ Call<Void> withdraw(@Query("asset") String asset, @Query("address") String addre
@GET("/wapi/v3/withdrawHistory.html")
Call<WithdrawHistory> 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<DepositAddress> getDepositAddress(@Query("asset") String asset, @Query("recvWindow") Long recvWindow, @Query("timestamp") Long timestamp);

// User stream endpoints

@Headers(BinanceApiConstants.ENDPOINT_SECURITY_TYPE_APIKEY_HEADER)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down

0 comments on commit 3748d49

Please sign in to comment.