From 576bb4e8d926a4e0d028ec986985a1e832293856 Mon Sep 17 00:00:00 2001 From: Raphael Vullriede Date: Mon, 18 Nov 2024 12:55:29 +0100 Subject: [PATCH 1/2] fix: reduce log level for conection reset --- .../service/marketdata/CandleStickTest.java | 41 +++++++++++++++++++ .../service/netty/WebSocketClientHandler.java | 25 +++++++---- 2 files changed, 59 insertions(+), 7 deletions(-) create mode 100644 xchange-poloniex/src/test/java/org/knowm/xchange/poloniex/service/marketdata/CandleStickTest.java diff --git a/xchange-poloniex/src/test/java/org/knowm/xchange/poloniex/service/marketdata/CandleStickTest.java b/xchange-poloniex/src/test/java/org/knowm/xchange/poloniex/service/marketdata/CandleStickTest.java new file mode 100644 index 00000000000..8bb742284ad --- /dev/null +++ b/xchange-poloniex/src/test/java/org/knowm/xchange/poloniex/service/marketdata/CandleStickTest.java @@ -0,0 +1,41 @@ +package org.knowm.xchange.poloniex.service.marketdata; + +import static org.assertj.core.api.Assertions.assertThat; + +import java.time.Instant; +import java.time.temporal.ChronoUnit; +import java.util.Date; +import org.junit.Test; +import org.knowm.xchange.Exchange; +import org.knowm.xchange.ExchangeFactory; +import org.knowm.xchange.currency.CurrencyPair; +import org.knowm.xchange.dto.marketdata.CandleStickData; +import org.knowm.xchange.dto.marketdata.Ticker; +import org.knowm.xchange.instrument.Instrument; +import org.knowm.xchange.poloniex.PoloniexExchange; +import org.knowm.xchange.service.marketdata.MarketDataService; +import org.knowm.xchange.service.trade.params.DefaultCandleStickParam; + +/** + * @author timmolter + */ +public class CandleStickTest { + + @Test + public void tickerFetchTest() throws Exception { + + Exchange exchange = ExchangeFactory.INSTANCE.createExchange(PoloniexExchange.class); + exchange.remoteInit(); + MarketDataService marketDataService = exchange.getMarketDataService(); + Instrument instrument = exchange.getExchangeMetaData().getInstruments().keySet().iterator().next(); + + Instant now = Instant.now(); + Date endDate = Date.from(now); + Date startDate = Date.from(now.minus(1, ChronoUnit.DAYS)); + CurrencyPair currencyPair = new CurrencyPair(instrument.getBase(), instrument.getCounter()); + CandleStickData ticker = marketDataService.getCandleStickData(currencyPair,new DefaultCandleStickParam( + startDate, endDate, 60*60)); + System.out.println(ticker.toString()); + assertThat(ticker).isNotNull(); + } +} \ No newline at end of file diff --git a/xchange-stream-service-netty/src/main/java/info/bitrich/xchangestream/service/netty/WebSocketClientHandler.java b/xchange-stream-service-netty/src/main/java/info/bitrich/xchangestream/service/netty/WebSocketClientHandler.java index 156d03d81ce..954d4d960a3 100644 --- a/xchange-stream-service-netty/src/main/java/info/bitrich/xchangestream/service/netty/WebSocketClientHandler.java +++ b/xchange-stream-service-netty/src/main/java/info/bitrich/xchangestream/service/netty/WebSocketClientHandler.java @@ -19,10 +19,12 @@ import org.slf4j.LoggerFactory; public class WebSocketClientHandler extends SimpleChannelInboundHandler { + private static final Logger LOG = LoggerFactory.getLogger(WebSocketClientHandler.class); private final StringBuilder currentMessage = new StringBuilder(); public interface WebSocketMessageHandler { + public void onMessage(String message); } @@ -114,15 +116,24 @@ private void dealWithContinuation(ContinuationWebSocketFrame frame) { @Override public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) { - LOG.error( - "WebSocket client {} encountered exception ({} - {}). Closing", - ctx.channel(), - cause.getClass().getSimpleName(), - cause.getMessage(), - cause); + if (cause.getMessage() != null && cause.getMessage().toLowerCase() + .contains("connection reset")) { + LOG.warn( + "WebSocket client {} encountered exception ({} - {}). Closing", + ctx.channel(), + cause.getClass().getSimpleName(), + cause.getMessage()); + } else { + LOG.error( + "WebSocket client {} encountered exception ({} - {}). Closing", + ctx.channel(), + cause.getClass().getSimpleName(), + cause.getMessage(), + cause); + } if (!handshakeFuture.isDone()) { handshakeFuture.setFailure(cause); } ctx.close(); } -} +} \ No newline at end of file From 4dc1f0d140853a4bd89403ce15d68819ac8c96b5 Mon Sep 17 00:00:00 2001 From: Raphael Vullriede Date: Tue, 19 Nov 2024 20:57:19 +0100 Subject: [PATCH 2/2] fix: remove unintended test --- .../service/marketdata/CandleStickTest.java | 41 ------------------- 1 file changed, 41 deletions(-) delete mode 100644 xchange-poloniex/src/test/java/org/knowm/xchange/poloniex/service/marketdata/CandleStickTest.java diff --git a/xchange-poloniex/src/test/java/org/knowm/xchange/poloniex/service/marketdata/CandleStickTest.java b/xchange-poloniex/src/test/java/org/knowm/xchange/poloniex/service/marketdata/CandleStickTest.java deleted file mode 100644 index 8bb742284ad..00000000000 --- a/xchange-poloniex/src/test/java/org/knowm/xchange/poloniex/service/marketdata/CandleStickTest.java +++ /dev/null @@ -1,41 +0,0 @@ -package org.knowm.xchange.poloniex.service.marketdata; - -import static org.assertj.core.api.Assertions.assertThat; - -import java.time.Instant; -import java.time.temporal.ChronoUnit; -import java.util.Date; -import org.junit.Test; -import org.knowm.xchange.Exchange; -import org.knowm.xchange.ExchangeFactory; -import org.knowm.xchange.currency.CurrencyPair; -import org.knowm.xchange.dto.marketdata.CandleStickData; -import org.knowm.xchange.dto.marketdata.Ticker; -import org.knowm.xchange.instrument.Instrument; -import org.knowm.xchange.poloniex.PoloniexExchange; -import org.knowm.xchange.service.marketdata.MarketDataService; -import org.knowm.xchange.service.trade.params.DefaultCandleStickParam; - -/** - * @author timmolter - */ -public class CandleStickTest { - - @Test - public void tickerFetchTest() throws Exception { - - Exchange exchange = ExchangeFactory.INSTANCE.createExchange(PoloniexExchange.class); - exchange.remoteInit(); - MarketDataService marketDataService = exchange.getMarketDataService(); - Instrument instrument = exchange.getExchangeMetaData().getInstruments().keySet().iterator().next(); - - Instant now = Instant.now(); - Date endDate = Date.from(now); - Date startDate = Date.from(now.minus(1, ChronoUnit.DAYS)); - CurrencyPair currencyPair = new CurrencyPair(instrument.getBase(), instrument.getCounter()); - CandleStickData ticker = marketDataService.getCandleStickData(currencyPair,new DefaultCandleStickParam( - startDate, endDate, 60*60)); - System.out.println(ticker.toString()); - assertThat(ticker).isNotNull(); - } -} \ No newline at end of file