forked from binance-exchange/binance-java-api
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathMarketDataEndpointsExampleAsync.java
More file actions
executable file
·46 lines (36 loc) · 1.77 KB
/
MarketDataEndpointsExampleAsync.java
File metadata and controls
executable file
·46 lines (36 loc) · 1.77 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
package com.binance.api.examples;
import com.binance.api.client.api.async.BinanceApiSpotAsyncRestClient;
import com.binance.api.client.domain.market.CandlestickInterval;
import com.binance.api.client.domain.market.OrderBook;
import com.binance.api.client.exception.BinanceApiException;
import com.binance.api.client.factory.BinanceSpotApiClientFactory;
/**
* Examples on how to get market data information such as the latest price of a symbol, etc., in an async way.
*/
public class MarketDataEndpointsExampleAsync {
public static void main(String[] args) {
BinanceSpotApiClientFactory factory = BinanceSpotApiClientFactory.newInstance();
BinanceApiSpotAsyncRestClient client = factory.newAsyncRestClient();
// Getting depth of a symbol (async)
client.getOrderBook("NEOETH", 10, (OrderBook response) -> {
System.out.println(response.getBids());
});
// Getting latest price of a symbol (async)
client.get24HrPriceStatistics("NEOETH", System.out::println);
// Getting all latest prices (async)
client.getAllPrices(System.out::println);
// Getting agg trades (async)
client.getAggTrades("NEOETH", System.out::println);
// Weekly candlestick bars for a symbol
client.getCandlestickBars("NEOETH", CandlestickInterval.WEEKLY, System.out::println);
// Book tickers (async)
client.getBookTickers(System.out::println);
// Exception handling
try {
client.getOrderBook("UNKNOWN", 10, System.out::println);
} catch (BinanceApiException e) {
System.out.println(e.getError().getCode()); // -1121
System.out.println(e.getError().getMsg()); // Invalid symbol
}
}
}