xchange-stream
xchange-stream copied to clipboard
okex null pointer exception
When run the xchange-stream/xchange-okcoin/src/test/java/info/bitrich/xchangestream/okcoin/OkExManualExample.java , a nullPointerException raised and the websocket was disconnected.
After trace the source code, I found that okex send a "addChannel" message after subscription. The "addChannel" message is like: {"binary":0,"channel":"addChannel","data":{"result":true,"channel":"ok_sub_spot_btc_usd_ticker"}}
It seems like that there would be two way to fix it.
- change the handleChannelMessage method to check whether the "channel" is in "channles" before get the "emitter".
- add the "addChannel" as default channel of okex
I guess that the okcoin exchange may have the same issue. Which solution is better? Or any other ideas?
I also had this issue, and then it disappeared. The problem I guess is with a fast server response. When first tickers arrive very fast, the emitter inside the subscriber is not properly initialised. Later, I could not reproduce the problem. With my modifications code works properly. Instead of sending the subscribe message to the server inside client subscription, I changed the code to send a message after the client's subscription is complete.
public void sendSubscribeMessage(String channelName, Object[] args) throws IOException {
sendMessage(getSubscribeMessage(channelName, args));
}
...
@Override
public Observable<Ticker> getTicker(CurrencyPair currencyPair, Object... args) {
String channel = String.format("ok_sub_spot_%s_%s_ticker", currencyPair.base.toString().toLowerCase(), currencyPair.counter.toString().toLowerCase());
return service.subscribeChannel(channel)
.doOnSubscribe(disposable -> {
service.sendSubscribeMessage(channel, args);
})
.map(s -> {
// TODO: fix parsing of BigDecimal attribute val that has format: 1,625.23
OkCoinTicker okCoinTicker = mapper.treeToValue(s.get("data"), OkCoinTicker.class);
return OkCoinAdapters.adaptTicker(new OkCoinTickerResponse(okCoinTicker), currencyPair);
});
}
I hope this will work.
This didn't work, seems to still be a problem