Skip to content
This repository has been archived by the owner on Jun 8, 2020. It is now read-only.

Not receiving any events on Binance Exchange? Is Binance broken? #567

Open
conspyrosy opened this issue Apr 5, 2020 · 2 comments
Open

Comments

@conspyrosy
Copy link

conspyrosy commented Apr 5, 2020

I'm trying to run the example code with the binance exchange but it doesnt work. In the debugger i can see the websocket is subscribed and receiving depth events. The same code works if i replace with the CoinbaseStreamingExchange...

    StreamingExchange exchange = StreamingExchangeFactory.INSTANCE.createExchange(BinanceStreamingExchange.class.getName());

    CurrencyPair BTCBUSD = new CurrencyPair("BTC", "BUSD");

    ProductSubscription subscriptions = ProductSubscription.create().addOrderbook(BTCBUSD).addTicker(BTCBUSD).build();
    // Connect to the Exchange WebSocket API. Blocking wait for the connection.
    exchange.connect(subscriptions).blockingAwait();

    Disposable subscriptionMarket = exchange.getStreamingMarketDataService()
        .getOrderBook(BTCBUSD)
        .subscribe(orderBook -> {
            System.out.println(
                "market"
            );
        }
    );

    Disposable subscriptionTicker = exchange.getStreamingMarketDataService()
        .getTicker(BTCBUSD)
        .subscribe(orderBook -> {
                       System.out.println(
                           "ticker"
                       );
               }
        );

Anyone know whats up? Thanks

@badgerwithagun
Copy link
Collaborator

Is there any code in place there to wait once you've subscribed? If that last subscription is the last line of the program, it will close immediately since the subscriptions are asynchronous.

IIRC, Coinbase sends a ticker and orderbook snapshot immediately on connection, so even if you disconnect immediately, you'll still get something. Binance doesn't.

If you're not sure what I mean, just add this at the end of your code and see what happens:

Thread.sleep(60000);

@conspyrosy
Copy link
Author

conspyrosy commented Apr 14, 2020

I'm not waiting anywhere after i subscribe but it seems to work i.e. the program doesn't exit and i start receiving events in the debug logs - see below:

