Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Does this library support auto re connection of Binance websocket when the network connection drops? #133

Closed
andrewlin0410 opened this issue Sep 8, 2019 · 2 comments
Labels
Question✋ Further information is requested

Comments

@andrewlin0410
Copy link

Hi Please let me know. Thank you

@namjug-kim namjug-kim added the Question✋ Further information is requested label Sep 9, 2019
@namjug-kim
Copy link
Owner

@andrewlin0410

it's not best solution, but it will be work

ExchangeClientFactory.websocket(ExchangeVendor.BINANCE)
            .createDepthSnapshot(listOf(CurrencyPair(Currency.BTC, Currency.USDT)))

            // retry when connetion drops
            .doOnTerminate { throw RuntimeException("terminated!") }
            .retryWhen { throwablePublisher ->
                throwablePublisher
                    .doOnNext { log.error(it.message, it) }
                    .flatMap { Mono.delay(Duration.ofSeconds(2)) } // retry wait time
            }

            .doOnNext { /* do something you want */ }

half connection checker(ping/pong handler) not implemented in binance yet. so upper reconnection code is not work with half connection.
but other case it will work fine :).

@andrewlin0410
Copy link
Author

andrewlin0410 commented Oct 25, 2019

while (true) {
            try {

                ExchangeWebsocketClient exchangeWebsocketClient = ExchangeClientFactory.websocket(ExchangeVendor.BINANCE);

                List<CurrencyPair> targetPairs = Collections.singletonList(CurrencyPair.parse("BTC", "USDT"));
                Flux<TickData> tickDataFlux = exchangeWebsocketClient.createTradeWebsocket(targetPairs);
//                .doOnNext(tickData -> System.out.println(tickData.getQuantity()))
//                .subscribe();
                while (true) {
                    TickData tickData = tickDataFlux.blockFirst();
                    System.out.println("time: " + System.currentTimeMillis());
                    System.out.println(tickData.getPrice());
                    System.out.println(tickData.getQuantity());
                    System.out.println("=======================");
                }
            } catch (Exception e) {
                StringWriter stringWriter = new StringWriter();
                    PrintWriter printWriter = new PrintWriter(stringWriter);
                    e.printStackTrace(printWriter);
                    testLogger.info(stringWriter.toString());
                    testLogger.info(e.getMessage());

            }
        }

Would this work? Looks like it does reconnect after wifi disconnection. I just don't know if it will work after 24h. I heard binance would drop connection after 24h?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Question✋ Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants