Skip to content

This example project shows how to set up a Docker Image to run the RTO C# WebSocket API examples with VS Code Remote Containers extension.

License

Notifications You must be signed in to change notification settings

LSEG-API-Samples/Article.WebSocketAPI.CSharp.DevContainer.RTO

Repository files navigation

Develop with Refinitiv WebSocket API Docker Image with C# in VS Code Using the Remote - Containers extension

  • version: 2.0
  • Last update: July 2023
  • Environment: Docker
  • Compiler: C#
  • Prerequisite: Demo prerequisite

Example Code Disclaimer: ALL EXAMPLE CODE IS PROVIDED ON AN “AS IS” AND “AS AVAILABLE” BASIS FOR ILLUSTRATIVE PURPOSES ONLY. REFINITIV MAKES NO REPRESENTATIONS OR WARRANTIES OF ANY KIND, EXPRESS OR IMPLIED, AS TO THE OPERATION OF THE EXAMPLE CODE, OR THE INFORMATION, CONTENT, OR MATERIALS USED IN CONNECTION WITH THE EXAMPLE CODE. YOU EXPRESSLY AGREE THAT YOUR USE OF THE EXAMPLE CODE IS AT YOUR SOLE RISK.

Introduction

Visual Studio Code (or just VS Code) is a free source code editor developed and maintained by Microsoft. This cross-platform editor rapidly gained popularity with developers as it is fast and lightweight, supports a variety of programming languages with IntelliSense (a feature that has originated with VS Code’s older sibling, Visual Studio IDE), and enables complete development operations like debugging, task running, and version control.

VS Code provides numerous extensions that add features and expand development workflows like the remote development that lets developers use a container, remote machine, or the Windows Subsystem for Linux (WSL) as a full-featured development environment with the Remote Development Extension Pack.

As part of the Remote Development Extension Pack, the Remote - Containers extension lets developers use a Docker container as an immutable/sandbox development environment. It allows the developers to open any folder inside (or mounted into) a container and take advantage of Visual Studio Code's full feature set (IntelliSense, code navigation, debugging, etc) as a local-quality development experience. This feature is called devcontainer or dev container.

figure-1

The previous Article.RTSDK.Java.Cpp.DevContainer project demonstrates how to use Refinitiv Real-Time SDK Java/C++ Docker Images devcontainer with VS Code Remote - Containers extension. This example project shows how to set up a .NET devcontainer with the Remote - Containers extension to for the Refinitiv Real-Time Optimized (RTO) C# WebSocket examples using a Dockerfile. This Dockerfile is built on top of the refinitivapis/websocket_api Docker Image and developers can run the RTO C# WebSocket examples codes directly in VS Code.

Update: The refinitivapis/websocket_api Docker Image has been updated to the current version of WebSocket API GitHub repository. All C# example projects have been update to .NET 6.0.

Refinitiv WebSocket API Introduction

As part of the Refinitiv Real-Time SDK, the Websocket API for Pricing Streaming and Real-Time Service (aka Websocket API) provides a connection to Refinitiv Real-Time via a standard WebSocket protocol and JSON message format. Developers can use multiple client technology standards such as Python, JavaScript, .Net, etc. to establish WebSocket connections to Refinitiv Real-Time Distribution Systems (RTDS), or Refinitiv Real-Time - Optimized (RTO - cloud solution) available via Refinitiv Data Platform (RDP).

The WebSocket API examples source code for various programming languages is available on GitHub. If developers are new to the Refinitiv Real-Time, they can use the refinitivapis/websocket_api Docker Image to learn the WebSocket API and RTO connection flows quickly. This Docker image contains all WebSocket API Examples, the Python runtime, and dependencies required to run the Python WebSocket examples. You can check my colleague's Introduction to the refinitivapis/websocket_api Docker Image article for step-by-step guidance on how to deploy and run the RTSDK Docker images via the Docker command line.

If you are using the Refinitiv Real-Time SDK C/C++ or Java, there are the following Docker images that contain the latest version SDK too.

Demo prerequisite

This example requires the following dependencies software and libraries.

  1. Visual Studio Code editor.
  2. Docker Desktop/Engine application.
  3. VS Code - Remote Development extension pack
  4. Access to the Refinitiv Refinitiv Data Platform and Refinitiv Real-Time - Optimized. (for the RTO example only)
  5. Internet connection.

