MCPcopy Index your code
hub / github.com/ccxt/ccxt / main

Method main

java/examples/src/main/java/examples/CompareExchanges.java:17–55  ·  view source on GitHub ↗
(String[] args)

Source from the content-addressed store, hash-verified

15public class CompareExchanges {
16
17 @SuppressWarnings("unchecked")
18 public static void main(String[] args) {
19 String symbol = args.length > 0 ? args[0] : "BTC/USDT";
20 String[] exchangeIds = {"binance", "bybit", "okx", "kraken", "bitget"};
21
22 System.out.println("Comparing " + symbol + " across exchanges\n");
23
24 System.out.printf("%-12s %12s %12s %12s %10s%n",
25 "Exchange", "Last", "Bid", "Ask", "Spread");
26 System.out.println("-".repeat(60));
27
28 for (String id : exchangeIds) {
29 try {
30 Exchange exchange = Exchange.dynamicallyCreateInstance(id, null);
31 exchange.loadMarkets(false).join();
32
33 // Untyped: fetchTicker returns CompletableFuture<Object>
34 Map<String, Object> ticker = (Map<String, Object>) exchange.fetchTicker(symbol).join();
35
36 Double last = toDouble(ticker.get("last"));
37 Double bid = toDouble(ticker.get("bid"));
38 Double ask = toDouble(ticker.get("ask"));
39
40 double spread = 0;
41 if (ask != null && bid != null) {
42 spread = ask - bid;
43 }
44
45 System.out.printf("%-12s %12.2f %12.2f %12.2f %10.2f%n",
46 id,
47 safe(last),
48 safe(bid),
49 safe(ask),
50 spread);
51 } catch (Exception e) {
52 System.out.printf("%-12s %s%n", id, "ERROR: " + rootMessage(e));
53 }
54 }
55 }
56
57 static Double toDouble(Object v) {
58 if (v instanceof Number n) return n.doubleValue();

Callers

nothing calls this directly

Calls 8

loadMarketsMethod · 0.95
fetchTickerMethod · 0.95
toDoubleMethod · 0.95
safeMethod · 0.95
rootMessageMethod · 0.95
repeatMethod · 0.80
getMethod · 0.45

Tested by

no test coverage detected