Quick Start - Connecting to Refinitiv Real-Time - Optimized

 

Last Update October 2021
Environment Windows and Linux OS on either on-premise or any Cloud VMs environment
Compiler Python
Prerequisite Refinitiv Real-Time - Optimized Access Credentials.

The goal of this Quick Start tutorial is to guide you through the initial steps to run the Refinitiv Real-Time - Optimized Websocket API example. The example is written in Python programming language to connect and consume streaming data from Refinitiv 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 Refinitiv Real-time Optimized:

The tutorial is applicable to both Linux and Windows environments.

In this quick start guide, we will cover the following areas:

Prerequisite

The following accounts and software are required in order to run this quick start guide:

  1. Python compiler and runtime
  2. Python's requests library.
  3. Python's websocket-client library (See the version required here ).
  4. Internet connection
  5. Refinitiv Real-Time - Optimized Username/machine ID, password, and client_id access credentials. Please reach out to your Refinitiv representative to acquire Refinitiv Real-Time - Optimized access credentials.

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:

  • The Python example has been qualified with Python versions 2.7.14 and 3.6.7.
  • Please refer to the pip installation guide page if your environment does not have the pip tool installed.
  • If your environment already has a WebSocket-client library installed, you can use the pip list command to verify a library version, then use pip install --upgrade websocket-client command to upgrade the websocket-client library.

How to run the Refinitiv Real-Time - Optimized Python example

You can connect to Refinitiv Real-Time - Optimized service from your existing VM, Cloud VM, or your local machine. The Refinitiv Real-Time - Optimized Quick Start example application is available for download at Refinitiv 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

  • sends the HTTP request to the EDP Gateway with the specified username and password for authentication, 
  • then it receives an access token to send in the HTTP request to Streaming Service Discovery to get an associated Refinitiv Real-Time - Optimized endpoint. 
  • It will then login and consume real-time streaming quote data from the above endpoint using the WebSocket API.

Refinitiv Real-Time - Optimized connection parameters

The required connections parameters for the Refinitiv Real-Time - Optimized example are as follows

  • Username, password, and client_id: To request your access token you must pass in a user name, password, and client_id credentials (or specify it with --user, --password and --client_id parameters on the application command line). 
  • When you subscribe to Refinitiv Real-Time - Optimized, you will receive a Welcome email that provides a link to activate your Machine ID (your username) and create a password.  
  • You must use these credentials to obtain a client_id from an AppKeyGenerator tool. The output of the tool is an AppKey, which is your client_id.

If you do not have that email please contact your Refinitiv representative, or if you are not a client please click Contact Us page if you would like to try Refinitiv 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 Refinitiv RIC Code of your preferred instrument via the RIC Search page

Running the example

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 Refinitiv 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"

  },

  

Troubleshooting

Q: How can I obtain Refinitiv Real-Time - Optimized username, password and client_id?

A: Please contact your Refinitiv representative to help you with Refinitiv 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 Refinitiv representative to help you with Refinitiv Real-Time - Optimized credentials and permission.

Q: I have a Refinitiv Real-Time - Optimized account and the required Python libraries, but the example application fails at the Connecting to WebSocket line

    	
            Connecting to WebSocket wss://<Refinitiv Real-Time - Optimized 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.

Next Steps

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:

References

For further details, please check out the following resources:

For any question related to this quick start guide or Refinitiv Real-Time - Optimized, please use the Developer Community Q&A Forum.