question

Upvotes
Accepted
3 0 0 1

How do grant and deployed_platform_username work in platform.Definition

I am having issues creating a session using the Python API.

We have a local ADS and DACS. deployed_platform_host is the ADS address and I have put a valid DACS user in deployed_platform_username.

For grant I am using GrantPassword with my Eikon username and password. I suspect this is wrong but I don't have any other users that seem to work.

I can also connect without using the DACS with the Eikon user but then I get an insufficient scope for trapi.streaming.pricing.read or trapi.data.pricing.read. I believe this is expected for an Eikon user?

Since we can connect and receive prices from our ADS using the C++ RFA libraries without having to use a username and password I was wondering if there is a way to do this using the Python libraries?

The application I am working on is a server side application that will retrieve volatility information to store in a database so I am conscious that there could be licensing issues here. Let me know if this is something that should be resolved with our account manager.

python#technologyDACSADS
icon clock
10 |1500

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

@matthew.french

Hi,

Thank you for your participation in the forum.

Are any of the replies below satisfactory in resolving your query?

If yes please click the 'Accept' text next to the most appropriate reply. This will guide all community members who have a similar question.

Otherwise please post again offering further insight into your question.

Thanks,

AHS

Upvote
Accepted
79.2k 251 52 74

@matthew.french

How did you check the WebScoket connection with the curl command?

The default WebSocket connection TCP port on ADS is 15000, not 14002.

The curl command should look like this:

curl --include --no-buffer --header "Connection: Upgrade" --header "Upgrade: websocket" --header "Sec-WebSocket-Key: SGVsbG8sIHdvcmxkIQ==" --header "Sec-WebSocket-Version: 13" --header "Sec-WebSocket-Protocol: tr_json2" http://127.0.0.1:15000/WebSocket

The output is:

1704773069178.png

If I use the TCP port 14002, I will get the 400 Bad Request.

1704773136729.png


1704773069178.png (38.6 KiB)
1704773136729.png (30.0 KiB)
icon clock
10 |1500

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

Upvotes
17.4k 82 39 63

Hi @matthew.french

If you have code, can you share it here?

I would suggest you look at the explanation/example that discusses how to connect into a deployed ADS using your DACS credentials.

For example:

1704462863736.png


1704462863736.png (75.1 KiB)
icon clock
10 |1500

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

Upvotes
3 0 0 1

Hi,

I had worked through most of the connection examples, but I was mostly trying to use snapshot data and not streaming data which I see is not supported by the RTDS.

Converting my request to streaming data I now have a different problem. My script hangs when I call stream.open() with a 400 Bad Request. Note that any attempt I make to call stream.open() hangs my process because it just keeps retrying, I can't seem to find a way to disable retries.

I have confirmed port 14002 is a valid HTTP service using curl. I'm told ADS version should be ads3.2.1.L1 although this seems a little old. Don't know if that might be part of the problem.

Snippet from the log file:

[2024-01-08T14:32:01.680258+02:00] - [sessions.platform.default.0] - [DEBUG] - [62020 - ThreadOMMSTREAMING_PRICING_0.0] - [stream_connection] - [run] - [OMMSTREAMING_PRICING_0.0] try to reconnect over url ws://<redacted>:14002/WebSocket
[2024-01-08T14:32:01.681259+02:00] - [sessions.platform.default.0] - [DEBUG] - [62020 - ThreadOMMSTREAMING_PRICING_0.0] - [stream_connection] - [run] - [OMMSTREAMING_PRICING_0.0] wait start connecting
[2024-01-08T14:32:01.681259+02:00] - [sessions.platform.default.0] - [DEBUG] - [62020 - ThreadOMMSTREAMING_PRICING_0.0] - [stream_connection] - [run] - [OMMSTREAMING_PRICING_0.0] is connecting
[2024-01-08T14:32:01.681259+02:00] - [sessions.platform.default.0] - [DEBUG] - [62020 - ThreadOMMSTREAMING_PRICING_0.0] - [stream_connection] - [_run_websocket_listener] - [OMMSTREAMING_PRICING_0.0] connect
    num_attempt : 3
    url         : ws://<redacted>:14002/WebSocket
    headers     : ['User-Agent: Python']
    cookies     : None
    transport   : websocket
    subprotocols: ['tr_json2']
