Crypto-toolbox / btfxwss

Bitfinex Websocket API Client written in Python3
MIT License
284 stars 125 forks source link

Problem spotted getting Wallet balance for second time #34

Closed FeSens closed 7 years ago

FeSens commented 7 years ago

Hello, There is a problem with this code:

wss = BtfxWss(key=key, secret=secret) 
wss.start()
wss.authenticate()
while True:
  if not wss.wallets.empty():
    print(wss.wallets.get())
  else:
    print("No wallet update received")

Actual Results

First loop iteration: Revice correct wallet balance Every other loop iteration, even after the balance change on BitFinex site: "No wallet update recived"

Expected Results

Well, the wallet should receive an update when it is changed

EDIT So, basically no post request is being done to get the new wallet balance. As @nlsdfnbch explained below there is no need to make a post request as the nature of the web-socket is to send updates automatically

FeSens commented 7 years ago

I think post requests are done by using the _send_auth_command(self, channel_name, data), I'm i right? But I'm not entirely sure how to request a wallet update, or any other account information.

deepbrook commented 7 years ago

Hey @FelipeSBonetto ! Firstly, I want to avoid confusion about what's supposed to be going on: After connecting to the API, you send a single request for account data (which you do with authenticate()), afterwards, no more requests are sent - that is the nature of a Websocket connection - you request a channel, and any updates are sent automatically, as the change happens on the server side.

So, there can be two possible explanations:

  1. The websocket API hasn't registered a change in your wallet yet, thus it does not send an update I find this unlikely, but it does happen. However, there is not much we could do to fix this.
  2. The client does not properly sort wallet updates This is probably the case. In order to debug this, I'll need the logs, however. So please run your code again, and add the following lines to the top and attach the created btfxwss.log file:
import logging
logging.basicConfig(filename="btfxwss.log", level=logging.DEBUG)

wss = BtfxWss(key, secret, log_level=logging.DEBUG)
...

Thanks for reporting and helping out!

FeSens commented 7 years ago

Hellow @nlsdfnbch, again thank you for your kind and fast reply :1st_place_medal: Oh, I'm sorry for the confusion I'm new to this web-socket concept. Here is the log, I could spot on the last lines a 'wu' event, is this a wallet update? Even if it is, the client din't show the update on the screen.

btfxwss.txt

deepbrook commented 7 years ago

Yup, in the line right after it you can see the problem:

ERROR:btfxwss.queue_processor:Channel ID does not have a data handler! ('data', [0, 'wu', ['exchange', 'BCH', 0, 0, None]], 1504114645.7759268)

Hence, we need to implement that. I'll have a look at it!

deepbrook commented 7 years ago

If I'm not mistaken, the last commit should take care of it. Could you verify that?

FeSens commented 7 years ago

It sure did! Blazing fast fix, wallets are updating now. Thanks a lot! Until next time!