Skip to content

Commit

Permalink
Resolves binance-exchange#5 - Support /exchangeInfo endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
joaopsilva committed Dec 23, 2017
1 parent af6ab53 commit 824b2e4
Show file tree
Hide file tree
Showing 18 changed files with 692 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import com.binance.api.client.domain.account.request.OrderRequest;
import com.binance.api.client.domain.account.request.OrderStatusRequest;
import com.binance.api.client.domain.event.ListenKey;
import com.binance.api.client.domain.general.ExchangeInfo;
import com.binance.api.client.domain.general.ServerTime;
import com.binance.api.client.domain.market.AggTrade;
import com.binance.api.client.domain.market.BookTicker;
Expand Down Expand Up @@ -41,6 +42,11 @@ public interface BinanceApiAsyncRestClient {
*/
void getServerTime(BinanceApiCallback<ServerTime> callback);

/**
* Current exchange trading rules and symbol information
*/
void getExchangeInfo(BinanceApiCallback<ExchangeInfo> callback);

// Market Data endpoints

/**
Expand Down
11 changes: 10 additions & 1 deletion src/main/java/com/binance/api/client/BinanceApiRestClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,15 @@
import com.binance.api.client.domain.account.request.CancelOrderRequest;
import com.binance.api.client.domain.account.request.OrderRequest;
import com.binance.api.client.domain.account.request.OrderStatusRequest;
import com.binance.api.client.domain.general.ExchangeInfo;
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 retrofit2.Call;

import java.util.List;

Expand All @@ -35,10 +37,17 @@ public interface BinanceApiRestClient {
void ping();

/**
* Check server time.
* Test connectivity to the Rest API and get the current server time.
*
* @return current server time.
*/
Long getServerTime();

/**
* @return Current exchange trading rules and symbol information
*/
ExchangeInfo getExchangeInfo();

// Market Data endpoints

/**
Expand Down
7 changes: 6 additions & 1 deletion src/main/java/com/binance/api/client/domain/OrderType.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,10 @@
*/
public enum OrderType {
LIMIT,
MARKET
MARKET,
STOP_LOSS,
STOP_LOSS_LIMIT,
TAKE_PROFIT,
TAKE_PROFIT_LIMIT,
LIMIT_MAKER
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package com.binance.api.client.domain.general;

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

/**
* Exchange Filters define trading rules an exchange.
*
* The MAX_NUM_ORDERS filter defines the maximum number of orders an account is allowed to have open on the exchange. Note that both "algo" orders and normal orders are counted for this filter.
*
* The MAX_ALGO_ORDERS filter defines the maximum number of "algo" orders an account is allowed to have open on the exchange. "Algo" orders are STOP_LOSS, STOP_LOSS_LIMIT, TAKE_PROFIT, and TAKE_PROFIT_LIMIT orders.
*/
public class ExchangeFilter {

private FilterType filterType;

private Integer limit;

public FilterType getFilterType() {
return filterType;
}

public void setFilterType(FilterType filterType) {
this.filterType = filterType;
}

public Integer getLimit() {
return limit;
}

public void setLimit(Integer limit) {
this.limit = limit;
}

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

import com.binance.api.client.exception.BinanceApiException;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import org.apache.commons.lang3.builder.ToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle;

import java.util.List;

/**
* Current exchange trading rules and symbol information.
* https://github.com/binance-exchange/binance-official-api-docs/blob/master/rest-api.md
*/
@JsonIgnoreProperties(ignoreUnknown = true)
public class ExchangeInfo {

private String timezone;

private Long serverTime;

private List<RateLimit> rateLimits;

// private List<String> exchangeFilters;

private List<SymbolInfo> symbols;

public String getTimezone() {
return timezone;
}

public void setTimezone(String timezone) {
this.timezone = timezone;
}

public Long getServerTime() {
return serverTime;
}

public void setServerTime(Long serverTime) {
this.serverTime = serverTime;
}

public List<RateLimit> getRateLimits() {
return rateLimits;
}

public void setRateLimits(List<RateLimit> rateLimits) {
this.rateLimits = rateLimits;
}

public List<SymbolInfo> getSymbols() {
return symbols;
}

public void setSymbols(List<SymbolInfo> symbols) {
this.symbols = symbols;
}

/**
* @param symbol the symbol to obtain information for (e.g. ETHBTC)
* @return symbol exchange information
*/
public SymbolInfo getSymbolInfo(String symbol) {
return symbols.stream().filter(symbolInfo -> symbolInfo.getSymbol().equals(symbol))
.findFirst()
.orElseThrow(() -> new BinanceApiException("Unable to obtain information for symbol " + symbol));
}

@Override
public String toString() {
return new ToStringBuilder(this, ToStringStyle.SHORT_PREFIX_STYLE)
.append("timezone", timezone)
.append("serverTime", serverTime)
.append("rateLimits", rateLimits)
.append("symbols", symbols)
.toString();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package com.binance.api.client.domain.general;

/**
* Filters define trading rules on a symbol or an exchange. Filters come in two forms: symbol filters and exchange filters.
*/
public enum FilterType {
// Symbol
PRICE_FILTER,
LOT_SIZE,
MIN_NOTIONAL,
MAX_NUM_ORDERS,
MAX_ALGO_ORDERS,

// Exchange
EXCHANGE_MAX_NUM_ORDERS,
EXCHANGE_MAX_ALGO_ORDERS
}
49 changes: 49 additions & 0 deletions src/main/java/com/binance/api/client/domain/general/RateLimit.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
package com.binance.api.client.domain.general;

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

/**
* Rate limits.
*/
public class RateLimit {

private RateLimitType rateLimitType;

private RateLimitInterval interval;

private Integer limit;

public RateLimitType getRateLimitType() {
return rateLimitType;
}

public void setRateLimitType(RateLimitType rateLimitType) {
this.rateLimitType = rateLimitType;
}

public RateLimitInterval getInterval() {
return interval;
}

public void setInterval(RateLimitInterval interval) {
this.interval = interval;
}

public Integer getLimit() {
return limit;
}

public void setLimit(Integer limit) {
this.limit = limit;
}

@Override
public String toString() {
return new ToStringBuilder(this, ToStringStyle.SHORT_PREFIX_STYLE)
.append("rateLimitType", rateLimitType)
.append("interval", interval)
.append("limit", limit)
.toString();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package com.binance.api.client.domain.general;

/**
* Rate limit intervals.
*/
public enum RateLimitInterval {
SECOND,
MINUTE,
DAY
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package com.binance.api.client.domain.general;

/**
* Rate limiters.
*/
public enum RateLimitType {
REQUESTS,
ORDERS
}
Loading

0 comments on commit 824b2e4

Please sign in to comment.