CCob / bittrex4j

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

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

What's the proper way of subscribe to level2 book

szd116 opened this issue · comments

I have just updated to 1.09 but getting some problems with this new release. I have the following code
bittrexExchange.onUpdateExchangeState(this);
bittrexExchange.connectToWebSocket(() -> {
bittrexExchange.subscribeToExchangeDeltas("BTC-XVG", null);
});
this works. But how do I subscribe to more exchangeDeltas after the webSocket is connected for instance
if I do the following
bittrexExchange.onUpdateExchangeState(this);
bittrexExchange.connectToWebSocket(() -> {
});
bittrexExchange.subscribeToExchangeDeltas("BTC-XVG", null);
I will get this error, and no updates ! I used to be able to this in 1.08. Please help. Thanks.
Error: com.github.signalr4j.client.InvalidStateException: The operation is not allowed in the 'Connecting' state

Seems to work fine for me with BTC-ETH and BTC-XRP. Are you calling queryExchangeState by any chance? There is an issue with it in 1.0.9 that might be putting the web socket into an error state. This has since been fixed in 1.0.10-SNAPSHOT and I'll release 1.0.10 when I get a chance

Ah, I think I see your problem. You have to wait for the socket to become connected in the connectoToWebSocket lambda callback. connectToWebSocket is asynchronous which is why you are getting The operation is not allowed in the 'Connecting' state. It's a little difficult to read the code in an unformatted state, so perhaps you can create gist to show me an example

I see. I worked around the issues for the level2 book. Now it seems fine. But when it comes to pulling the data I have:

bittrexExchange = new BittrexExchange("key1","key2");

	bittrexExchange.queryExchangeState("BTC-ETH", orderBook -> {
		ConcurrentSkipListMap<BigDecimal, BigDecimal> asks = new ConcurrentSkipListMap<>(Comparator.naturalOrder());
		for (MarketOrder ask : orderBook.getSells()) {
			asks.put(ask.getRate(), (ask.getQuantity()));
			System.out.println("inside take marketDataSnapShot " + ask.getRate() + " size: " + ask.getQuantity());
		}
	});

I am getting Error: com.google.gson.JsonSyntaxException: java.lang.IllegalStateException: Expected BEGIN_OBJECT but was STRING at path $
Is this related to the bug in 1.09 that you mentioned above ? Thanks.

That's the bug I described in my first post. This is fixed is 1.0.10-SNAPSHOT

Thank you CCob. Please close.

No problem. Hopefully this week I'll get 1.0.10 release out.