Skip to content
Permalink
Branch: master
Find file Copy path
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
268 lines (244 sloc) 14.4 KB

Elektron in Cloud WebSocket example with Node.js and TypeScript

Table of Content

Overview

Elektron Data Platform (EDP) gives you seamless and holistic access to all of Refinitiv content (whether real-time or non- real-time, analytics or alternative datasets), commingled with your own content, enriching, integrating and distributing the data through a single interface, delivered wherever you need it.

As part of the Elektron Data Platform, Elektron Real Time in Cloud (ERT in Cloud) gives you access to best in class Real Time market data delivered in the cloud. ERT in Cloud is a new delivery mechanism for EDP, using the AWS (Amazon Web Services) cloud. Once a connection to EDP is established using ERT in Cloud, data can be retrieved using Elektron WebSocket API.

This example shows how to implement the ERT in Cloud Node.js application with TypeScript language. The application source codes are implemented in TypeScript language to connect, consuming EDP straming market data through ERT in Cloud. All source codes will be compiled to readable JavaScript file with Webpack JavaScript module bundler. The example functionalities are based on ERT in Cloud market_price_edpgw_service_discovery.py Python example.

connection diagram

TypeScript Overview

TypeScript is an open-source programming language developed and maintained by Microsoft. The language lead architect is Anders Hejlsberg, lead architect of C# and creator of Delphi and Turbo Pascal. TypeScript is a typed superset of JavaScript that compiles to readable, standards-based JavaScript. The syntax is designed for application-scale JavaScript by adding optional types, classes, modules, ECMAScript 2015 features and future proposals to JavaScript. TypeScript supports tools for large-scale JavaScript applications for any browser, for any host, on any OS. TypeScript is as a first-class programming language in Microsoft Visual Studio and Angular web application platform. It also supported by various application frameworks like React, NodeJS and Express framework, ASP.Net Core, Vue.js and more.

Prerequisite

This example requires the following dependencies softwares.

  1. Node.js runtime - version 11.4.0 or higher.
  2. npm package manager (included in Node.js)
  3. TypeScript compiler (will be installed via npm install command)
  4. Express.js web framework (will be installed via npm install command)
  5. Webpack JavaScript module bundler (will be installed via npm install command)
  6. Access to the Refinitiv Elektron Data Platform and Elektron Real Time in Cloud.

Please contact your Refinitiv's Technical Account Manager or Technical Relationship Manager to help you to access EDP account and services. You will receive your Machine ID as a user name and a link to activate your machine account and set your password via the Welcome Email that you receive when you subscribe to ERT in Cloud.

Connecting to the API from Amazon AWS

For Production and QA Testing purposes, Elektron Real Time in Cloud (ERT in Cloud) supports Amazon EC2 instance customers only. However, customers can use any environments (VM, Cloud VM, local machine) for Development purpose.

Refinitiv will not support Production and QA/Testing customers outside of Amazon EC2 service until further notice.

ERT in Cloud connection parameters

User name and Password: To request your access token and steaming data, you must pass in a user name and password (or specify it with --user and --password parameters on the application command line). You will receive your Machine ID as a user name and a link to activate your machine account and set your password via the Welcome Email that you receive when you subscribe to ERT in Cloud. If you do not have that email please contact your Refinitiv account team, or if you are not a client please click Contact Us page if you would like to try Elektron Real Time data.

Optionally, the application subscribes EUR= RIC code from ERT in Cloud by default. You can pass your interested RIC code to --ric parameter on the application command line. You can find Refinitiv RIC Code of your interested instrument via RIC Search page