I highly recommend following System requirements and Installation sections to set up your environment.

Please contact your Refinitiv representative to help you to access the RTO account and services. You can find more detail regarding the RDP and RTO access credentials set up from the Getting Started for Machine ID section of the Getting Start with Refinitiv Data Platform article.

RTO C# devcontainer Detail

Please see the full details over the RTO C# devcontainer implementation on the WebSocketAPI_DevContainer.md file.

Project files

This example project contains the following files and folders

  1. .devcontainer/devcontainer.json: An example devcontainer configuration file.
  2. .devcontainer/Dockerfile: An example Dockerfile.
  3. .devcontainer/.env.devcontainer.example: An example .env.devcontainer file.
  4. .vscode: VS Code debugging configurations for the RTO C# WebSocket example.
  5. images: Project images folder.
  6. LICENSE.md: Project's license file.
  7. README.md: Project's README file.
  8. WebSocketAPI_DevContainer.md: Project's Document file.

How to run the Examples

The first step is to unzip or download the example project folder into a directory of your choice, then follow the steps below.

  1. Go to the project's .devcontainer folder and create a file name .env.devcontainer with the following content.

    # V1
    RTO_USERNAME=<Version 1 RTO Machine-ID>
    RTO_PASSWORD=<Version 1 RTO Password>
    RTO_CLIENTID=<Version 1 RTO AppKey>
    # V2
    RTO_CLIENTID=<Version 2 Client-ID>
    RTO_CLIENTSECRET=<Version 2 Client-Secret>

    Please note that the environment variable file above contains the V1 and V2 Authentication. If you have only V1 or V2, please change the file based on your preference.

  2. Start a Docker desktop or Docker engine on your machine.

  3. Open the project folder in the VS Code editor

  4. Install the VS Code - Remote Development extension pack.

  5. Open the VS Code Command Palette with the F1 key, and then select the Remote-Containers: Reopen in Container command.

figure-3b

Now VS Code is ready to run the RTO C# WebSocket devcontainer.

running-demo

Troubleshooting

Question: I do not have the RTO credentials.

Answer: Please contact your Refinitiv representative to help you to access the RTO account and services.

Question: When I select the Remote-Containers: Reopen in Container command, VS Code returns an error with Docker returned an error. Make Sure the Docker daemon is running. message.

Answer: Please install and start a Docker desktop or Docker engine on your machine.

Question: When I select the Remote-Containers: Reopen in Container command, VS Code returns an error with Docker returned an error. Make Sure the Docker daemon is running. message.

Answer: Please install and start a Docker desktop or Docker engine on your machine.

Question: VS Code throws an error with the An error occurred setting up the container message.

figure-10

Answer: Please choose the Open devcontainer.json Locally option. Delete Docker container and images (named vsc-XXX), check the error log file, and restart the process.

Question: VS Code throws an error and the log show *docker: open .devcontainer/.env.devcontainer: The system cannot find... message.

figure-11

Answer: This error message means you do not have a .dev.devcontainer environment variables file in the .devcontainer folder. Please create it using the template from a .dev.devcontainer.example file.

Conclusion and Next Steps

Docker is an open containerization platform for developing, testing, deploying, and running any software application. It helps developers create a consistent development environment (aka devcontainer) without manually maintaining dependencies and toolsets for the project. The VS Code Remote - Containers let developers develop applications with a devcontainer using VS Code full-featured sets such as debugging and various extensions. This devcontainer is easy to set up and share among the project team.

This example project is just a brief introduction to the Remote - Containers extension. Developers can work with Docker Compose to build a customized Docker image that matches the development requirements, debugging, install various VS Code extensions to use in the Dev Container (via the GUI or configuration file), clone Docker container from Git repository, attach the VS Code to a running container, port forwarding, and much more. I highly recommend you check the following VS Code resources for more details:

The refinitivapis/websocket_api Docker Image is a good starting point for developers who are new to the WebSocket API. Developers can use the Docker Image with the Remote - Containers extensions to set up a development environment, and run the Python WebSocket examples. Developers who are using other programming languages can install more compilers/runtime to run the WebSocket examples based on their preferred technology too.

References

For further details, please review the following resources:

For any questions related to this project or the WebSocket API page, please use the Developer Community Q&A Forum.

Developers Articles

About

This example project shows how to set up a Docker Image to run the RTO C# WebSocket API examples with VS Code Remote Containers extension.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published