Skip to main content
Version: 1.x

Market

 Maven Central Sonatype Nexus  License: MIT

Description

Binance4j-market is a Java connector for the market endpoints of the Binance REST API.

Installation

pom.xml
<dependency>
<groupId>{{groupId}}</groupId>
<artifactId>{{artifactId}}</artifactId>
<version>{{version}}</version>
</dependency>

Dependencies

Test connectivity

   
MarketDataClient client = new MarketDataClient(key, secret);

try{
client.ping().execute();
}catch(ApiException e){
//...
}

Get server time

    
MarketDataClient client = new MarketDataClient(key, secret);

try{
ServerTimeResponse response = client.getServerTime().execute();
}catch(ApiException e){
//...
}

Get exchange info

     
MarketDataClient client = new MarketDataClient(key, secret);

try{
ExchangeInfo response = client.getExchangeInfo().execute();
}catch(ApiException e){
//...
}

Get a symbol's order book

     

The term order book refers to an electronic list of buy and sell orders for a specific security or financial instrument organized by price level. An order book lists the number of shares being bid on or offered at each price point, or market depth. It also identifies the market participants behind the buy and sell orders, though some choose to remain anonymous. These lists help traders and also improve market transparency because they provide valuable trading information.

Investopedia

MarketDataClient client = new MarketDataClient(key, secret);

OrderBookRequest request = new OrderBookRequest("BNBBTC");

try{
OrderBook response = client.getOrderBook(request).execute();
}catch(ApiException e){
//...
}
note

The limit will determine the request weight

danger

The integer value must match one of the OrderBookLimit values or the request will fail

Get recent trades

     
MarketDataClient client = new MarketDataClient(key, secret);

TradesRequest request = new TradesRequest("BNBBTC");

try{
List<TradeHistoryItem> response = client.getTrades(request).execute();
}catch(ApiException e){
//...
}

Get historical trades

     
MarketDataClient client = new MarketDataClient(key, secret);

HistoricalTradesRequest request = new HistoricalTradesRequest("BNBBTC");

try{
List<TradeHistoryItem> response = client.getHistoricalTrades(request).execute();
}catch(ApiException e){
//...
}

Get compressed/aggregate trades List

     
MarketDataClient client = new MarketDataClient(key, secret);

AggTradeRequest request = new AggTradeRequest("BNBBTC");

try{
List<AggTrade> response = client.getAggTrades(request).execute();
}catch(ApiException e){
//...
}

Get Klines / candles

     
MarketDataClient client = new MarketDataClient(key, secret);

KlinesRequest request = new KlinesRequest("BNBBTC", CandlestickInterval.FIVE_MINUTES);

try{
List<CandlestickBar> response = client.getKlines(request).execute();
}catch(ApiException e){
//...
}
note

Default limit is 500, max is 1000.

caution

The String interval must correspond to one of the CandlestickInterval else the request will throw an ApiException

Get average price

     
MarketDataClient client = new MarketDataClient(key, secret);

AveragePriceRequest request = new AveragePriceRequest("BNBBTC");

try{
AveragePrice response = client.getAveragePrice(request).execute();
}catch(ApiException e){
//...
}

Get 24h ticker statistics

     
MarketDataClient client = new MarketDataClient(key, secret);

TickerStatisticsRequest request = new TickerStatisticsRequest("BNBBTC");

try{
TickerStatistics response = client.get24hTickerStatistics(request).execute();
}catch(ApiException e){
//...
}
note

Note the difference between TickerStatisticsRequest and TickersStatisticsRequest. The first is for one or all symbols, the other is for specific symbols.

Get price ticker

     
MarketDataClient client = new MarketDataClient(key, secret);

PriceTickerRequest request = new PriceTickerRequest("BNBBTC");

try{
PriceTicker response = client.getTicker(request).execute();
}catch(ApiException e){
//...
}
note

Note the difference between PriceTickerRequest and PriceTickersRequest. The first is for one or all symbols, the other is for specific symbols.

Get order book ticker

     
MarketDataClient client = new MarketDataClient(key, secret);

BookTickerRequest request = new BookTickerRequest("BNBBTC");

try{
BookTicker response = client.getBookTicker(request).execute();
}catch(ApiException e){
//...
}
note

Note the difference between BookTickerRequest and BookTickersRequest. The first is for one or all symbols, the other is for specific symbols.