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.
Best Answer
-
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.
0
Answers
-
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.
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"
}
]0 -
Categories
- All Categories
- 6 AHS
- 37 Alpha
- 161 App Studio
- 4 Block Chain
- 4 Bot Platform
- 16 Connected Risk APIs
- 47 Data Fusion
- 30 Data Model Discovery
- 608 Datastream
- 1.3K DSS
- 577 Eikon COM
- 4.9K Eikon Data APIs
- 7 Electronic Trading
- Generic FIX
- 7 Local Bank Node API
- Trading API
- 2.7K Elektron
- 1.3K EMA
- 236 ETA
- 519 WebSocket API
- 33 FX Venues
- 10 FX Market Data
- 1 FX Post Trade
- 1 FX Trading - Matching
- 12 FX Trading – RFQ Maker
- 5 Intelligent Tagging
- 2 Legal One
- 20 Messenger Bot
- 2 Messenger Side by Side
- 9 ONESOURCE
- 7 Indirect Tax
- 59 Open Calais
- 264 Open PermID
- 39 Entity Search
- 2 Org ID
- PAM
- PAM - Logging
- 8.4K Private Comments
- 6 Product Insight
- Project Tracking
- ProView
- ProView Internal
- 20 RDMS
- 1.4K Refinitiv Data Platform
- 367 Refinitiv Data Platform Libraries
- 3 Refinitiv Due Diligence
- LSEG Due Diligence Portal API
- 3 Refinitiv Due Dilligence Centre
- Rose's Space
- 1.1K Screening
- 18 Qual-ID API
- 13 Screening Deployed
- 23 Screening Online
- 10 World-Check Customer Risk Screener
- 990 World-Check One
- 44 World-Check One Zero Footprint
- 45 Side by Side Integration API
- Test Space
- 3 Thomson One Smart
- 1.2K TR Internal
- Global Hackathon 2015
- 2 Specialists Who Code
- 10 TR Knowledge Graph
- 150 Transactions
- 142 REDI API
- 1.7K TREP APIs
- 4 CAT
- 21 DACS Station
- 117 Open DACS
- 1.1K RFA
- 103 UPA
- 172 TREP Infrastructure
- 224 TRKD
- 886 TRTH
- 5 Velocity Analytics
- 5 Wealth Management Web Services
- 59 Workspace SDK
- 9 Element Framework
- 5 Grid
- 13 World-Check Data File
- Yield Book Analytics
- 46 中文论坛