(String[] args)
| 16 | public class AsyncExample { |
| 17 | |
| 18 | public static void main(String[] args) throws Exception { |
| 19 | Binance exchange = new Binance(); |
| 20 | |
| 21 | exchange.loadMarkets(false); |
| 22 | |
| 23 | String[] symbols = {"BTC/USDT", "ETH/USDT", "SOL/USDT", "XRP/USDT", "DOGE/USDT"}; |
| 24 | |
| 25 | System.out.println("Fetching " + symbols.length + " tickers concurrently..."); |
| 26 | long start = System.currentTimeMillis(); |
| 27 | |
| 28 | // Fire all requests concurrently |
| 29 | @SuppressWarnings("unchecked") |
| 30 | CompletableFuture<Ticker>[] futures = new CompletableFuture[symbols.length]; |
| 31 | for (int i = 0; i < symbols.length; i++) { |
| 32 | futures[i] = exchange.fetchTickerAsync(symbols[i], null); |
| 33 | } |
| 34 | |
| 35 | // Wait for all to complete |
| 36 | CompletableFuture.allOf(futures).get(30, TimeUnit.SECONDS); |
| 37 | |
| 38 | long elapsed = System.currentTimeMillis() - start; |
| 39 | |
| 40 | System.out.printf("%-12s %12s %10s%n", "Symbol", "Price", "Change%"); |
| 41 | System.out.println("-".repeat(36)); |
| 42 | |
| 43 | for (CompletableFuture<Ticker> f : futures) { |
| 44 | Ticker t = f.get(); |
| 45 | System.out.printf("%-12s %12.4f %9.2f%%%n", |
| 46 | t.symbol, |
| 47 | t.last != null ? t.last : 0, |
| 48 | t.percentage != null ? t.percentage : 0); |
| 49 | } |
| 50 | |
| 51 | System.out.println("\nAll fetched in " + elapsed + "ms"); |
| 52 | } |
| 53 | } |
nothing calls this directly
no test coverage detected