Ariticle

Introduction to the Refinitiv Real-Time WebSocket Docker Image

Author:

Jirapongse Phuriphanvichai
Developer Advocate Developer Advocate

Refinitiv provides several methods for users to consume real-time streaming financial data from Refinitiv Real-time servers. Users can choose from low-level and high-performance APIs to high-level and easy-to-use WebSocket APIs. 

The Refinitiv Real-Time SDKs are suites of modern and open source APIs that are designed to simplify development through a strong focus on ease of use and standardized access to a broad set of Refinitiv and proprietary content and services. They currently support C, C++, and Java programming languages and can be run on several operating systems including Windows, Oracle Linux, Red Hat Enterprise Linux, and CentOS.

Besides Refinitiv Real-Time SDKs, Refinitiv also provides a WebSocket solution for other developers who are not familiar with C, C++, and Java programming languages. The WebSocket API consists of a protocol specification and a set of sample programs used to illustrate the usage of the protocol to establish WebSocket connections to Refinitiv Real-Time Distribution Systems, or Refinitiv Real-Time - Optimized (cloud solution) available via Refinitiv Data Platform (RDP).

This article demonstrates how to use the Refinitiv WebSocket API on the Docker platform. It has three sections including:

  • Refinitiv APIs docker images on the Docker Hub
  • Deploying the Refinitiv WebSocket API docker image
  • Running Python examples in the docker container 

Refinitiv APIs docker images

The examples of Refinitiv WebSocket API and the source code of the Refinitiv Real-Time SDKs are available on Github (C/C++, Java, and WebSocket API). Steps to build the Refinitiv Real-Time SDK libraries and run the examples are also mentioned on GitHub.

Fortunately, the Refinitiv Real-Time SDK Docker images are now available in Docker Hub, as shown below.

  • refinitivapis/websocket_api: This docker image contains WebSocket API Examples used to connect to Refinitiv Real-Time Distribution System or Refinitiv Data Platform to consume real-time data through the WebSocket connections. There are examples of various programming languages such as CSharp, Java, Python, Go, Ruby, Node, Perl, and R. The image uses Oracle Linux 8 as a base image and it installs Python 3.9 used to run Python WebSocket API examples.
  • refinitivapis/realtimesdk_c: This docker image contains the latest version of Refinitiv Real-Time SDK C/C++ libraries and examples. The image is rebuilt when the new version of Refinitiv Real-Time SDK is available in GitHub. It uses Oracle Linux 7 as a based image and the GCC version is 4.8.5.
  • refinitivapis/realtimesdk_java: This docker image contains the latest version of Refinitiv Real-Time SDK Java libraries and examples. The image is rebuilt when the new version of Refinitiv Real-Time SDK is available in GitHub. It uses Oracle Linux 7 as a based image and the Oracle OpenJDK version is 11.

This article only focuses on the refinitivapis/websocket_api docker image. This Docker image contains only the Python runtime and dependencies required to run the Python examples. If you need to run other examples in different programming languages, you need to manually install other compilers and dependencies. 

In the next section, I will demonstrate how to deploy the refinitivapis/websocket_api image on Docker engines and Azure Containers.

Deploying the Refinitiv Real-Time WebSocket API docker image

The docker images can be run as docker containers on local machines or cloud platforms. To follow the steps in this section, the docker engine must be installed on a local machine or an Azure account is ready to be used.

Deploying the Refinitiv Real-Time WebSocket API docker image on a local machine

First, the docker engine must be installed and run properly on the machine. The "docker version" command can be used to verify the docker engine.

    	
            

PS C:\> docker version

Client:

 Cloud integration: v1.0.22

 Version:           20.10.12

 API version:       1.41

 Go version:        go1.16.12

 Git commit:        e91ed57

 Built:             Mon Dec 13 11:44:07 2021

 OS/Arch:           windows/amd64

 Context:           default

 Experimental:      true

Server: Docker Engine - Community

 Engine:

  Version:          20.10.12

  API version:      1.41 (minimum version 1.12)

  Go version:       go1.16.12

  Git commit:       459d0df

  Built:            Mon Dec 13 11:43:56 2021

  OS/Arch:          linux/amd64

  Experimental:     false

 containerd:

  Version:          1.4.12

  GitCommit:        7b11cfaabd73bb80907dd23182b9347b4245eb5d

 runc:

  Version:          1.0.2

  GitCommit:        v1.0.2-0-g52b36a2

 docker-init:

  Version:          0.19.0

  GitCommit:        de40ad0

When the docker engine is started, run the "docker pull refinitivapis/websocket_api" command to pull the latest Refinitiv Real-Time WebSocket docker image from the Docker Hub.

    	
            

