Skip to content

Commit 824b2e4

Browse files
committed
Resolves binance-exchange#5 - Support /exchangeInfo endpoint
1 parent af6ab53 commit 824b2e4

18 files changed

+692
-4
lines changed

src/main/java/com/binance/api/client/BinanceApiAsyncRestClient.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
import com.binance.api.client.domain.account.request.OrderRequest;
1414
import com.binance.api.client.domain.account.request.OrderStatusRequest;
1515
import com.binance.api.client.domain.event.ListenKey;
16+
import com.binance.api.client.domain.general.ExchangeInfo;
1617
import com.binance.api.client.domain.general.ServerTime;
1718
import com.binance.api.client.domain.market.AggTrade;
1819
import com.binance.api.client.domain.market.BookTicker;
@@ -41,6 +42,11 @@ public interface BinanceApiAsyncRestClient {
4142
*/
4243
void getServerTime(BinanceApiCallback<ServerTime> callback);
4344

45+
/**
46+
* Current exchange trading rules and symbol information
47+
*/
48+
void getExchangeInfo(BinanceApiCallback<ExchangeInfo> callback);
49+
4450
// Market Data endpoints
4551

4652
/**

src/main/java/com/binance/api/client/BinanceApiRestClient.java

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,15 @@
1212
import com.binance.api.client.domain.account.request.CancelOrderRequest;
1313
import com.binance.api.client.domain.account.request.OrderRequest;
1414
import com.binance.api.client.domain.account.request.OrderStatusRequest;
15+
import com.binance.api.client.domain.general.ExchangeInfo;
1516
import com.binance.api.client.domain.market.AggTrade;
1617
import com.binance.api.client.domain.market.BookTicker;
1718
import com.binance.api.client.domain.market.Candlestick;
1819
import com.binance.api.client.domain.market.CandlestickInterval;
1920
import com.binance.api.client.domain.market.OrderBook;
2021
import com.binance.api.client.domain.market.TickerPrice;
2122
import com.binance.api.client.domain.market.TickerStatistics;
23+
import retrofit2.Call;
2224

2325
import java.util.List;
2426

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

3739
/**
38-
* Check server time.
40+
* Test connectivity to the Rest API and get the current server time.
41+
*
42+
* @return current server time.
3943
*/
4044
Long getServerTime();
4145

46+
/**
47+
* @return Current exchange trading rules and symbol information
48+
*/
49+
ExchangeInfo getExchangeInfo();
50+
4251
// Market Data endpoints
4352

4453
/**

src/main/java/com/binance/api/client/domain/OrderType.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,10 @@
55
*/
66
public enum OrderType {
77
LIMIT,
8-
MARKET
8+
MARKET,
9+
STOP_LOSS,
10+
STOP_LOSS_LIMIT,
11+
TAKE_PROFIT,
12+
TAKE_PROFIT_LIMIT,
13+
LIMIT_MAKER
914
}
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
package com.binance.api.client.domain.general;
2+
3+
import org.apache.commons.lang3.builder.ToStringBuilder;
4+
import org.apache.commons.lang3.builder.ToStringStyle;
5+
6+
/**
7+
* Exchange Filters define trading rules an exchange.
8+
*
9+
* 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.
10+
*
11+
* 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.
12+
*/
13+
public class ExchangeFilter {
14+
15+
private FilterType filterType;
16+
17+
private Integer limit;
18+
19+
public FilterType getFilterType() {
20+
return filterType;
21+
}
22+
23+
public void setFilterType(FilterType filterType) {
24+
this.filterType = filterType;
25+
}
26+
27+
public Integer getLimit() {
28+
return limit;
29+
}
30+
31+
public void setLimit(Integer limit) {
32+
this.limit = limit;
33+
}
34+
35+
@Override
36+
public String toString() {
37+
return new ToStringBuilder(this, ToStringStyle.SHORT_PREFIX_STYLE)
38+
.append("filterType", filterType)
39+
.append("limit", limit)
40+
.toString();
41+
}
42+
}
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
package com.binance.api.client.domain.general;
2+
3+
import com.binance.api.client.exception.BinanceApiException;
4+
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
5+
import org.apache.commons.lang3.builder.ToStringBuilder;
6+
import org.apache.commons.lang3.builder.ToStringStyle;
7+
8+
import java.util.List;
9+
10+
/**
11+
* Current exchange trading rules and symbol information.
12+
* https://github.com/binance-exchange/binance-official-api-docs/blob/master/rest-api.md
13+
*/
14+
@JsonIgnoreProperties(ignoreUnknown = true)
15+
public class ExchangeInfo {
16+
17+
private String timezone;
18+
19+
private Long serverTime;
20+
21+
private List<RateLimit> rateLimits;
22+
23+
// private List<String> exchangeFilters;
24+
25+
private List<SymbolInfo> symbols;
26+
27+
public String getTimezone() {
28+
return timezone;
29+
}
30+
31+
public void setTimezone(String timezone) {
32+
this.timezone = timezone;
33+
}
34+
35+
public Long getServerTime() {
36+
return serverTime;
37+
}
38+
39+
public void setServerTime(Long serverTime) {
40+
this.serverTime = serverTime;
41+
}
42+
43+
public List<RateLimit> getRateLimits() {
44+
return rateLimits;
45+
}
46+
47+
public void setRateLimits(List<RateLimit> rateLimits) {
48+
this.rateLimits = rateLimits;
49+
}
50+
51+
public List<SymbolInfo> getSymbols() {
52+
return symbols;
53+
}
54+
55+
public void setSymbols(List<SymbolInfo> symbols) {
56+
this.symbols = symbols;
57+
}
58+
59+
/**
60+
* @param symbol the symbol to obtain information for (e.g. ETHBTC)
61+
* @return symbol exchange information
62+
*/
63+
public SymbolInfo getSymbolInfo(String symbol) {
64+
return symbols.stream().filter(symbolInfo -> symbolInfo.getSymbol().equals(symbol))
65+
.findFirst()
66+
.orElseThrow(() -> new BinanceApiException("Unable to obtain information for symbol " + symbol));
67+
}
68+
69+
@Override
70+
public String toString() {
71+
return new ToStringBuilder(this, ToStringStyle.SHORT_PREFIX_STYLE)
72+
.append("timezone", timezone)
73+
.append("serverTime", serverTime)
74+
.append("rateLimits", rateLimits)
75+
.append("symbols", symbols)
76+
.toString();
77+
}
78+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
package com.binance.api.client.domain.general;
2+
3+
/**
4+
* Filters define trading rules on a symbol or an exchange. Filters come in two forms: symbol filters and exchange filters.
5+
*/
6+
public enum FilterType {
7+
// Symbol
8+
PRICE_FILTER,
9+
LOT_SIZE,
10+
MIN_NOTIONAL,
11+
MAX_NUM_ORDERS,
12+
MAX_ALGO_ORDERS,
13+
14+
// Exchange
15+
EXCHANGE_MAX_NUM_ORDERS,
16+
EXCHANGE_MAX_ALGO_ORDERS
17+
}
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
package com.binance.api.client.domain.general;
2+
3+
import org.apache.commons.lang3.builder.ToStringBuilder;
4+
import org.apache.commons.lang3.builder.ToStringStyle;
5+
6+
/**
7+
* Rate limits.
8+
*/
9+
public class RateLimit {
10+
11+
private RateLimitType rateLimitType;
12+
13+
private RateLimitInterval interval;
14+
15+
private Integer limit;
16+
17+
public RateLimitType getRateLimitType() {
18+
return rateLimitType;
19+
}
20+
21+
public void setRateLimitType(RateLimitType rateLimitType) {
22+
this.rateLimitType = rateLimitType;
23+
}
24+
25+
public RateLimitInterval getInterval() {
26+
return interval;
27+
}
28+
29+
public void setInterval(RateLimitInterval interval) {
30+
this.interval = interval;
31+
}
32+
33+
public Integer getLimit() {
34+
return limit;
35+
}
36+
37+
public void setLimit(Integer limit) {
38+
this.limit = limit;
39+
}
40+
41+
@Override
42+
public String toString() {
43+
return new ToStringBuilder(this, ToStringStyle.SHORT_PREFIX_STYLE)
44+
.append("rateLimitType", rateLimitType)
45+
.append("interval", interval)
46+
.append("limit", limit)
47+
.toString();
48+
}
49+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
package com.binance.api.client.domain.general;
2+
3+
/**
4+
* Rate limit intervals.
5+
*/
6+
public enum RateLimitInterval {
7+
SECOND,
8+
MINUTE,
9+
DAY
10+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
package com.binance.api.client.domain.general;
2+
3+
/**
4+
* Rate limiters.
5+
*/
6+
public enum RateLimitType {
7+
REQUESTS,
8+
ORDERS
9+
}

0 commit comments

Comments
 (0)