Giter Site home page Giter Site logo

Comments (2)

namjug-kim avatar namjug-kim commented on September 4, 2024 2

@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 :).

from reactive-crypto.

andrewlin0410 avatar andrewlin0410 commented on September 4, 2024
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?

from reactive-crypto.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.