PS C:\> docker pull refinitivapis/websocket_api

Using default tag: latest

latest: Pulling from refinitivapis/websocket_api

671f9b4a2df1: Already exists

55f54a4c7507: Already exists

4f4fb700ef54: Already exists

Digest: sha256:23fababa66766f6c928408ccc8bdb1b2e85608bd43b1da32e38751ae7421ac0f

Status: Downloaded newer image for refinitivapis/websocket_api:latest

docker.io/refinitivapis/websocket_api:latest

Then, the "docker images" command can be used to verify that the Refinitiv Real-Time WebSocket API docker image is available on the machine.

    	
            

PS C:\> docker images

REPOSITORY                                  TAG            IMAGE ID       CREATED         SIZE

refinitivapis/websocket_api                 latest         c9bd8bddaf15   4 days ago      541MB

The output of the "docker images" command must contain the refinitivapis/websocket_api repository.

A Docker image can be run inside a container. The "docker run" command creates a new running container instance of the docker image. Run the following command to create a container instance of the Refinitiv Real-Time WebSocket API docker image.

    	
            

PS C:\> docker run -it --name websocket  refinitivapis/websocket_api

sh-4.4# ls

README.md  market_price_rdpgw_authentication.py  market_price_rdpgw_service_discovery.py

sh-4.4# pwd

/opt/refinitiv/websocket-api/Applications/Examples/RDP/python

sh-4.4#

After running this command, you can access a Linux shell in the container. Then, you can run the Refinitiv Real-Time WebSocket examples in the container. The default directory of the container is the /opt/refinitiv/websocket-api/Applications/Examples/RDP/python directory which contains Python examples to connect to Refinitiv Real-Time Optimized and you can find other examples in the /opt/refinitiv/websocket-api/Applications/Examples directory. 

Deploying the Refinitiv WebSocket API docker image on Azure

Instead of running docker containers on the local machine, you can run the Refinitiv WebSocket API docker container on Azure Container Instances. Azure Container Instances are used to create and manage Docker containers in Azure without having to set up virtual machines or manage additional infrastructure.

First, log in to Azure and then create a new Container Instances resource.

On the Create container instance page, fill in all required information. Select Docker Hub or other registry for the Image source and enter refinitivapis/websocket_api for the Image. Then, click on the Next: Networking button.

On the Networking tab, keep the default setting. Then click on the Next: Advanced button.

On the Advanced tab, enter [ "/bin/bash", "-c", "echo hello; sleep 60m" ] for the Command override. This command will keep the container running for 60 minutes before exiting. You can use another command or change the sleep time to keep the container running. Then, click on Review + create button.

Next, review the information and then click on the Create button to create a container instance.

Wait for the deployment process to be completed.

After the deployment is complete, click on the created resource (websocketapi).

On the overview page, verify that the status of the container is Running.

Then, select Containers under Settings, click on the Connect tab, choose the shell to be used, and then click on the Connect button.

Now, you can access a bash shell in the container.

Running examples in the container

This section demonstrates how to run Python examples in the container to consume real-time data from Refinitiv Real-Time - Optimized. The Python examples are in the /opt/refinitiv/websocket-api/Applications/Examples/RDP/python directory.

To connect to Refinitiv Real-Time - Optimized, the following information is required.

  1. UserID/MachineID
  2. Password
  3. AppKey (Client ID)

For more information, please refer to the Getting Start with Refinitiv Data Platform article.

There are two Python examples in the /opt/refinitiv/websocket-api/Applications/Examples/RDP/python directory. The purpose of these examples is to connect to the Refinitiv Real-Time Optimized and retrieve JSON-formatted market content over a WebSocket connection.

These applications are intended as basic usage examples. Some of the design choices were made to favor simplicity and readability over performance. These applications are not intended to be used for measuring performance. The examples are available on GitHub.

Running the market_price_rdpgw_service_discovery.py example

This example retrieves market-price content for a RIC after authenticating with an authentication server and uses tokens sent by that server to keep the connection alive. This example discovers the endpoint information using a service discovery URL using a region supplied as input. The content is retrieved using this endpoint information. This example maintains a session by proactively renewing the authentication token before expiration.

Run the example with the following parameters:

    	
            sh-4.4# python3 market_price_rdpgw_service_discovery.py  --user <UserID/MachineID> --password '<password>' --clientid <ClientID>
        
        
    

The output is:

    	
            

Sending authentication request with password to https://api.refinitiv.com:443/auth/oauth2/v1/token ...

Refinitiv Data Platform Authentication succeeded. RECEIVED:

{

  "access_token":"eyJ0eXA...",

  "expires_in":"600",

  "refresh_token":"…",

  "scope":"trapi.streaming.pricing.read",

  "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":"ap-southeast-1-aws-3-lrg.optimized-pricing-api.refinitiv.net",

      "location":[

        "ap-southeast-1a",

        "ap-southeast-1b"

      ],

      "port":443,

      "provider":"aws",

      "transport":"websocket"

    },...

  ]

}

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":"eyJ0e...",

      "Position":"172.17.0.2/e684c482a0d1"

    },

    "NameType":"AuthnToken"

  }

}

RECEIVED on session1:

[

  {

    "Domain":"Login",

    "Elements":{

      "MaxMsgSize":61426,

      "PingTimeout":30

    },

    "ID":1,

    "Key":{

      "Elements":{

        "AllowSuspectData":1,

        "ApplicationId":"256",

        "ApplicationName":"RTO",

        "AuthenticationErrorCode":0,

        "AuthenticationErrorText":{

          "Data":null,

          "Type":"AsciiString"

        },

        "AuthenticationTTReissue":1644472207,

        "Position":"172.17.0.2/e684c482a0d1",

        "ProvidePermissionExpressions":1,

        "ProvidePermissionProfile":0,

        "SingleOpen":1,

        "SupportBatchRequests":7,

        "SupportEnhancedSymbolList":1,

        "SupportOMMPost":1,

        "SupportOptimizedPauseResume":0,

        "SupportPauseResume":0,

        "SupportStandby":0,

        "SupportViewRequests":1

      },

      "Name":"..."

    },

    "State":{

      "Data":"Ok",

      "Stream":"Open",

      "Text":"Login accepted by host ads-fanout-lrg-az1-use1-prd."

    },

    "Type":"Refresh"

  }

]

SENT on session1:

{

  "ID":2,

  "Key":{

    "Name":"/TRI.N",

    "Service":"ELEKTRON_DD"

  }

}

RECEIVED on session1:

[

  {

    "Fields":{

      "52WK_HIGH":123.59,

      "52WK_LOW":80.16,

      "52W_HDAT":"2021-11-19",

      "52W_HIND":null,

      "52W_LDAT":"2021-02-22",

      "52W_LIND":null,

      "ACVOL_1":191271,

      "ACVOL_UNS":191271,

      "AC_TRN_CRS":null,

      "AC_VOL_CRS":0,

      "ADJUST_CLS":105.24,

      "AFTMKT_DT":null,

      "AFTMKT_NS":null,

      "AFTMKT_PRC":null,

      "AFTMKT_VOL":null,

      "ASK":0.0,

      "ASKSIZE":0,

      "ASK_1":105.24,

      "ASK_2":105.24,

      "ASK_COND_N":"R",

      "ASK_MMID1":null,

….

Running the market_price_rdpgw_authentication.py example

This example retrieves market-price content for a RIC after authenticating with an authentication server and uses tokens sent by that server to keep the connection alive. The content is retrieved using endpoint information (host and port) supplied as input. This example maintains a session by proactively renewing the authentication token before expiration.

Run the example with the following parameters:

    	
            sh-4.4# python3 market_price_rdpgw_ authentication.py  --user <UserID or MachineID> --password '<password>' --clientid <ClientID> --hostname <hostname>
        
        
    

The <hostname> could be ap-southeast-1-aws-1-lrg.optimized-pricing-api.refinitiv.net. You can find the Refinitiv Real-Time Optimized hostname lists from the Refinitiv Real-Time - Optimized New Hostnames August 2021 link or the RDP Service Discovery endpoint.

The output is:

    	
            

Sending authentication request with password to https://api.refinitiv.com:443/auth/oauth2/v1/token ...

Refinitiv Data Platform Authentication succeeded. RECEIVED:

{

  "access_token":"eyJ0eXA… ",

  "expires_in":"600",

  "refresh_token":"…",

  "scope":"trapi.streaming.pricing.read",

  "token_type":"Bearer"

}

Connecting to WebSocket wss://ap-southeast-1-aws-1-lrg.optimized-pricing-api.refinitiv.net:443/WebSocket ...

WebSocket successfully connected!

SENT:

{

  "Domain":"Login",

  "ID":1,

  "Key":{

    "Elements":{

      "ApplicationId":"256",

      "AuthenticationToken":"eyJ0eX…",

      "Position":"172.17.0.2/e684c482a0d1"

    },

    "NameType":"AuthnToken"

  }

}

RECEIVED:

[

  {

    "Domain":"Login",

    "Elements":{

      "MaxMsgSize":61426,

      "PingTimeout":30

    },

    "ID":1,

    "Key":{

      "Elements":{

        "AllowSuspectData":1,

        "ApplicationId":"256",

        "ApplicationName":"RTO",

        "AuthenticationErrorCode":0,

        "AuthenticationErrorText":{

          "Data":null,

          "Type":"AsciiString"

        },

        "AuthenticationTTReissue":1644472867,

        "Position":"172.17.0.2/e684c482a0d1",

        "ProvidePermissionExpressions":1,

        "ProvidePermissionProfile":0,

        "SingleOpen":1,

        "SupportBatchRequests":7,

        "SupportEnhancedSymbolList":1,

        "SupportOMMPost":1,

        "SupportOptimizedPauseResume":0,

        "SupportPauseResume":0,

        "SupportStandby":0,

        "SupportViewRequests":1

      },

      "Name":"AQIC5…"

    },

    "State":{

      "Data":"Ok",

      "Stream":"Open",

      "Text":"Login accepted by host ads-fanout-lrg-az1-apse1-prd."

    },

    "Type":"Refresh"

  }

]

SENT:

{

  "ID":2,

  "Key":{

    "Name":"/TRI.N",

    "Service":"ELEKTRON_DD"

  }

}

RECEIVED:

[

  {

    "Fields":{

      "52WK_HIGH":123.59,

      "52WK_LOW":80.16,

      "52W_HDAT":"2021-11-19",

      "52W_HIND":null,

      "52W_LDAT":"2021-02-22",

      "52W_LIND":null,

      "ACVOL_1":191271,

      "ACVOL_UNS":191271,

      "AC_TRN_CRS":null,

      "AC_VOL_CRS":0,

      "ADJUST_CLS":105.24,

      "AFTMKT_DT":null,

      "AFTMKT_NS":null,

      "AFTMKT_PRC":null,

      "AFTMKT_VOL":null,

      "ASK":0.0,

      "ASKSIZE":0,

      "ASK_1":105.24,

      "ASK_2":105.24,

      "ASK_COND_N":"R",

      …

Summary

This article introduces Refinitiv Real-Time SDK and WebSocket API Docker images in Docker Hub. The refinitivapis/websocket_api docker image contains WebSocket API Examples used to connect to Refinitiv Real-Time Distribution System or Refinitiv Data Platform to consume real-time data through the WebSocket connections. The refinitivapis/realtimesdk_c docker image contains the latest version of Refinitiv Real-Time C/C++ libraries and examples. The refinitivapis/realtimesdk_java docker image contains the latest version of Refinitiv Real-Time SDK Java libraries and examples.

Then, it demonstrates how to deploy the refinitivapis/websocket_api docker image on the Docker engines and Azure Containers. Finally, it shows how to the Python examples to retrieve real-time data from Refinitiv Real-Time – Optimized.

References

  1. Azure.microsoft.com. 2020. Azure Container Instances | Microsoft Azure. [online] Available at: https://azure.microsoft.com/en-us/services/container-instances/ [Accessed 10 Feb 2022].
  2. Azure.microsoft.com. 2020. Cloud Computing Services | Microsoft Azure. [online] Available at: https://azure.microsoft.com/en-us/ [Accessed 10 Feb 2022].
  3. Hub.docker.com. n.d. Docker Image For Refinitiv Real-Time SDK C/CPP. [online] Available at: https://hub.docker.com/repository/docker/refinitivapis/realtimesdk_c [Accessed 10 Feb 2022].
  4. Hub.docker.com. 2020. Docker Image For Refinitiv Real-Time SDK Java. [online] Available at: https://hub.docker.com/r/refinitivapis/realtimesdk_java [Accessed 10 Feb 2022].
  5. Hub.docker.com. 2020. Docker Image For Websocket APIs. [online] Available at: https://hub.docker.com/r/refinitivapis/websocket_api [Accessed 10 Feb 2022].
  6. Docker Documentation. 2020. Get Docker. [online] Available at: https://docs.docker.com/get-docker/ [Accessed 10 Feb 2022].
  7. GitHub. n.d. Refinitiv/Real-Time-SDK. [online] Available at: https://github.com/Refinitiv/Real-Time-SDK [Accessed 10 Feb 2022].
  8. GitHub. n.d. Refinitiv/Websocket-Api. [online] Available at: https://github.com/Refinitiv/websocket-api/ [Accessed 10 Feb 2022].
  9. Rungruengrayubkul, V., 2020. Getting Start With Refinitiv Data Platform | DEVELOPER COMMUNITY. [online] Developers.refinitiv.com. Available at: https://developers.refinitiv.com/en/article-catalog/article/getting-start-with-refinitiv-data-platform [Accessed 10 Feb 2022].