xchange-stream icon indicating copy to clipboard operation
xchange-stream copied to clipboard

okex null pointer exception

Open yangguang760 opened this issue 6 years ago • 2 comments

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.

  1. change the handleChannelMessage method to check whether the "channel" is in "channles" before get the "emitter".
  2. 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?

yangguang760 avatar Jan 09 '18 08:01 yangguang760

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.

chaschev avatar Jan 25 '18 03:01 chaschev

This didn't work, seems to still be a problem

somguyth avatar Mar 11 '18 18:03 somguyth