17:28:02.861 [nioEventLoopGroup-2-1] INFO info.bitrich.xchangestream.binance.BinanceStreamingService - Subscribing to channel btcbusd@ticker 17:28:02.872 [nioEventLoopGroup-2-1] INFO info.bitrich.xchangestream.binance.BinanceStreamingService - Subscribing to channel btcbusd@depth 17:28:03.218 [nioEventLoopGroup-2-1] DEBUG info.bitrich.xchangestream.service.netty.JsonNettyStreamingService - Received message: {"stream":"btcbusd@depth","data":{"e":"depthUpdate","E":1586881683039,"s":"BTCBUSD","U":468408556,"u":468408682,"b":[["6940.20000000","0.01225300"],["6940.17000000","0.00720400"],["6940.16000000","0.00213100"],["6940.12000000","0.00180000"],["6940.11000000","0.11330400"],["6940.10000000","0.00800000"],["6940.09000000","0.00848200"],["6940.06000000","0.00000000"],["6940.05000000","0.00000000"],["6940.04000000","0.00000000"],["6940.03000000","0.00000000"],["6940.02000000","0.00000000"],["6939.80000000","0.00000000"],["6939.78000000","0.00800000"],["6939.77000000","0.00000000"],["6939.66000000","0.00000000"],["6939.65000000","0.00000000"],["6939.60000000","0.00000000"],["6939.58000000","0.00000000"],["6939.56000000","0.00000000"],["6939.50000000","0.00000000"],["6939.48000000","0.00000000"],["6939.26000000","0.03965400"],["6939.09000000","0.04613800"],["6938.63000000","0.00000000"],["6938.62000000","0.00000000"],["6938.54000000","0.00000000"],["6938.52000000","0.00000000"],["6938.46000000","0.09803400"],["6938.20000000","0.00000000"],["6938.17000000","0.10003100"],["6938.08000000","0.00000000"],["6937.91000000","0.00000000"],["6936.62000000","0.19200000"],["6935.67000000","1.20000000"],["6935.37000000","0.00000000"],["6934.23000000","0.00000000"],["6933.47000000","0.07211100"],["6929.37000000","0.08000000"],["6927.32000000","0.00000000"],["6927.29000000","0.02000000"],["6901.05000000","0.11200000"],["6888.20000000","0.00000000"]],"a":[["6940.41000000","0.00000000"],["6940.42000000","0.00000000"],["6940.43000000","0.00000000"],["6940.44000000","0.00000000"],["6940.60000000","0.00000000"],["6940.61000000","0.00000000"],["6940.62000000","0.00000000"],["6940.67000000","0.06800700"],["6940.70000000","0.00000000"],["6940.81000000","0.00000000"],["6940.88000000","0.00000000"],["6940.89000000","0.00000000"],["6940.91000000","0.00000000"],["6940.93000000","0.00000000"],["6940.95000000","0.00000000"],["6940.99000000","0.00000000"],["6941.05000000","0.00000000"],["6941.46000000","0.00000000"],["6941.47000000","0.00000000"],["6941.53000000","0.00000000"],["6941.56000000","0.00000000"],["6941.58000000","0.00000000"],["6941.84000000","0.00000000"],["6941.86000000","0.00000000"],["6941.90000000","0.01947600"],["6941.92000000","0.00000000"],["6942.01000000","0.00000000"],["6942.20000000","0.00780200"],["6942.55000000","0.04251700"],["6942.63000000","0.15131400"],["6942.85000000","0.00148600"],["6943.00000000","0.19602500"],["6944.06000000","0.00000000"],["6944.49000000","0.00000000"],["6944.62000000","1.20000000"],["6944.82000000","0.00000000"],["6950.31000000","0.02000000"],["6952.06000000","0.11000000"],["6955.89000000","0.00000000"],["6955.98000000","0.10000000"],["7065.35000000","0.06098300"],["7079.92000000","0.06694300"]]}} 17:28:03.461 [nioEventLoopGroup-2-1] DEBUG info.bitrich.xchangestream.service.netty.JsonNettyStreamingService - Received message: {"stream":"btcbusd@ticker","data":{"e":"24hrTicker","E":1586881683298,"s":"BTCBUSD","p":"169.76000000","P":"2.507","w":"6859.10641011","x":"6770.92000000","c":"6940.71000000","Q":"0.02316900","b":"6940.44000000","B":"0.01225300","a":"6940.75000000","A":"0.00147500","o":"6770.95000000","h":"6966.10000000","l":"6745.01000000","v":"4123.26699100","q":"28281927.04857940","O":1586795283287,"C":1586881683287,"F":7971662,"L":8154307,"n":182646}} 17:28:04.209 [nioEventLoopGroup-2-1] DEBUG info.bitrich.xchangestream.service.netty.JsonNettyStreamingService - Received message: {"stream":"btcbusd@depth","data":{"e":"depthUpdate","E":1586881684039,"s":"BTCBUSD","U":468408683,"u":468408870,"b":[["6940.74000000","0.01733400"],["6940.73000000","0.01405300"],["6940.70000000","0.00000000"],["6940.69000000","0.00000000"],["6940.66000000","0.00000000"],["6940.65000000","0.00000000"],["6940.61000000","0.00000000"],["6940.60000000","0.00000000"],["6940.56000000","0.00000000"],["6940.55000000","0.00000000"],["6940.51000000","0.25000000"],["6940.50000000","0.00000000"],["6940.49000000","0.00000000"],["6940.46000000","0.00000000"],["6940.45000000","0.25000000"],["6940.44000000","0.00000000"],["6940.40000000","0.00977000"],["6940.39000000","0.00000000"],["6940.36000000","0.00000000"],["6940.34000000","0.00000000"],["6940.33000000","0.20200000"],["6940.30000000","0.00000000"],["6940.27000000","0.00800000"],["6940.26000000","0.00000000"],["6940.25000000","0.00000000"],["6940.22000000","0.04838000"],["6940.21000000","0.25000000"],["6940.20000000","0.00000000"],["6940.17000000","0.00000000"],["6940.16000000","0.00000000"],["6940.12000000","0.00000000"],["6940.10000000","0.00000000"],["6940.09000000","0.00000000"],["6939.78000000","0.00000000"],["6939.26000000","0.00000000"],["6939.25000000","0.00000000"],["6939.11000000","0.00000000"],["6939.09000000","0.00000000"],["6938.46000000","0.11515700"],["6938.17000000","0.00000000"],["6937.46000000","0.43100000"],["6936.71000000","0.28832100"],["6936.66000000","0.00000000"],["6936.30000000","0.00000000"],["6936.29000000","0.57619800"],["6936.05000000","0.00000000"],["6935.78000000","0.10000000"],["6935.67000000","1.10000000"],["6935.54000000","0.25000000"],["6935.21000000","0.15000000"],["6935.01000000","0.00000000"],["6934.49000000","0.00000000"],["6934.48000000","0.00000000"],["6933.92000000","0.00000000"],["6933.61000000","0.00000000"],["6933.60000000","0.26000000"],["6933.54000000","0.12018300"],["6933.45000000","0.00000000"],["6932.85000000","0.00000000"],["6931.72000000","0.00000000"],["6931.43000000","0.00000000"],["6929.09000000","1.10000000"],["6926.91000000","0.15000000"],["6926.62000000","0.10100000"],["6925.51000000","0.24208000"],["6924.66000000","0.10000000"],["6924.54000000","0.00000000"],["6924.43000000","0.00000000"],["6920.39000000","0.00000000"]],"a":[["6940.67000000","0.00000000"],["6940.71000000","0.00000000"],["6940.75000000","0.00000700"],["6941.59000000","0.00000000"],["6941.90000000","0.00000000"],["6941.92000000","0.00000000"],["6941.93000000","0.00000000"],["6942.20000000","0.00000000"],["6942.30000000","0.00000000"],["6942.45000000","0.00000000"],["6942.48000000","0.08644500"],["6942.55000000","0.00000000"],["6942.56000000","0.00000000"],["6942.63000000","0.01012000"],["6942.64000000","0.01850500"],["6942.68000000","0.00000000"],["6942.79000000","0.00000000"],["6943.00000000","0.00202500"],["6943.43000000","0.00000000"],["6943.80000000","0.00000000"],["6943.99000000","0.00000000"],["6944.38000000","0.19800000"],["6944.61000000","0.01711800"],["6944.63000000","0.15125500"],["6944.71000000","0.57619800"],["6944.80000000","0.00000000"],["6944.83000000","0.15900000"],["6945.07000000","0.00000000"],["6945.93000000","0.00000000"],["6946.08000000","0.43000000"],["6946.34000000","0.11904800"],["6946.38000000","0.00000000"],["6947.32000000","0.00000000"],["6947.68000000","0.15000000"],["6947.96000000","0.06359500"],["6947.97000000","0.00000000"],["6948.01000000","0.25000000"],["6948.05000000","0.00000000"],["6948.55000000","0.00000000"],["6948.95000000","0.01414700"],["6949.93000000","0.00000000"],["6950.14000000","0.10000000"],["6950.23000000","0.33199000"],["6954.94000000","0.00000000"],["6959.24000000","0.10000000"],["7296.88000000","0.74080600"]]}} 17:28:04.463 [nioEventLoopGroup-2-1] DEBUG info.bitrich.xchangestream.service.netty.JsonNettyStreamingService - Received message: {"stream":"btcbusd@ticker","data":{"e":"24hrTicker","E":1586881684283,"s":"BTCBUSD","p":"169.80000000","P":"2.508","w":"6859.10655627","x":"6770.92000000","c":"6940.75000000","Q":"0.00427000","b":"6940.74000000","B":"0.01733400","a":"6940.75000000","A":"0.00000700","o":"6770.95000000","h":"6966.10000000","l":"6745.01000000","v":"4123.27437400","q":"28281978.29201213","O":1586795283910,"C":1586881683910,"F":7971662,"L":8154310,"n":182649}}

But I don't see "market" or "ticker" printed after each event as i expect (as this is in the lambda i'm passing to react to events). For coinbase i see this as expected:

17:33:54.627 [nioEventLoopGroup-2-1] DEBUG info.bitrich.xchangestream.service.netty.JsonNettyStreamingService - Received message: {"type":"l2update","product_id":"BTC-USD","changes":[["buy","6946.24","0.00000000"]],"time":"2020-04-14T16:33:54.034485Z"} market 17:33:54.640 [nioEventLoopGroup-2-1] DEBUG info.bitrich.xchangestream.service.netty.JsonNettyStreamingService - Received message: {"type":"l2update","product_id":"BTC-USD","changes":[["buy","6914.20","0.00000000"]],"time":"2020-04-14T16:33:54.035934Z"} market

i.e. you can see the "market" messages intertwined with the debug logs of the data from the websocket

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants