BitMEX/sample-market-maker

Websocket error "can only concatenate str (not "int") to str"

Closed this issue · 4 comments

Hello,

I'm trading on bitmex since 2019 using the websocket client. It is the same python module used in the sample-market-maker.

Everything worked fine until march 27, 2023. But since then I sometimes get the following error "can only concatenate str (not "int") to str" directly as websocket error message.

I'm using an older version of the websocket client (1.2.3). As mentioned before without getting the error. Only thing I recognised: there was an issue with the websocket that day and a fix that mentioned CancelAllAfter. But I don't use that.

So the question is: What changed that day? There may be a problem in the websocket client, so the real error cannot be processed due to an internal concat error. But I couldn't find any sign of it in the websocket module.

Hi,

Thanks for raising this. Can you please provide more information and context on the error? Stack trace would be helpful.

Thank you!

Hello DanishAlsayed,

thank you for your reply. Here is the simple code I use for errors from the websocket client. Nothing special:

def on_error(self, ws, error_msg):
     print(f"ERROR - Websocket Error | {error_msg}")

Output (as mentioned, this sometimes appears since march 27, 2023):

ERROR - Websocket Error | can only concatenate str (not "int") to str

Other errors are displayed correctly, e.g.

ERROR - Websocket Error | Connection to remote host was lost.

I don't know if I can trace the websocket module. I'll check that.

Thanks, so you have received the string can only concatenate str (not "int") to str from the WS directly? What were you subscribed on? WS trace could help.

I did some further research. At first I thought it might be from the websocket itself or the websocket client module. Now I know I may have a bug in my own code.

I modified the websocket module to get a traceback:

I put the code print(traceback.format_exc()) inside the "_callback" function in _app.py:

def _callback(self, callback, *args):
    if callback:
        try:
            callback(self, *args)
  
        except Exception as e:
            print(traceback.format_exc())
            _logging.error("error from callback {}: {}".format(callback, e))
            if self.on_error:
                self.on_error(self, e)

And the traceback revealed the following:

Traceback (most recent call last):
  File "/home/pi/Share/websocket2/_app.py", line 409, in _callback
    callback(self, *args)
  File "/home/pi/Share/Bitmex Trading Bot V37.py", line 1657, in on_close
    print(f"WARNING - Websocket closed{' | ' + close_status_code if close_status_code is not None else ''}{' | ' + close_msg if close_msg is not None else ''} | Trying to reconnect in 5 sec ...")
TypeError: can only concatenate str (not "int") to str

So my on_close function causes this:

def on_close(self, ws, close_status_code, close_msg):
        print(f"WARNING - Websocket closed{' | ' + close_status_code if close_status_code is not None else ''}{' | ' + close_msg if close_msg is not None else ''} | Trying to reconnect in 5 sec ...")

Exactly this part: + close_status_code this can now be an int value and it cannot be concatenate with str. This has never happend before march 27, 2023.

So this error in the on_close function throws an exception in the callback function in the websocket client and causes an on_error.

I will close this issue :-)

Many thanks for your help.