Last Update | June 2024 |
Environment | Windows and Linux OS on either on-premise or any Cloud VMs environment |
Compiler | Python |
Prerequisite | Real-Time - Optimized Access Credentials. |
Important Note:
The goal of this Quick Start tutorial is to guide you through the initial steps to run the Real-Time - Optimized (RTO) with the Authentication Version 1 (Machine ID) Websocket API example. The example is written in Python programming language to connect and consume streaming data from Real-Time - Optimized, via a WebSocket API connection over the internet.
Following video shows a sequence of events required to connect and get data from the RTO:
The tutorial is applicable to both Linux and Windows environments.
The following accounts and software are required in order to run this quick start guide:
You need to install examples required libraries via the pip install command in your environment before running the example:
$>pip install requests websocket-client
Note:
You can connect to Real-Time - Optimized service from your existing VM, Cloud VM, or your local machine. The Real-Time - Optimized Quick Start example application is available for download at LSEG Developer Community: WebSocket API download page or Refinitiv/websocket-api: GitHub page. The Quick Start example package contains the WebSocket API examples for Python, Java, and C# languages.
This Quick Start is focusing on Python's market_price_rdpgw_service_discovery.py application. The market_price_rdpgw_service_discovery.py file is an example Python application that
The required connections parameters for the Real-Time - Optimized example are as follows
If you do not have that email please contact your LSEG representative, or if you are not a client please click Contact Us page if you would like to try Real-Time data.
The application subscribes TRI.N RIC code from the service by default. You can pass your preferred RIC code instead using the --ric parameter on the example command line. You can find a the RIC Code of your preferred instrument via the RIC Search page
You can run market_price_rdpgw_service_discovery.py application with the following command
$>python market_price_rdpgw_service_discovery.py --user <Machine-ID> --password <Password> --clientid <client_id/AppKey>
The other optional parameters are explained in the README.md file.
Upon execution, the example will output authentication information and the results of the Service endpoint discovery, followed by the initial WebSocket connection between the application and Real-Time - Optimized.
$>python market_price_rdpgw_service_discovery.py --user user1 --password password1 --clientid AppKey..
Sending authentication request with password to https://api.refinitiv.com:443/auth/oauth2/v1/token ...
Refinitiv Data Platform Authentication succeeded. RECEIVED:
{
"access_token":"<Access Token>",
"expires_in":"600",
"refresh_token":"<Refresh Token>",
"scope":"<Your Scope>",
"token_type":"Bearer"
}
Sending Refinitiv Data Platform service discovery request to https://api.refinitiv.com/streaming/pricing/v1/
Refinitiv Data Platform Service discovery succeeded. RECEIVED:
{
"services":[
{
"dataFormat":[
"tr_json2"
],
"endpoint":"ap-southeast-1-aws-1-lrg.optimized-pricing-api.refinitiv.net",
"location":[
"ap-southeast-1a"
],
"port":443,
"provider":"aws",
"transport":"websocket"
},
...
{
"dataFormat":[
"tr_json2"
],
"endpoint":"eu-west-1-aws-3-lrg.optimized-pricing-api.refinitiv.net",
"location":[
"eu-west-1a",
"eu-west-1b"
],
"port":443,
"provider":"aws",
"transport":"websocket"
},
...
{
"dataFormat":[
"tr_json2"
],
"endpoint":"us-east-2-aws-3-lrg.optimized-pricing-api.refinitiv.net",
"location":[
"us-east-2a",
"us-east-2b"
],
"port":443,
"provider":"aws",
"transport":"websocket"
},
]
}
Connecting to WebSocket wss://us-east-2-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":"<Access Token>",
"Position":"<IP/Local Machine Name>"
},
"NameType":"AuthnToken"
}
}
RECEIVED on session1:
[
{
"Domain":"Login",
"Elements":{
"MaxMsgSize":61426,
"PingTimeout":30
},
"ID":1,
"Key":{
"Elements":{
"AllowSuspectData":1,
"ApplicationId":"256",
"ApplicationName":"ADS",
"AuthenticationErrorCode":0,
"AuthenticationErrorText":{
"Data":null,
"Type":"AsciiString"
},
"AuthenticationTTReissue":1633530590,
"Position":"172.31.48.1/latitude5511",
"ProvidePermissionExpressions":1,
"ProvidePermissionProfile":0,
"SingleOpen":1,
"SupportBatchRequests":7,
"SupportEnhancedSymbolList":1,
"SupportOMMPost":1,
"SupportOptimizedPauseResume":0,
"SupportPauseResume":0,
"SupportStandby":0,
"SupportViewRequests":1
},
"Name":"AQIC5wM2LY4SfczsgaoIJWYF3RxaW8fJ8jxFqIrF0b9y3Vo%3D%40AAJTSQACNDAAAlNLABI1ODA5NjQ0ODAzMDE4MjUxMDkAAlMxAAIzNg%3D%3D%23"
},
"State":{
"Data":"Ok",
"Stream":"Open",
"Text":"Login accepted by host ads-fanout-lrg-az1-use2-prd."
},
"Type":"Refresh"
}
]
The application will receive an initial image called a RefreshMsg. The RefreshMsg or initial image contains all fields for the requested instrument representing the latest up-to-date market values. Following this image, you will begin to see UpdateMsgs or realtime updates reflecting changes in the market. All messages between the application and ERT in Cloud are in JSON format, you can find more detail regarding the WebSocket API's JSON message format in the WebSocket API Try it Now! Documentation.
You can (Ctrl+C) to exit the application at any time.
SENT on session1:
{
"ID":2,
"Key":{
"Name":"AAPL.O",
"Service":"ELEKTRON_DD"
}
}
RECEIVED on session1:
[
{
"Fields":{
"52WK_HIGH":157.26,
"52WK_LOW":107.32,
"52W_HDAT":"2021-09-07",
"DSPLY_NAME":"APPLE INC",
"52W_HIND":null,
"52W_LDAT":"2020-11-02",
"52W_LIND":null,
"ACVOL_1":21138087,
"ACVOL_AFT":null,
"ACVOL_PRE":1497597,
"ACVOL_UNS":21138087,
"AC_TRN_CRS":88144391.24,
"AC_VOL_CRS":632222,
"ADJUST_CLS":141.11,
"AFTMKT_DT":"2021-10-05",
...
"VWAP":139.3343,
"VWAP_FLAG":null,
"VWAP_VOL":19429174,
"XMIC_CODE":"XNAS",
"YCHIGH_IND":null,
"YCLOW_IND":null,
"YIELD":0.6236,
"YRHIGH":157.26,
"YRHIGHDAT":"2021-09-07",
"YRHI_IND":"Yr.High ",
"YRLOW":107.32,
"YRLOWDAT":"2020-11-02",
"YRLO_IND":"Yr.Low "
},
"ID":2,
"Key":{
"Name":"AAPL.O",
"Service":"ELEKTRON_DD"
},
"PermData":"AwEBdMA=",
"Qos":{
"Rate":"JitConflated",
"Timeliness":"Realtime"
},
"SeqNumber":50190,
"State":{
"Data":"Ok",
"Stream":"Open"
},
"Type":"Refresh"
}
]
RECEIVED on session1:
[
{
"Fields":{
"ASK":139.34,
"ASKSIZE":4,
"ASKXID":"IEX",
"ASK_COND_N":"R",
"ASK_MMID1":"IEX",
"BID":139.33,
"BIDFINMMID":null,
"BIDSIZE":3,
"BIDXID":"BAT",
"BID_COND_N":"R",
...
"QUOTIM":"14:19:52",
"QUOTIM_MS":51592467,
"SEQNUM_QT":22859040
},
"ID":2,
"Key":{
"Name":"AAPL.O",
"Service":"ELEKTRON_DD"
},
"SeqNumber":50336,
"Type":"Update",
"UpdateType":"Quote"
},
Q: How can I obtain Real-Time - Optimized username, password and client_id?
A: Please contact your LSEG representative to help you with Real-Time - Optimized credentials.
Q: I have tried to use the App Key Generator page to create my client_id but page keeps asking me Eikon's email username
A: Please contact your LSEG representative to help you with Real-Time - Optimized credentials and permission.
Q: I have a Real-Time - Optimized account and the required Python libraries, but the example application fails at the Connecting to WebSocket line
Connecting to WebSocket wss://<RTO - URL> for session1...
A: Please verify your Python and websocket-client versions. The Python examples have been qualified with Python versions 2.7.14, 3.6.7, and the websocket-client library version 0.49 or greater. You can use python --version and pip list commands to verify the Python and libraries versions in your environment.
Once you have successfully completed the steps above, you can further your learning by following the series of WebSocket API tutorials on this Developer Community website.
Note: If there are plans to run your WebSocket applications within the Amazon Cloud, you can refer to the Setting Up an Amazon EC2 instance article for further details or watch the video version of the article:
For further details, please check out the following resources:
For any question related to this quick start guide or Real-Time - Optimized, please use the Developer Community Q&A Forum.