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

Method watchMultiple

java/lib/src/main/java/io/github/ccxt/Exchange.java:1712–1756  ·  view source on GitHub ↗
(Object url, Object messageHashes2, Object message, Object subscribeHashes2, Object subscription)

Source from the content-addressed store, hash-verified

1710 // Note: a single subscribe message is sent for all symbols, matching JS/C# design.
1711 // Exchange-specific code is responsible for building the message with all symbols.
1712 @SuppressWarnings("unchecked")
1713 public CompletableFuture<Object> watchMultiple(Object url, Object messageHashes2, Object message, Object subscribeHashes2, Object subscription) {
1714 var client = this.client(url);
1715
1716 List<Object> messageHashes = (List<Object>) messageHashes2;
1717 io.github.ccxt.ws.Future[] futures = new io.github.ccxt.ws.Future[messageHashes.size()];
1718 for (int i = 0; i < messageHashes.size(); i++) {
1719 futures[i] = client.future(messageHashes.get(i).toString());
1720 }
1721 var raceFuture = io.github.ccxt.ws.Future.race(futures);
1722
1723 List<String> missingSubscriptions = new java.util.ArrayList<>();
1724 if (subscribeHashes2 instanceof List<?> subscribeHashes) {
1725 for (Object sh : subscribeHashes) {
1726 if (sh == null) continue;
1727 String subHash = sh.toString();
1728 if (client.subscriptionsMap().putIfAbsent(subHash, subscription != null ? subscription : true) == null) {
1729 missingSubscriptions.add(subHash);
1730 }
1731 }
1732 }
1733
1734 if (subscribeHashes2 == null || !missingSubscriptions.isEmpty()) {
1735 client.connect(0).thenAccept(connected -> {
1736 if (message != null) {
1737 try {
1738 client.send(message);
1739 } catch (Exception ex) {
1740 for (String subHash : missingSubscriptions) {
1741 client.subscriptionsMap().remove(subHash);
1742 }
1743 raceFuture.reject(ex);
1744 }
1745 }
1746 }).exceptionally(ex -> {
1747 for (String subHash : missingSubscriptions) {
1748 client.subscriptionsMap().remove(subHash);
1749 }
1750 raceFuture.reject(ex);
1751 return null;
1752 });
1753 }
1754
1755 return raceFuture.getFuture();
1756 }
1757
1758 public void handleMessage(Client client, Object message) {
1759 // Base implementation — overridden by pro exchange classes

Callers 15

watchTickersMethod · 0.45
unWatchTickersMethod · 0.45
watchMarkPricesMethod · 0.45
unWatchMarkPricesMethod · 0.45
watchBidsAsksMethod · 0.45
unWatchBidsAsksMethod · 0.45
watchTradesForSymbolsMethod · 0.45
watchOHLCVForSymbolsMethod · 0.45

Calls 13

clientMethod · 0.95
subscriptionsMapMethod · 0.80
isEmptyMethod · 0.80
getFutureMethod · 0.80
rejectMethod · 0.65
futureMethod · 0.45
toStringMethod · 0.45
getMethod · 0.45
raceMethod · 0.45
addMethod · 0.45
connectMethod · 0.45
sendMethod · 0.45

Tested by

no test coverage detected