Skip to content

Commit

Permalink
Merge branch 'master' of github.com:binance-exchange/binance-java-api
Browse files Browse the repository at this point in the history
  • Loading branch information
joaopsilva committed Nov 19, 2017
2 parents fba2a95 + 3748d49 commit f51ee15
Show file tree
Hide file tree
Showing 15 changed files with 428 additions and 12 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ cmake-build-debug/

# IntelliJ
/out/
.idea

# mpeltonen/sbt-idea plugin
.idea_modules/
Expand Down Expand Up @@ -90,4 +91,6 @@ fabric.properties
# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
hs_err_pid*

# Maven
target/
# End of https://www.gitignore.io/api/java,intellij
28 changes: 27 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ binance-java-api is a lightweight Java library for interacting with the [Binance

## Features
* Support for synchronous and asynchronous REST requests to all [General](https://www.binance.com/restapipub.html#user-content-general-endpoints), [Market Data](https://www.binance.com/restapipub.html#user-content-market-data-endpoints), [Account](https://www.binance.com/restapipub.html#user-content-account-endpoints) endpoints, and [User](https://www.binance.com/restapipub.html#user-content-user-data-stream-endpoints) stream endpoints.
* Support for User Data, Trade, and Depth event streaming using [Binance WebSocket API](https://www.binance.com/restapipub.html#wss-endpoint).
* Support for User Data, Trade, Kline, and Depth event streaming using [Binance WebSocket API](https://www.binance.com/restapipub.html#wss-endpoint).

## Installation
1. Install library into your Maven's local repository by running `mvn install`
Expand Down Expand Up @@ -147,6 +147,19 @@ AssetBalance[asset=ETH,free=0.10000000,locked=0.00000000]
```
</details>

#### Get list of trades for an account and a symbol
```java
List<Trade> myTrades = client.getMyTrades("NEOETH");
System.out.println(myTrades);
```
<details>
<summary>View Response</summary>

```java
[Trade[id=123,price=0.00000100,qty=1000.00000000,commission=0.00172100,commissionAsset=ETH,time=1507927870561,buyer=false,maker=false,bestMatch=true,symbol=<null>,orderId=11289], Trade[id=123,price=0.00001000,qty=3.00000000,commission=0.00000003,commissionAsset=ETH,time=1507927874215,buyer=false,maker=false,bestMatch=true,symbol=<null>,orderId=123]]
```
</details>

#### Get account open orders for a symbol
```java
List<Order> openOrders = client.getOpenOrders(new OrderRequest("LINKETH"));
Expand Down Expand Up @@ -239,6 +252,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,10 +1,12 @@
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.WithdrawHistory;
import com.binance.api.client.domain.account.request.AllOrdersRequest;
import com.binance.api.client.domain.account.request.CancelOrderRequest;
Expand Down Expand Up @@ -175,6 +177,33 @@ public interface BinanceApiAsyncRestClient {
*/
void getAccount(BinanceApiCallback<Account> callback);

/**
* Get trades for a specific account and symbol.
*
* @param symbol symbol to get trades from
* @param limit default 500; max 500
* @param fromId TradeId to fetch from. Default gets most recent trades.
* @param callback the callback that handles the response with a list of trades
*/
void getMyTrades(String symbol, Integer limit, Long fromId, Long recvWindow, Long timestamp, BinanceApiCallback<List<Trade>> callback);

/**
* Get trades for a specific account and symbol.
*
* @param symbol symbol to get trades from
* @param limit default 500; max 500
* @param callback the callback that handles the response with a list of trades
*/
void getMyTrades(String symbol, Integer limit, BinanceApiCallback<List<Trade>> callback);

/**
* Get trades for a specific account and symbol.
*
* @param symbol symbol to get trades from
* @param callback the callback that handles the response with a list of trades
*/
void getMyTrades(String symbol, BinanceApiCallback<List<Trade>> callback);

/**
* Submit a withdraw request.
*
Expand All @@ -201,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
38 changes: 36 additions & 2 deletions src/main/java/com/binance/api/client/BinanceApiRestClient.java
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
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.WithdrawHistory;
import com.binance.api.client.domain.account.request.AllOrdersRequest;
import com.binance.api.client.domain.account.request.CancelOrderRequest;
Expand All @@ -17,8 +19,6 @@
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 @@ -166,6 +166,33 @@ public interface BinanceApiRestClient {
*/
Account getAccount();

/**
* Get trades for a specific account and symbol.
*
* @param symbol symbol to get trades from
* @param limit default 500; max 500
* @param fromId TradeId to fetch from. Default gets most recent trades.
* @return a list of trades
*/
List<Trade> getMyTrades(String symbol, Integer limit, Long fromId, Long recvWindow, Long timestamp);

/**
* Get trades for a specific account and symbol.
*
* @param symbol symbol to get trades from
* @param limit default 500; max 500
* @return a list of trades
*/
List<Trade> getMyTrades(String symbol, Integer limit);

/**
* Get trades for a specific account and symbol.
*
* @param symbol symbol to get trades from
* @return a list of trades
*/
List<Trade> getMyTrades(String symbol);

/**
* Submit a withdraw request.
*
Expand All @@ -192,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
Expand Up @@ -8,7 +8,7 @@ public class BinanceApiConstants {
/**
* REST API base URL.
*/
public static final String API_BASE_URL = "https://www.binance.com";
public static final String API_BASE_URL = "https://api.binance.com";

/**
* Streaming API base URL.
Expand Down
28 changes: 28 additions & 0 deletions src/main/java/com/binance/api/client/domain/account/Deposit.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,16 @@ public class Deposit {
*/
private String insertTime;

/**
* Transaction id
*/
private String txId;

/**
* (0:pending,1:success)
*/
private int status;

public String getAmount() {
return amount;
}
Expand All @@ -49,12 +59,30 @@ public void setInsertTime(String insertTime) {
this.insertTime = insertTime;
}

public String getTxId() {
return txId;
}

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

public int getStatus() {
return status;
}

public void setStatus(int status) {
this.status = status;
}

@Override
public String toString() {
return new ToStringBuilder(this, ToStringStyle.SHORT_PREFIX_STYLE)
.append("amount", amount)
.append("asset", asset)
.append("insertTime", insertTime)
.append("txId", txId)
.append("status", status)
.toString();
}
}
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 @@ -13,7 +13,7 @@
*/
public class DepositHistory {

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

private boolean success;
Expand Down
Loading

0 comments on commit f51ee15

Please sign in to comment.