For a deeper look into our Elektron API, look into:

Overview |  Quickstart |  Documentation |  Downloads |  Tutorials |  Articles

question

Upvotes
Accepted
24 5 8 11

Websocket python/C# login question

Hello,

There is a json string in the market_price.py example:

login_json = {

'ID': 1,

'Domain': 'Login',

'Key': {

'Name': '',

'Elements': {

'ApplicationId': '256',

'Position': '127.0.0.1'

}

}

}

What should I type in the "name" field?

Also in the Global Default Variables section, there is a "user" variable, what should I type in there?

The Machine ID, AppKey, user, userID, name etc. are very confusing. I don't know which is which because in the websocket/API example, the variable name is never the same as what I see in the welcome email/ App generator page. Is "user" my normal login user email or the machine ID or the AppKey or something else for example. Please help.

python#technologywebsockets.net
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.

Upvote
Accepted
26.3k 60 17 14

Hello @tobywong

I am assuming that you are connecting to the RTO (or Streaming Price Wealth). If so, the C# examples for the cloud connection are available on the https://github.com/Refinitiv/websocket-api/tree/master/Applications/Examples/RDP/CSharp (Applications/Examples/RDP/Charp).

The recommend examples for the Machine-ID type login are

  • MarketPriceRdpGwServiceDiscoveryExample (C#)
  • MarketPriceRdpGwAuthenticationExample (C#)

The examples outside the "RDP" folder are for the local RTDS connection only.

I also highly recommend you check the WebSocket API tutorial: Connect to Refinitiv Real-Time - Optimized which gives you a step-by-step guide about the RTO connection.

### Machine-ID, Username, etc ###

The RTO utilizes the RDP APIs authentication service to obtain Access Token information for authentication process.

The RDP APIs provides two types of credentials for access.

  • Machine ID Type (GE-A-XXXXXXX-X-XXXX): This type is used for the RTO real-time service.
  • User ID: This is an email-based username (example: someone@lseg.com). This type is used for the none-real time service.

The RDP API authentication service needs the following parameters with the HTTP POST request:

  • username: The Machine-ID type username
  • password: Password associated with the Machine-ID
  • client_id: Your App Key
  • grant_type: "password" (for initial authentication) or "refresh_token" (for refreshing the access token)
  • scope: (Optional) Limits the scope of the generated token so that the Access token is valid only for a specific data

    set

  • takeExclusiveSignOnControl: (Optional) If your user credentials permit multiple concurrent sign-on, this parameter invalidates the Refresh token for all previous sign-on when it is set to true.

Example:

POST /auth/oauth2/v1/token HTTP/1.1
Accept: */*
Content-Type: application/x-www-form-urlencoded
Host: api.refinitiv.com:443
Content-Length: XXX
username=GE-A-XXXXXXX
&password=XXXXXXX
&client_id=YYYYYY
&grant_type=password
&takeExclusiveSignOnControl=true
&scope=trapi

### Login ###

The first step of RTO workflow is the application sends the HTTP POST request above to obtain the access token from the RDP APIs.

Once the authentication is successful, the function gets the RDP Auth service response message and keeps the following RDP token information in the variables.

  • access_token: The token used to invoke REST data API calls as described above. The application must keep this credential for further RDP APIs requests.
  • refresh_token: Refresh token to be used for obtaining an updated access token before expiration. The application must keep this credential for access token renewal.
  • expires_in: Access token validity time in seconds.

Then the application establishes a WebSocket connection to the RTO WebSocket server. Once the WebSocket connection is accepted, the application sends a login request message to the RTO WebSocket server via a WebSocket connection as follows:

login_json = {
    'ID': 1,
    'Domain': 'Login',
    'Key': {
        'NameType': 'AuthnToken',
        'Elements': {
            'ApplicationId': '{appid}',
            'Position': '{position}',
            'AuthenticationToken': '{Access Token}'
        }
    }
}

I hope this information helps.



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
24 5 8 11

Thank you for the answer. It helps a lot. Yes, I'm trying to connect to the RTO(cloud). But what is "position", "host", "hostname". and the different between "client_secret" and "password" in the "market_price_rdpgw_authentication.py" example? And how do I get the "AuthenticationToken"?

Currently I'm sending the authentication request with password to https://api.refinitiv.com:443/auth/oauth2/v1/token

And it says "

Refinitiv Data Platform authentication HTTP code: 400 Bad Request" Should I sent the request to some where else? Thank you.

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
24 5 8 11

Also, does the C# examples has to be run using command line? Because eventually I want to build a winform application for my company. Could I put the credential in the code and just run it in Visual studio? thank you.

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.

Hi @tobywong

All examples are a console examples by default. The ParseComandLine() and GripeAboutMissingOptionArgumentAndExit() methods are for checking the command line arguments.

If you need to hardcode the credentials or change to winform, you can modify it based on your preference. The WebSocket API and RTO are not strictly limited to console app.

Let's say I want to run the "market_price_rdpgw_service_discovery" or "market_price_rdpgw_authentication" examples(what is the difference anyways?), can I just type in my credentials in the code(in the appropriate variables) and run it in VS code without modifying the example? I've try it but it says "Refinitiv Data Platform authentication HTTP code: 400 Bad Request". My credential should be valid because I just received the welcome email last week. I just want to try to be able to login successfully and get some data back of one RIC for now, this is step 1 of my development. Thank you so much

  • rdpgw_service_discovery: The application gets the RTO endpoint dynamically
  • rdpgw_service_discovery: You need to input the RTO endpont manually

Question: can I just type in my credentials in the code(in the appropriate variables) and run it in VS code without modifying the example?

Answer: No, you cant. The example code checks if you do not input a required parameter, it exits the application.

If you need to hard code your credentials, you can modify the code to bypass parameters check.

Upvote
26.3k 60 17 14

Hello @tobywong

The "position" is the IP address position of the application logging in. The example application should get this information from your machine programmatically and puts it to JSON for you.

if position == '':
        # Populate position if possible
        try:
            position_host = socket.gethostname()
            position = socket.gethostbyname(position_host) + "/" + position_host
        except socket.gaierror:
            position = "127.0.0.1/net"

The "hostname" is the RTO WebSocket endpoint that you want to connect to.

I highly recommend you try the market_price_rdpgw_service_discovery example that automatically get the list of RTO WebSocket endpoints and connect to the endpoint for you. You do not need to manual set the endpoint URL. To run the market_price_rdpgw_service_discovery, you can use the following command

python market_price_rdpgw_service_discovery --user {Machine-ID} --password {Password} --clientid {App Key} --region {your nearest region} --ric {Item name}

### different between "client_secret" and "password" ###

The Machine-ID type authentication (aka Version 1 authentication) does not use "client_secret", you can leave it as blank.

The password is the Machine-ID password.

### how do I get the "AuthenticationToken"? ###

The application must send the HTTP POST request to the RDP API Auth service to get the Access Token, and then put it in the WebSocket JSON login request message.

However, I do not understand why you need to manual input it. The reason is the market_price_rdpgw_service_discovery.py/market_price_rdpgw_authentication.py already have a code that send an authentication request to RDP and set the access token to the WebSocket for you.

sts_token, refresh_token, expire_time = get_sts_token(None)
...
def get_sts_token(current_refresh_token, url=None):
    """
        Retrieves an authentication token.
        :param current_refresh_token: Refresh token retrieved from a previous authentication, used to retrieve a
        subsequent access token. If not provided (i.e. on the initial authentication), the password is used.
    """
...

### Refinitiv Data Platform authentication HTTP code: 400 Bad Request ###

Did you have a valid Machine-ID, password and RTO permission?

Please try the following cURL command with your credentials and see if it returns any errors.

curl --location --request POST 'https://api.refinitiv.com/auth/oauth2/v1/token' \
--header 'Content-Type: application/x-www-form-urlencoded' \
--header 'Authorization: Bearer ' \
--data-urlencode "username=$Machine-ID" \
--data-urlencode "password=$password" \
--data-urlencode 'grant_type=password' \
--data-urlencode 'scope=trapi' \
--data-urlencode 'takeExclusiveSignOnControl=true' \
--data-urlencode "client_id=$App Key"
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
24 5 8 11

Let's say I want to run the "market_price_rdpgw_service_discovery" or "market_price_rdpgw_authentication" examples(what is the difference anyways?), can I just type in my credentials in the code(in the appropriate variables) and run it in VS code without modifying the example? I've try it but it says "Refinitiv Data Platform authentication HTTP code: 400 Bad Request". My credential should be valid because I just received the welcome email last week. I just want to try to be able to login successfully and get some data back of one RIC for now, this is step 1 of my development. Thank you so much

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.

  • rdpgw_service_discovery: The application gets the RTO endpoint dynamically
  • rdpgw_service_discovery: You need to input the RTO endpont manually

Question: can I just type in my credentials in the code(in the appropriate variables) and run it in VS code without modifying the example?

Answer: No, you cant. The example code checks if you do not input a required parameter, it exits the application.

If you need to hard code your credentials, you can modify the code to bypass parameters check.

Upvote
26.3k 60 17 14

Hello @tobywong

Please be informed that the examples code aim for demonstrating the RTO workflow purpose only. The code is not optimized for the Production use. If you need a different business logic, you need to change or update the code to match your requirement.


About running the RDP C# example with hardcoded credentials, you can just input your credentials in the source code as follows:

charp-1.png

and comment the command line arguments checking:

charp-2.png

Then you can run the example without a command line parameters.

dotnet MarketPriceRdpGwServiceDiscoveryExample_NET6.0.dll 

charp-1.png (173.9 KiB)
charp-2.png (85.9 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.

Result are as follows:

charp-3.png

charp-3.png (110.7 KiB)
Upvote
26.3k 60 17 14

Hi @tobywong

About the "Refinitiv Data Platform authentication HTTP code: 400 Bad Request", can you please try to run the following cURL command to verify your account?

curl --location --request POST 'https://api.refinitiv.com/auth/oauth2/v1/token' \
--header 'Content-Type: application/x-www-form-urlencoded' \
--header 'Authorization: Bearer ' \
--data-urlencode "username=$Machine-ID" \
--data-urlencode "password=$password" \
--data-urlencode 'grant_type=password' \
--data-urlencode 'scope=trapi' \
--data-urlencode 'takeExclusiveSignOnControl=true' \
--data-urlencode "client_id=$App Key"
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
24 5 8 11

This is the output. Please check if I have any typo in the command too. Thank you.

screenshot-2023-07-31-144918.png


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
24 5 8 11

I also try to run the C# "MarketPriceRdpGwAuthenticationExample" example in visual studio, it gives the following error. I hard coded my credential and comment out the parse argument line.

1690787527029.png


1690787527029.png (7.4 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.

Upvote
26.3k 60 17 14

Hello @tobywong

The access denied when calling the RDP APIs Auth service indicates that your credential has a permission issue to access the RDP Auth service to get the access token.

That is why the C# example shows HTTP bad request message.

I strongly suggest you contact your Refinitiv Representative to help you with this permission issue.

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.

I've contacted my Refinitiv Representative. I should be getting an updated credential this week. I will see if I could login, authenticate, get real time data back using the new credential

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.