CCob / bittrex4j

Java library for accessing the Bittrex Web API's and Web Sockets

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Websocet subscribeToExchangeDeltas method for many markets

CheremisinVlad opened this issue · comments

Hello. Previously i open this issue #40
I've subscribed for market deltas but only for one market there.
Now I need order book for every pair on exchange.
I tried it like this:

BittrexExchange  exchange = new BittrexExchange();

            getBittrexMarkets().forEach((market)->{

                    exchange.connectToWebSocket(()->{

                        exchange.subscribeToExchangeDeltas(market,null);

                        exchange.onUpdateExchangeState(orderBook->{

    Stream.of(orderBook.getFills()).forEach(fill-> System.out.println(market + fill.getQuantity()));

                        });
                    });   
            });
        

But when i run this code i recieve this error:

ERROR WebSockets [SignalRLoggerDecorator.java:30] HubConnection - Error: com.github.signalr4j.client.InvalidStateException: The operation is not allowed in the 'Disconnected' state

I also tried it this way:

BittrexExchange  exchange = new BittrexExchange();
            exchange.connectToWebSocket(()->{
                getBittrexMarkets().forEach((market)->{
                    exchange.subscribeToExchangeDeltas(market,null);
                    exchange.onUpdateExchangeState(orderBook->{
                        Stream.of(orderBook.getFills()).forEach(fill -> {
                            System.out.println(market + " " + fill.getQuantity());
                        });
                    });
                });
            });

When i run it i get same output for every market(some part of it):

BTC-HYDRO 3349.0
BTC-UPP 3349.0
USD-ADA 3349.0
USD-ZEC 3349.0
USDT-DOGE 3349.0
BTC-ENJ 3349.0
BTC-MET 3349.0

And i tried do it in concurent way but it's also don't work.
Is any way subscribe for more than one market and recieve data simultaneously?
Thanks in advance!

You should only register a single event listener for onUpdatedExchangeState and only call connectToWebsocket once. Then call subscribeToExchangeDeltas for each market

Thanks a lot. Sorry for stupid question and your wasting efforts.