question

Upvotes
Accepted
1 0 1 1

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!

trepissueconnection-error
icon clock
10 |1500

Up to 2 attachments (including images) can be used with a maximum of 5.0 MiB each and 10.0 MiB total.

Upvotes
Accepted
23k 22 9 14

Hello @Raghav Atal ,

I would suggest to confirm, that your Python version is new, modules websocket and websocket-client are recent if not the latest, and to verify the same with the latest example code available from Refinitiv GitHub Websocket examples repository.

You may wish to also test the connection to the same RTDS host with Try It Out example, please find the details in Quick Start - Connecting to Refinitiv Real-Time Distribution System.

I completely agree with @nick.zincone.1 If you continue experiencing the connectivity issue, would next reach out to your market data/network group in charge of RTDS (formerly TREP).

icon clock
10 |1500

Up to 2 attachments (including images) can be used with a maximum of 5.0 MiB each and 10.0 MiB total.

Upvotes
9.7k 49 38 60

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.

icon clock
10 |1500

Up to 2 attachments (including images) can be used with a maximum of 5.0 MiB each and 10.0 MiB total.

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.

Upvotes
20.3k 73 10 20

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


icon clock
10 |1500

Up to 2 attachments (including images) can be used with a maximum of 5.0 MiB each and 10.0 MiB total.

Upvotes
9.7k 49 38 60

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.

icon clock
10 |1500

Up to 2 attachments (including images) can be used with a maximum of 5.0 MiB each and 10.0 MiB total.

Click below to post an Idea Post Idea