(String[] args)
| 22 | public class ImplicitApi { |
| 23 | |
| 24 | @SuppressWarnings("unchecked") |
| 25 | public static void main(String[] args) throws Exception { |
| 26 | |
| 27 | // Create a concrete exchange class to access exchange-specific methods |
| 28 | Binance exchange = new Binance(); |
| 29 | |
| 30 | exchange.loadMarkets(false); |
| 31 | |
| 32 | String symbol = "BTC/USDT"; |
| 33 | |
| 34 | // ========================================== |
| 35 | // 1. Unified API — typed methods on Binance |
| 36 | // ========================================== |
| 37 | System.out.println("=== Unified Typed API ===\n"); |
| 38 | |
| 39 | // fetchTicker returns Ticker directly |
| 40 | Ticker ticker = exchange.fetchTicker(symbol); |
| 41 | System.out.println("Ticker: " + ticker.symbol + " last=" + ticker.last |
| 42 | + " bid=" + ticker.bid + " ask=" + ticker.ask); |
| 43 | |
| 44 | // fetchTrades returns List<Trade> directly |
| 45 | List<Trade> trades = exchange.fetchTrades(symbol, null, 3L, null); |
| 46 | System.out.println("\nRecent trades:"); |
| 47 | for (Trade t : trades) { |
| 48 | System.out.printf(" %s %-4s price=%-12.2f amount=%.6f%n", |
| 49 | t.datetime, t.side, t.price, t.amount); |
| 50 | } |
| 51 | |
| 52 | // fetchOrderBook returns OrderBook directly |
| 53 | OrderBook ob = exchange.fetchOrderBook(symbol, 5L, null); |
| 54 | System.out.println("\nOrder book (top 5):"); |
| 55 | System.out.println(" Bids:"); |
| 56 | for (List<Double> bid : ob.bids) { |
| 57 | System.out.printf(" %.2f x %.6f%n", bid.get(0), bid.get(1)); |
| 58 | } |
| 59 | System.out.println(" Asks:"); |
| 60 | for (List<Double> ask : ob.asks) { |
| 61 | System.out.printf(" %.2f x %.6f%n", ask.get(0), ask.get(1)); |
| 62 | } |
| 63 | |
| 64 | // ========================================== |
| 65 | // 2. Implicit API — exchange-specific endpoints |
| 66 | // ========================================== |
| 67 | System.out.println("\n=== Implicit (Exchange-Specific) API ===\n"); |
| 68 | |
| 69 | // Binance publicGetTicker24hr — returns raw exchange response as Object |
| 70 | Map<String, Object> params = new HashMap<>(); |
| 71 | params.put("symbol", "BTCUSDT"); // Binance uses native symbol format |
| 72 | Object rawTicker = exchange.publicGetTicker24hr(params).join(); |
| 73 | Map<String, Object> tickerMap = (Map<String, Object>) rawTicker; |
| 74 | System.out.println("publicGetTicker24hr (raw Binance response):"); |
| 75 | System.out.println(" symbol: " + tickerMap.get("symbol")); |
| 76 | System.out.println(" lastPrice: " + tickerMap.get("lastPrice")); |
| 77 | System.out.println(" volume: " + tickerMap.get("volume")); |
| 78 | System.out.println(" priceChange: " + tickerMap.get("priceChange")); |
| 79 | |
| 80 | // Binance publicGetDepth — raw order book |
| 81 | params.clear(); |
nothing calls this directly
no test coverage detected