TREP Websocket connection issues : python example market_price.py unable to connect: Error 400

The example websocket python script connects after 7 or 8 tries. Please see below for logs

(tensorflow) C:\Users\Raghav.Atal\Documents\Developer\external_code_repos\websocket-api\Applications\Examples\python>python market_price.py --host trep-dacs-main.corp.stonex.com --user MDHUB

Connecting to WebSocket ws://trep-dacs-main.corp.stonex.com:15000/WebSocket ...

Handshake status 400 OK

on_close() takes 1 positional argument but 3 were given


(tensorflow) C:\Users\Raghav.Atal\Documents\Developer\external_code_repos\websocket-api\Applications\Examples\python>python market_price.py --host trep-dacs-main.corp.stonex.com --user MDHUB

Connecting to WebSocket ws://trep-dacs-main.corp.stonex.com:15000/WebSocket ...

Handshake status 400 OK

on_close() takes 1 positional argument but 3 were given


(tensorflow) C:\Users\Raghav.Atal\Documents\Developer\external_code_repos\websocket-api\Applications\Examples\python>python market_price.py --host trep-dacs-main.corp.stonex.com --user MDHUB

Connecting to WebSocket ws://trep-dacs-main.corp.stonex.com:15000/WebSocket ...

Handshake status 400 OK

on_close() takes 1 positional argument but 3 were given


(tensorflow) C:\Users\Raghav.Atal\Documents\Developer\external_code_repos\websocket-api\Applications\Examples\python>python market_price.py --host trep-dacs-main.corp.stonex.com --user MDHUB

Connecting to WebSocket ws://trep-dacs-main.corp.stonex.com:15000/WebSocket ...

Handshake status 400 OK

on_close() takes 1 positional argument but 3 were given


(tensorflow) C:\Users\Raghav.Atal\Documents\Developer\external_code_repos\websocket-api\Applications\Examples\python>python market_price.py --host trep-dacs-main.corp.stonex.com --user MDHUB

Connecting to WebSocket ws://trep-dacs-main.corp.stonex.com:15000/WebSocket ...

Handshake status 400 OK

on_close() takes 1 positional argument but 3 were given


(tensorflow) C:\Users\Raghav.Atal\Documents\Developer\external_code_repos\websocket-api\Applications\Examples\python>python market_price.py --host trep-dacs-main.corp.stonex.com --user MDHUB

Connecting to WebSocket ws://trep-dacs-main.corp.stonex.com:15000/WebSocket ...

Handshake status 400 OK

on_close() takes 1 positional argument but 3 were given


(tensorflow) C:\Users\Raghav.Atal\Documents\Developer\external_code_repos\websocket-api\Applications\Examples\python>python market_price.py --host trep-dacs-main.corp.stonex.com --user MDHUB

Connecting to WebSocket ws://trep-dacs-main.corp.stonex.com:15000/WebSocket ...

WebSocket successfully connected!

Best Answer

Answers

  • Hi @Raghav Atal

    There are a couple of things I would suggest you do. It appears the example code 'market_price.py' may have implemented an old signature for some of the callbacks. For example, it is complaining about the number of arguments passed to the on_close(). Within the example, it only defines one positional argument - I would suggest you update the example so the on_close() looks like this:

    def on_close(ws, close_status_code, close_msg):
    print("### closed ###")

    Update the code to print out the status code and msg arguments that are being passed in. This should at least provide some clue as to why it is failing to connect to your local market data system and also eliminate the error message:

    on_close() takes 1 positional argument but 3 were given

    Assuming it will provide any more meaningful information, I would reach out to your market data team to understand why it is rejecting your request - providing to them this information. At first glance, it doesn't appear the code is the issue but rather the server.

  • Hi @Raghav Atal

    I seem to recall that the error 'on_close() takes 1 positional argument but 3 were given ' occurs when the websocket library is installed - rather than websocket-client

    Can you confirm you have done:

    pip install websocket-client

    Please the Websocket API QuickStart for further details


  • Hello Nick,

    I even tried with updated signature for on_close function and printed out the close_status_code and close_msg but both of them are set to None. The on_close error is now gone, but the problem of not connecting to the websocket still remains.


    (tensorflow) C:\Users\Raghav.Atal\Documents\Developer\external_code_repos\websocket-api\Applications\Examples\python>python market_price.py --host trep-dacs-main.corp.stonex.com --user MDHUB

    Connecting to WebSocket ws://trep-dacs-main.corp.stonex.com:15000/WebSocket ...

    Handshake status 400 OK

    Close_status_code: None

    close_msg: None

    WebSocket Closed

  • Hi @Raghav Atal

    Given there are no additional details within the on_close that explain why the request is failing, I would suggest you reach out to your market data team as they can explain why they are rejecting the request.

  • Hi @Raghav Atal

    Can you confirm where you pulled that example (market_price.py) from? If it is not from here (https://github.com/Refinitiv/websocket-api/blob/master/Applications/Examples/python/market_price.py), can you try that version. Also, can you confirm the version of Python you are using? Confirm the WebSocket library? Also, can you try running the example without specifying any user name? I want to see how the example responds. Thanks.