How to run the application

  1. Unzip or download the example project folder into a directory of your choice
  2. Run $> npm install command in the command prompt to install all the dependencies required to run the sample in a subdirectory called node_modules/.
  3. If the machine is behind a proxy server, you need to configure Node.js uses proxy instead of a direct HTTP connection via the following command in command prompt:
    set https_proxy=http://<proxy.server>:<port>
    
  4. Run $> npx webpack command in the command prompt to build and compile all TypeScript files in src folder into JavaScript file in ./dist/ folder
  5. In a command prompt, go to ./dist/ folder and run market_price_edpgw_service_discovery.js Node.js application with the following command
    $> node market_price_edpgw_service_discovery.js --user <Your ERT in Cloud username> --password <Your ERT in Cloud password> --ric <Interested RIC code>
    
  6. Upon execution, you will be presented with authentication and ERT in Cloud Service discovery processes via EDP Gateway REST API, then followed by initial WebSocket connection between the application and ERT in Cloud.
    Sending authentication request with password to https://api.edp.thomsonreuters.com:443/auth/oauth2/beta1/token
    HTTP Request: EDP-GW Authentication success
    EDP-GW Authentication succeeded. RECEIVED: {
    "access_token": "<Access Token>",
    "refresh_token": "<Refresh Token>",
    "expires_in": "300",
    "scope": "trapi.streaming.pricing.read",
    "token_type": "Bearer"
    }
    Sending EDP-GW service discovery request to https://api.edp.thomsonreuters.com/streaming/pricing/v1/
    HTTP Request: EDP-GW service discovery success
    EDP-GW Service discovery succeeded. RECEIVED: {
    "services": [
        {
        "port": 443,
        "location": [
            "us-east-1a",
            "us-east-1b"
        ],
        "provider": "aws",
        "transport": "websocket",
        "endpoint": "amer-3.pricing.streaming.edp.thomsonreuters.com",
        "dataFormat": [
            "tr_json2"
        ]
        },
        {
        "port": 443,
        "location": [
            "us-east-1b"
        ],
        "provider": "aws",
        "transport": "websocket",
        "endpoint": "amer-2.pricing.streaming.edp.thomsonreuters.com",
        "dataFormat": [
            "tr_json2"
        ]
        },
        {
        "port": 443,
        "location": [
            "us-east-1a"
        ],
        "provider": "aws",
        "transport": "websocket",
        "endpoint": "amer-1.pricing.streaming.edp.thomsonreuters.com",
        "dataFormat": [
            "tr_json2"
        ]
        }
    ]
    }
    Receive EDP-RT Service Endpoint and Port, init Elektron WebSocket connection for session 1
    session1 ws_connect to wss://amer-3.pricing.streaming.edp.thomsonreuters.com:443/WebSocket
    WebSocket successfully connected for session1, sedning login request message
    Sent on session1:
    {
    "ID": 1,
    "Domain": "Login",
    "Key": {
        "NameType": "AuthnToken",
        "Elements": {
        "ApplicationId": "256",
        "Position": "10.42.68.162",
        "AuthenticationToken": "<Access Token>"
        }
    }
    }
    Receive Login Refresh Message on session1: {
    "ID": 1,
    "Type": "Refresh",
    "Domain": "Login",
    "Key": {
        "Name": "<Name>",
        "Elements": {
        "AllowSuspectData": 1,
        "ApplicationId": "256",
        "ApplicationName": "ADS",
        "AuthenticationErrorCode": 0,
        "AuthenticationErrorText": {
            "Type": "AsciiString",
            "Data": null
        },
        "AuthenticationTTReissue": 1541069071,
        "Position": "10.42.68.162",
        "ProvidePermissionExpressions": 1,
        "ProvidePermissionProfile": 0,
        "SingleOpen": 1,
        "SupportEnhancedSymbolList": 1,
        "SupportOMMPost": 1,
        "SupportPauseResume": 0,
        "SupportStandby": 0,
        "SupportBatchRequests": 7,
        "SupportViewRequests": 1,
        "SupportOptimizedPauseResume": 0
        }
    },
    "State": {
        "Stream": "Open",
        "Data": "Ok",
        "Text": "Login accepted by host ads-premium-az2-green-4-main-prd.use1-az2."
    },
    "Elements": {
        "PingTimeout": 30,
        "MaxMsgSize": 61430
    }
    }
    
  7. Then 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 Elektron WebSocket API's JSON message format in WebSocket API Developer Guide link.
    Sending Market Price request on session1 for /EUR= item
    Sent on session1:
    {
    "ID": 2,
    "Key": {
        "Name": "/EUR="
    }
    }
    Receive Market Price Refresh Message on session1: {
    "ID": 2,
    "Type": "Refresh",
    "Key": {
        "Service": "ELEKTRON_DD",
        "Name": "/EUR="
    },
    "State": {
        "Stream": "Open",
        "Data": "Ok",
        "Text": "*All is well"
    },
    "Qos": {
        "Timeliness": "Realtime",
        "Rate": "JitConflated"
    },
    "PermData": "AwEBITw=",
    "SeqNumber": 20846,
    "Fields": {
        "PROD_PERM": 213,
        "RDNDISPLAY": 153,
        "DSPLY_NAME": "INTERPROMBAN MOW",
        "TIMACT": "10:39:00",
        "NETCHNG_1": 0.0062,
        "HIGH_1": 1.1388,
        "LOW_1": 1.1308,
        "CURRENCY": "USD",
        "ACTIV_DATE": "2018-11-01",
        "OPEN_PRC": 1.1309,
        "HST_CLOSE": 1.131,
        "BID": 1.1372,
        "BID_1": 1.1371,
        "BID_2": 1.1373,
        "ASK": 1.1374,
        "ASK_1": 1.1375,
        ...
        "BIDLO5_MS": null,
        "MIDHI1_MS": "09:03:53.395",
        "MIDLO1_MS": "21:01:01.479",
        "BID_HR_MS": "10:00:01.078"
    }
    }
    
    Receive Update Message on session1: {
    "ID": 2,
    "Type": "Update",
    "UpdateType": "Unspecified",
    "DoNotConflate": true,
    "Key": {
        "Service": "ELEKTRON_DD",
        "Name": "/EUR="
    },
    "SeqNumber": 20894,
    "Fields": {
        "PCTCHG_3M": -2.44,
        "PCTCHG_6M": -4.83,
        "PCTCHG_MTD": 0.56,
        "PCTCHG_YTD": -5.19
    }
    }
    
  8. You can (Ctrl+C) to exit the application at any time.

All Commandline Option Descriptions:

  • --user <REQUIRED> Username to use when authenticating via Username/Password to the Gateway.
  • --password <REQUIRED> Password to use when authenticating via Username/Password to the Gateway.
  • --hotstandby <OPTIONAL> Specifies the hotstandby mechanism to create two connections and subscribe identical items for service resiliency.
  • --auth_hostname <OPTIONAL> Hostname of the EDP Gateway.
  • --auth_port <OPTIONAL> Port of the EDP Gateway. Defaults to 443
  • --scope <OPTIONAL> An authorization scope to include when authenticating. Defaults to 'trapi'
  • --ric <OPTIONAL> Name of the item to request from the Elektron Real-Time Service. If not specified, /EUR= is requested.
  • --app_id <OPTIONAL> Application ID to use when logging in. If not specified, "256" is used.
  • --position <OPTIONAL> Position to use when logging in. If not specified, the current host is used.

References

For further details, please check out the following resources:

For any question related to this article or EDP/ERT in Cloud API, please use the Developer Community Q&A Forum.

You can’t perform that action at this time.