bitvavo / python-bitvavo-api

Python wrapper for the Bitvavo API
https://pypi.org/project/python-bitvavo-api/
ISC License
38 stars 25 forks source link

Book subscription on websocket is not working #49

Open DukeOfRI opened 6 months ago

DukeOfRI commented 6 months ago

I am trying to use the book subscription on the websocket. If I run the code that is in the example on the website, I get an error. I am referring to the python example here: https://docs.bitvavo.com/#tag/Market-data-subscription-WebSocket/paths/~1subscribeBook/post

Python 3.12.1 python_bitvavo_api 1.4.1

Steps to reproduce:

from python_bitvavo_api.bitvavo import Bitvavo

def callback(response):
    print(f"Callback: {response}")  # Note that json.dumps from documentation also doesn't work

def errorCallback(error):
    raise RuntimeError()

bitvavo = Bitvavo()
websocket = bitvavo.newWebsocket()
websocket.setErrorCallback(errorCallback)

websocket.subscriptionBook("BTC-EUR", callback)

I get the following traceback.

Traceback (most recent call last):
  File "..\.venv\Lib\site-packages\websocket\_app.py", line 660, in _callback
    callback(self, *args)
  File "..\.venv\Lib\site-packages\python_bitvavo_api\bitvavo.py", line 485, in on_message
    callbacks['subscriptionBook'][market](ws, msg)
  File "..\.venv\Lib\site-packages\python_bitvavo_api\bitvavo.py", line 78, in processLocalBook
    ws.localBook[market]['bids'] = message['response']['bids']
    ^^^^^^^^^^^^
AttributeError: 'WebSocketApp' object has no attribute 'localBook'
DukeOfRI commented 6 months ago

Seems like I found the problem. However, I cannot create a branch/PR.

The issue is solved by changing line 485 from: callbacks['subscriptionBook'][market](ws, msg) to: callbacks['subscriptionBook'][market](self, msg)

And line 514 from: callbacks['subscriptionBook'][market](ws, msg) to: callbacks['subscriptionBook'][market](self, msg)