@Override protected void handleMessage(JsonNode message) { super.handleMessage(message); }
@Override public Observable<JsonNode> subscribeChannel(String channelName, Object... args) { if (!channels.containsKey(channelName)) { Observable<JsonNode> subscription = super.subscribeChannel(channelName, args); subscriptions.put(channelName, subscription); } return subscriptions.get(channelName); }
@Override public Completable disconnect() { return super.disconnect(); }
@Override protected void handleMessage(JsonNode message) { if (message.get("event") != null && "pong".equals(message.get("event").asText()) ) { // ignore pong message return; } if (message.get("data") != null) { if (message.get("data").has("result")) { boolean success = message.get("data").get("result").asBoolean(); if (!success) { super.handleError(message, new ExchangeException("Error code: " + message.get("data").get("error_code").asText())); } return; } } super.handleMessage(message); }
@Override public Completable connect() { Completable conn = super.connect(); return conn.andThen((CompletableSource)(completable) -> { try { if (pingPongSubscription != null && !pingPongSubscription.isDisposed()) { pingPongSubscription.dispose(); } pingPongSubscription = pingPongSrc.subscribe(o -> { this.sendMessage("{\"event\":\"ping\"}"); }); completable.onComplete(); } catch (Exception e) { completable.onError(e); } }); }
@Override protected void handleMessage(JsonNode message) { if (message.has(JSON_ID)) { int requestId = message.get(JSON_ID).asInt(); if (requests.containsKey(requestId)) { String subscriptionMethod = requests.get(requestId).getLeft(); if (message.has(JSON_ERROR)) { try { HitbtcException exception = objectMapper.treeToValue(message, HitbtcException.class); super.handleError(message, exception); } catch (JsonProcessingException e) { super.handleError(message, e); } } else { boolean result = message.get(JSON_RESULT).asBoolean(); LOG.info("HitBTC returned {} as result of '{}' method", result, subscriptionMethod); } requests.remove(requestId); return; } else { LOG.error("Unknown request ID {}", requestId); } } String channel = getChannel(message); if (!channels.containsKey(channel)) { LOG.warn("The message has been received from disconnected channel '{}'. Skipped.", channel); return; } super.handleMessage(message); }
@Override protected void handleMessage(JsonNode message) { super.handleMessage(message); }
return; super.handleError(message, new ExchangeException("Error code: " + message.get(ERROR_CODE).asText())); break; throw new RuntimeException("Failed to get channel name from message", e); super.handleMessage(message);
/** * Subscribes to the provided channel name, maintains a cache of subscriptions, in order not to * subscribe more than once to the same channel. * * @param channelName the name of the requested channel. * @return an Observable of json objects coming from the exchange. */ @Override public Observable<JsonNode> subscribeChannel(String channelName, Object... args) { channelName = SHARE_CHANNEL_NAME; if (!channels.containsKey(channelName) && !subscriptions.containsKey(channelName)) { subscriptions.put(channelName, super.subscribeChannel(channelName, args)); } return subscriptions.get(channelName); }
@Override protected void handleMessage(JsonNode message) { super.handleMessage(message); }
public Observable<JsonNode> subscribeChannel(BinanceWebSocketTypes eventType) { return super.subscribeChannel(eventType.getSerializedValue()); }
@Override protected void handleMessage(JsonNode message) { if (message.has("info") || message.has("success")) { return; } if (message.has("error")) { String error = message.get("error").asText(); LOG.error("Error with message: " + error); return; } super.handleMessage(message); }
@Override public void messageHandler(String message) { LOG.debug("Received message: {}", message); JsonNode jsonNode; // Parse incoming message to JSON try { jsonNode = objectMapper.readTree(message); } catch (IOException e) { LOG.error("Error parsing incoming message to JSON: {}", message); return; } // In case of array - handle every message separately. if (jsonNode.getNodeType().equals(JsonNodeType.ARRAY)) { for (JsonNode node : jsonNode) { handleMessage(node); } } else { handleMessage(jsonNode); } }
@Override protected void handleMessage(JsonNode message) { if (message.isArray()) { Integer channelId = new Integer(message.get(0).toString()); if (channelId > 0 && channelId < 1000) { JsonNode events = message.get(2); if (events.isArray()) { JsonNode event = events.get(0); if (event.get(0).toString().equals("\"i\"")) { if (event.get(1).has("orderBook")) { String currencyPair = event.get(1).get("currencyPair").asText(); LOG.info("Register {} as {}", String.valueOf(channelId), currencyPair); subscribedChannels.put(String.valueOf(channelId), currencyPair); } } } } } if (message.has("error")) { LOG.error("Error with message: " + message.get("error").asText()); return; } super.handleMessage(message); }