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

Overview |  Quickstart |  Documentation |  Downloads |  Tutorials |  Articles

question

Upvotes
Accepted
5 3 3 6

How to use PHP in establishing websocket connection and set headers?

The client is using PHP and is able to open a WebSocket to the link http://eu-west-1-aws-1-sm.optimized-pricing-api.refinitiv.net:443/ but he asked what information he needs to send to the WebSocket to be able to log in. The installation & Configuration guide says he needs to send the following information:

{ "Domain": "Login",
"ID": 1,
"Key": {
"Elements": {
"ApplicationId": 256,
"Position":"127.0.0.1"
},
"Name":"user"
}
}

It also says in the code there that he has to pass information in the headers when connecting to the Socket. Namely the following info:

- AuthToken

- AuthPosition

- ApplicationId

But he doesn't find any information in the documentation that he must fill in there. Can you please advise? Thank you.


#technologyapiwebsocketsauthenticationsetupphpoauth
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
Accepted
21.9k 58 14 21

Hi @neri.wong01,

For connecting to the RTO cloud, the login credentials have to be sent in the login request message in the following syntax:

{
  "Domain": "Login",
  "ID": 1,
  "Key": {
    "Elements": {
      "ApplicationId": "256",
      "AuthenticationToken": "--- YOUR OAUTH ACCESS TOKEN ---",
      "Position": "--- YOUR MACHINE IP ADDRESS ---"
    },
    "NameType": "AuthnToken"
  }
}


Please have the client try out the python sample and see the message exchange, before proceeding to do this in PHP. It will save them a lot of development time.

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.6k 54 17 14

Hello @neri.wong01

I highly recommend the client check the WebSocket API: Connect to Refinitiv Real-Time - Optimized tutorial page. The source code in the Tutorials is Python but the logic can be applied to any programing language including PHP.

ws-login-1.png

ws-login-2.png

The Tutorial is best for checking and running the code as suggested by my colleague above.

Example:

1. The application gets an authentication token from RDP

Sending authentication request with password to https://api.refinitiv.com:443/auth/oauth2/v1/token ...
Refinitiv Data Platform Authentication succeeded. RECEIVED:
{
  "access_token":"XXXXXXXXx",
  "expires_in":"600",
  "refresh_token":"YYYYYYYYy",
  "scope":"trapi.streaming.pricing.read",
  "token_type":"Bearer"
}

2. The application gets a list of RTO WebSocket endpoints

3. The application establishes a connection with one of the endpoint

4. On success, the application sends a JSON login request message to the WebSocket endpoint with the token from step (1)

Connecting to WebSocket wss://us-east-1-aws-3-lrg.optimized-pricing-api.refinitiv.net:443/WebSocket for session1...
WebSocket successfully connected for session1!
SENT on session1:
{
  "Domain":"Login",
  "ID":1,
  "Key":{
    "Elements":{
      "ApplicationId":"256",
      "AuthenticationToken":"XXXXXXXXx",
      "Position":"10.42.61.2XX/WINDOWS-ABCEFGH"
    },
    "NameType":"AuthnToken"
  }
}

4. Login success: The application gets the Login refresh response message via on_message callback.

RECEIVED on session1:
[
  {
    "Domain":"Login",
    "Elements":{
      "MaxMsgSize":61516,
      "PingTimeout":30
    },
    "ID":1,
    "Key":{
      "Elements":{
        "AllowSuspectData":1,
        "ApplicationId":"256",
        "ApplicationName":"RTO",
        "AuthenticationErrorCode":0,
        "AuthenticationErrorText":{
          "Data":null,
          "Type":"AsciiString"
        },
        "AuthenticationTTReissue":1680507565,
        "Position":"10.42.61.2XX/WINDOWS-ABCEFGH",
        "ProvidePermissionExpressions":1,
        "ProvidePermissionProfile":0,
        "SingleOpen":1,
        "SupportBatchRequests":7,
        "SupportEnhancedSymbolList":1,
        "SupportOMMPost":1,
        "SupportOptimizedPauseResume":0,
        "SupportPauseResume":0,
        "SupportStandby":1,
        "SupportStandbyMode":3,
        "SupportViewRequests":1
      },
      "Name":"AAAABBBCCCDDEEE"
    },
    "State":{
      "Data":"Ok",
      "Stream":"Open",
      "Text":"Login accepted by host ads-fanout-lrg-az1-use1-prd."
    },
    "Type":"Refresh"
  }
]

ws-login-1.png (50.3 KiB)
ws-login-2.png (27.8 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
5 3 3 6

@Gurpreet and @wasin.w ,

Thank you and I will share the same information to the client.

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.