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

Method loadOrderBook

java/lib/src/main/java/io/github/ccxt/Exchange.java:1882–1917  ·  view source on GitHub ↗

Load order book snapshot from REST and merge with cached deltas. Matches TS base Exchange.loadOrderBook().

(Client client, Object messageHash, Object symbol, Object limit, Object params)

Source from the content-addressed store, hash-verified

1880 * Matches TS base Exchange.loadOrderBook().
1881 */
1882 @SuppressWarnings("unchecked")
1883 public void loadOrderBook(Client client, Object messageHash, Object symbol, Object limit, Object params) {
1884 try {
1885 if (!Helpers.inOp(this.orderbooks, symbol)) {
1886 client.reject(new ExchangeError(this.id + " loadOrderBook() orderbook is not initiated"), messageHash);
1887 return;
1888 }
1889 int maxRetries = ((Number) this.handleOption("watchOrderBook", "snapshotMaxRetries", 3)).intValue();
1890 int tries = 0;
1891 try {
1892 Object stored = Helpers.GetValue(this.orderbooks, symbol);
1893 while (tries < maxRetries) {
1894 java.util.List<Object> cache = (java.util.List<Object>) Helpers.GetValue(stored, "cache");
1895 Object orderBook = this.fetchRestOrderBookSafe(symbol, limit, params != null ? params : new java.util.HashMap<String, Object>()).join();
1896 Object index = this.getCacheIndex(orderBook, cache);
1897 if (Helpers.isGreaterThanOrEqual(index, 0)) {
1898 Helpers.callDynamically(stored, "reset", new Object[]{orderBook});
1899 int idx = ((Number) index).intValue();
1900 this.handleDeltas(stored, cache.subList(idx, cache.size()));
1901 ((java.util.List<Object>) Helpers.GetValue(stored, "cache")).clear();
1902 client.resolve(stored, messageHash);
1903 return;
1904 }
1905 tries++;
1906 }
1907 client.reject(new ExchangeError(this.id + " nonce is behind the cache after " + maxRetries + " tries."), messageHash);
1908 ((java.util.concurrent.ConcurrentHashMap<String, Client>) this.clients).remove(client.url);
1909 Helpers.addElementToObject(this.orderbooks, symbol, this.orderBook());
1910 } catch (Exception e) {
1911 client.reject(e, messageHash);
1912 this.loadOrderBook(client, messageHash, symbol, limit, params);
1913 }
1914 } catch (Exception e) {
1915 client.reject(e, messageHash);
1916 }
1917 }
1918
1919 /** Overload for 3-arg calls (without limit and params). */
1920 public void loadOrderBook(Client client, Object messageHash, Object symbol) {

Callers 7

handleOrderBookMethod · 0.45
handleOrderBookMethod · 0.45
handleOrderBookMethod · 0.45
handleOrderBookMethod · 0.45
handleUtaOrderBookMethod · 0.45
handleOrderBookMethod · 0.45
handleOrderBookMethod · 0.45

Calls 14

inOpMethod · 0.95
handleOptionMethod · 0.95
GetValueMethod · 0.95
getCacheIndexMethod · 0.95
isGreaterThanOrEqualMethod · 0.95
callDynamicallyMethod · 0.95
handleDeltasMethod · 0.95
addElementToObjectMethod · 0.95
orderBookMethod · 0.95
rejectMethod · 0.65
resolveMethod · 0.65

Tested by

no test coverage detected