Crypto-toolbox/btfxwss

Issue KeyError from wss.tickers('XXX')

AlexMout opened this issue · 7 comments

I get the same error as people in #51 and #40 (raise KeyError(pair) KeyError: 'BTCUSD') when launching the chunk of code provided on the main page of the project.
I tried with other tickers, adding a 't' at the beginning, other function for order books and candles but the same issue arises.
I tried with the master branch and the dev branch, I'm running Python 3.6.

Thanks a lot!

Hey @AlexMout ,
I can't reproducde this issue with dev - could you post your code and the test.log file ?

Thanks for your short answer!

Here is the log:

INFO:btfxwss.connection:Connection opened
INFO:btfxwss.connection:Initialized Client on API Version 2
Traceback (most recent call last):
File "/Users/alexmouturat/Desktop/website/Articles_Python/exchange_interaction.py", line 27, in
ticker_q = wss.tickers('BTCUSD')
File "/Users/alexmouturat/anaconda/lib/python3.6/site-packages/btfxwss/client.py", line 105, in tickers
raise KeyError(pair)
KeyError: 'BTCUSD'
DEBUG:btfxwss.client:_subscribe: {'event': 'subscribe', 'channel': 'ticker', 'symbol': 'BTCUSD'}

And the piece of code:

`import logging
import time
import sys

from btfxwss import BtfxWss

log = logging.getLogger(name)

fh = logging.FileHandler('test.log')
fh.setLevel(logging.DEBUG)
sh = logging.StreamHandler(sys.stdout)
sh.setLevel(logging.DEBUG)

log.addHandler(sh)
log.addHandler(fh)
logging.basicConfig(level=logging.DEBUG, handlers=[fh, sh])

wss = BtfxWss()
wss.start()

while not wss.conn.connected.is_set():
time.sleep(1)

wss.subscribe_to_ticker('BTCUSD')

ticker_q = wss.tickers('BTCUSD')

#while not ticker_q.empty():
#print(ticker_q.get())

wss.stop()`

If I install btfxwss package with 'pip install btfwss' it installs the package from the master branch right?
How should I install the package from the dev branch? (To verify I'm not doing something wrong..)

Hey @AlexMout ,
While the call traceback helps as well, there should be a test.log in the directory you execute the code from - that's the log I need :)

the easiest way to install it is to download the dev branch and run python setup.py install from within the downloaded repository.

Thanks @nlsdfnbch

I tried to reinstall the dev branch but the error is still the same. Here is the test.log :

INFO:btfxwss.connection:Connection opened
INFO:btfxwss.connection:API version: 2
DEBUG:btfxwss.client:_subscribe: {'event': 'subscribe', 'channel': 'ticker', 'symbol': 'BTCUSD'}
INFO:btfxwss.connection:Connection opened
INFO:btfxwss.connection:API version: 2
DEBUG:btfxwss.client:_subscribe: {'event': 'subscribe', 'channel': 'ticker', 'symbol': 'BTCUSD'}
INFO:btfxwss.connection:Connection opened
INFO:btfxwss.connection:Initialized Client on API Version 2
DEBUG:btfxwss.client:_subscribe: {'event': 'subscribe', 'channel': 'ticker', 'symbol': 'BTCUSD'}
INFO:btfxwss.connection:Connection opened
INFO:btfxwss.connection:Initialized Client on API Version 2
DEBUG:btfxwss.client:_subscribe: {'event': 'subscribe', 'channel': 'ticker', 'symbol': 'BTCUSD'}
INFO:btfxwss.connection:Connection opened
INFO:btfxwss.connection:Initialized Client on API Version 2
DEBUG:btfxwss.client:_subscribe: {'event': 'subscribe', 'channel': 'ticker', 'symbol': 'BTCUSD'}
INFO:btfxwss.connection:Connection opened
INFO:btfxwss.connection:Initialized Client on API Version 2
DEBUG:btfxwss.client:_subscribe: {'event': 'subscribe', 'channel': 'ticker', 'symbol': 'BTCUSD'}
INFO:btfxwss.connection:Connection opened
INFO:btfxwss.connection:Initialized Client on API Version 2
DEBUG:btfxwss.client:_subscribe: {'event': 'subscribe', 'channel': 'ticker', 'symbol': 'BTCUSD'}
INFO:btfxwss.connection:Connection opened
INFO:btfxwss.connection:Initialized Client on API Version 2
DEBUG:btfxwss.client:_subscribe: {'event': 'subscribe', 'channel': 'ticker', 'symbol': 'tBTCUSD'}
INFO:btfxwss.connection:Connection opened
INFO:btfxwss.connection:Initialized Client on API Version 2
DEBUG:btfxwss.client:_subscribe: {'event': 'subscribe', 'channel': 'ticker', 'symbol': 'XRPUSD'}
INFO:btfxwss.connection:Connection opened
INFO:btfxwss.connection:Initialized Client on API Version 2
DEBUG:btfxwss.client:_subscribe: {'event': 'subscribe', 'channel': 'ticker', 'symbol': 'tXRPUSD'}

Please do not rule out any possible silly error that I could perform...

Hey @AlexMout,
Sorry for the slow reply.
Has this issue persisted? I'm getting the feeling it might be related to bitfinex, since your log indicates that you never actually received a subscription confirmation for your subscription to the ticker channel.
Essentially, this means that there is no data (and no Queue with the key BTCUSD) - this behaviour was changed recently in PR #115, and now returns an empty Queue instance.

No response, assuming issue resolved.

For those who are still confused by this or a similar subscription issue. This piece of code

wss.subscribe_to_ticker('BTCUSD')
ticker_q = wss.tickers('BTCUSD')

will not work because you have to wait for the 'subscribed' response of the exchange before calling ticker_q = wss.tickers('BTCUSD') (i.e. there is no queue to read from until the exchange has confirmed subscription).

This will work:

wss.subscribe_to_ticker('BTCUSD')
time.sleep(10)
ticker_q = wss.tickers('BTCUSD')

The name of the pair (i.e. whether it should be 'BTCUSD' or 'tBTCUSD' or even 'fBTCUSD') is another issue to be addressed (separately)