[2024-01-08T14:32:02.189103+02:00] - [sessions.platform.default.0] - [ERROR] - [62020 - ThreadOMMSTREAMING_PRICING_0.0] - [stream_connection] - [_on_ws_error] - [OMMSTREAMING_PRICING_0.0] on_ws_error: Exception: Handshake status 400 Bad Request
[2024-01-08T14:32:02.191107+02:00] - [sessions.platform.default.0] - [DEBUG] - [62020 - ThreadOMMSTREAMING_PRICING_0.0] - [stream_connection] - [_on_ws_error] - Traceback (most recent call last):
  File "C:\Program Files\Front\Front Arena\CommonLib\PythonLib397\lib\site-packages\websocket\_app.py", line 395, in setSock
    self.sock.connect(
  File "C:\Program Files\Front\Front Arena\CommonLib\PythonLib397\lib\site-packages\websocket\_core.py", line 253, in connect
    self.handshake_response = handshake(self.sock, url, *addrs, **options)
  File "C:\Program Files\Front\Front Arena\CommonLib\PythonLib397\lib\site-packages\websocket\_handshake.py", line 57, in handshake
    status, resp = _get_resp_headers(sock)
  File "C:\Program Files\Front\Front Arena\CommonLib\PythonLib397\lib\site-packages\websocket\_handshake.py", line 147, in _get_resp_headers
    raise WebSocketBadStatusException("Handshake status %d %s", status, status_message, resp_headers)
websocket._exceptions.WebSocketBadStatusException: Handshake status 400 Bad Request


[2024-01-08T14:32:02.192081+02:00] - [sessions.platform.default.0] - [DEBUG] - [62020 - ThreadOMMSTREAMING_PRICING_0.0] - [stream_connection] - [_on_ws_close] - [OMMSTREAMING_PRICING_0.0] on_ws_close: close_status_code=None, close_msg=None, state=StreamCxnState.Connecting
[2024-01-08T14:32:02.192081+02:00] - [sessions.platform.default.0] - [DEBUG] - [62020 - ThreadOMMSTREAMING_PRICING_0.0] - [stream_connection] - [run] - [OMMSTREAMING_PRICING_0.0] tried all infos, waiting time 60 secs until the next attempt.


Code:

RD_CONFIG = {
    "usage_logger.enabled": True,
    "logs.transports.file.name": r"C:\TEMP\refinitiv-data-lib.log",
    "logs.transports.file.enabled": True,
    "logs.level": "debug",
    "http.auto-retry.number-of-retries": 0,
}


def _fetch_prices():
    from refinitiv.data import get_config
    from refinitiv.data.content import pricing
    from refinitiv.data.session import platform

    config = get_config()
    if config:
        for k, v in RD_CONFIG.items():
            config.set_param(k, v)
        print(f"CONFIG:\n{dumps(config.as_dict(), indent=2)}")

    session = platform.Definition(
        app_key=RTDS_APP_KEY,
        signon_control=False,
        deployed_platform_host=RTDS_HOST,
        deployed_platform_username=RTDS_USER
    ).get_session()

    session.open()
    print(f"Session state: {session.open_state}")
    print("  Getting stream...")
    stream = pricing.Definition(
        ['EUR=', ],
        fields=['BID', 'ASK']
    ).get_stream(session=session)

    print("  Opening stream...")
    stream.open()

    print("DATA:")
    print(stream.get_snapshot())

icon clock
10 |1500

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

Upvotes
3 0 0 1

Thanks. I was not aware the ADS port was different to WebSocket. Turns out WebSocket is not enabled on our RTDS.

Explains why it has been so difficult to get this working.

Still waiting for WebSocket to be enabled but once that is done I think I'll have much more success.

icon clock
10 |1500

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

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

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