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

Method main

java/examples/src/main/java/examples/WatchOrderBook.java:18–58  ·  view source on GitHub ↗
(String[] args)

Source from the content-addressed store, hash-verified

16public class WatchOrderBook {
17
18 public static void main(String[] args) throws Exception {
19 String symbol = args.length > 0 ? args[0] : "BTC/USDT";
20
21 Binance exchange = new Binance();
22 exchange.verbose = false;
23
24 System.out.println("Loading markets...");
25 exchange.loadMarkets(false);
26 System.out.println("Watching " + symbol + " order book (10 updates)...\n");
27
28 for (int i = 0; i < 10; i++) {
29 OrderBook ob = exchange.watchOrderBook(symbol);
30
31 List<List<Double>> bids = ob.bids;
32 List<List<Double>> asks = ob.asks;
33
34 System.out.println("=== Update #" + (i + 1) + " (ts=" + ob.timestamp + ") ===");
35 System.out.printf("%-20s | %-20s%n", "BIDS (price x size)", "ASKS (price x size)");
36 System.out.println("-".repeat(43));
37
38 int rows = Math.min(5, Math.min(bids.size(), asks.size()));
39 for (int j = 0; j < rows; j++) {
40 List<Double> bid = bids.get(j);
41 List<Double> ask = asks.get(j);
42 System.out.printf("%10s x %-8s | %10s x %-8s%n",
43 bid.get(0), bid.get(1),
44 ask.get(0), ask.get(1));
45 }
46
47 if (!bids.isEmpty() && !asks.isEmpty()) {
48 double bestBid = bids.get(0).get(0);
49 double bestAsk = asks.get(0).get(0);
50 double spread = bestAsk - bestBid;
51 System.out.printf("Spread: %.2f | Total bids: %d | Total asks: %d%n%n",
52 spread, bids.size(), asks.size());
53 }
54 }
55
56 System.out.println("Done!");
57 System.exit(0);
58 }
59}

Callers

nothing calls this directly

Calls 6

loadMarketsMethod · 0.95
watchOrderBookMethod · 0.95
repeatMethod · 0.80
isEmptyMethod · 0.80
minMethod · 0.45
getMethod · 0.45

Tested by

no test coverage detected