Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Book subscription on websocket is not working #49

Open
DukeOfRI opened this issue Apr 9, 2024 · 1 comment
Open

Book subscription on websocket is not working #49

DukeOfRI opened this issue Apr 9, 2024 · 1 comment

Comments

@DukeOfRI
Copy link

DukeOfRI commented Apr 9, 2024

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
Copy link
Author

DukeOfRI commented Apr 9, 2024

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)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant