Introduction
Last Update: Oct 2024.
The Real-Time SDK (C# Edition) (RTSDK, formerly known as Elektron SDK) is a suite of modern and open source APIs (GitHub) that aim to simplify development through a strong focus on ease of use and standardized access to LSEG Real-Time Platform via the proprietary TCP connection named RSSL and proprietary binary message encoding format named OMM Message. The capabilities range from low latency/high-performance APIs right through to simple streaming Web APIs.
The RTSDK C# Edition can run on Windows, Oracle Linux Server, Red Hat Enterprise Server and Ubuntu Linux platforms. It supports the Visual Studio 2022 IDE for the full features development experience but the IDE is available for Windows developers only. Fortunately, the RTSDK C# Edition also supports the cross-platform .NET CORE and the Visual Studio Code (aka VS Code) editor is available for all major OS platforms. Linux and Windows developers who are using the VS Code editor can implement the real-time streaming application with LSEG Real-Time platform using the RTSDK C# Edition.
This example project shows a step-by-step guide to create the EMA API .NET project and solution with the RTSDK C# Edition connect to the Real-Time Optimized (RTO) server on VS Code and the C# extension. I am demonstrating with the RTSDK C# version 2.1.3.L1 on Ubuntu Linux, and this step-by-step guide can be applied to any supported OS platforms.
Note: For developers who connect to the Real-Time Distribution System (RTDS), you can apply the steps to set up the project, solution and the libraries. However, please check the 100_MP_Streaming example and Cons100 section on the RTSDK C# QuickStart page for the source code part.
Prerequisite
Before I am going further, there is some prerequisite, dependencies, and libraries that the project is needed.
.NET SDK
Firstly, you need .NET 6 SDK for this project. You can download the SDK based on your system from Microsoft .NET 6 website.
Please check How to check that .NET is already installed to verify installed .NET versions on your machine.
Note: Please check the RTSDK C# versions and .NET versions supported from the API Compatibility Matrix document.
Visual Studio Code
Next, the VS Code editor tool with the free C# extension.
Note:
- There is also the C# Dev Kit extension that gives developers more "Visual Studio like" experience and features than the C# extension. However, the C# Dev Kit extension requires Visual Studio License.
- The C# extension requires .NET 8.0 (As of April 2024), but you can setup and compile .NET 6.0 project with the .NET 8.0 SDK.
Access to the RTO
This project uses RTO access credentials for Version 2 Authentication (Service ID).
Please contact your LSEG representative to help you with the RTO account and services.
Note: For developers who connect to the Real-Time Distribution System (RTDS), you need the following information:
- Your ADS Server or Interactive-Provider application hostname or IP Address
- Your ADS Server or Interactive-Provider application RSSL Port number (14002 by default)
- Your Market Data Service Name
- Your Data Access Control System (DACS) User name
Internet Access
The RTSDK C# libraries (both ETA and EMA APIs) are available on the NuGet package manager and distribution platform. You can use the built-in VS Code CLI command to download the EMA and ETA libraries from NuGet over internet.
That covers the prerequisite of this project.
Next, access the ema_project folder and create a new console project with the following command:
Example result:
The dotnet new console --framework net6.0 --use-program-main command creates a new console project with .NET 6.0 framework for you. The command also create a simple application Program.cs as a starting point for the project as follows:
We can test our project creation and .NET SDK setup verification by running this Program.cs with the following command in a terminal:
Add EMA Library
Now we come to how to add the EMA library to the project. The RTSDK C# libraries are available on the NuGet package manager and distribution platform.
We can add the EMA Core library into the project with the dotnet add package LSEG.Ema.Core --version {version} command as follows.
Result:
You can use dotnet list package command to verify the EMA library package installation.
Now the ema_project is ready for implementing the real-time application with EMA C# API.
Add the Real-Time Application Source Code with EMA
Please let me remind you again, if you environment connects to the Real-Time Distribution System (RTDS), please check the 100_MP_Streaming example source code and Cons100 section on the RTSDK C# QuickStart page for the source code part. The code below on this article connects to the RTO (Real-Time Optimized on the Cloud).
So, now let’s look at the real-time application source code. The next step is to changing the Program.cs file source code to call EMA library to connect and consume data from RTO.
To handle a .env file that store you RTO Authentication version 2 credential, we add the DotNetEnv library to the project with the following command:
Then add a .env file to the ema_project folder with the following Authentication V2 content:
Now we come to the coding part. You can open the project in VS Code editor by running the code . command inside the ema_project folder.
The first step is to adding the AppClient class to the Program.cs file. The AppClient class can be a simple class that print Refresh, Update, and Status messages as follows:
Moving on the the Program class that act as the Consumer:
The final step is to create the EmaConfig.xml file with the configurations based on this Enterprise Message API (EMA) - Configuration Overview article. The main point is set the Channel configuration to connect to RTO.
That covers the coding part of the project.
Build and Run Real-Time Application Source Code
That brings us to build and run our source code step we just created. To build the project, we use the dotnet build command inside the ema_project folder.
Please note that the default configuration value is Debug.
Example:
Then the generated executable project_name.dll files (and project_name.exe files if you are on Windows) will be available in the <project folder>/bin/<Debug/Release>/<dotnet target version> folder as follows:
Please keep in mind that the product of dotnet build command isn't ready to be transferred to another machine to run. To create a version of the application that can be deployed, you need to publish it (for example, with the dotnet publish command).
For more detail about the dotnet build command options, please check the dotnet build document page.
Next, we come to the dotnet run command. This command provides a convenient option to run your application from the source code with one command.
Please note that the dotnet run command automatically build the project using dotnet build command if necessary.
Example:
The dotnet run command is used in the context of projects, not built assemblies. If you're trying to run a framework-dependent application DLL instead, you must use dotnet without a command inside <project folder>/bin/<Debug/Release>/<dotnet target version> folder like the following example:
Please note that when running a framework-dependent application DLL above, you need to copy all necessary files (like the EmaConfig.xml or .env file) to the <project folder>/bin/<Debug/Release>/<dotnet target version> folder as well.
For more detail about the run options, please check the dotnet run document page.
Let’s leave the build and run step there.
Publishing the Project
Now let me turn to how to publish our project. The dotnet publish command compiles the application, reads through its dependencies specified in the project file, and publishes the resulting set of files to a directory (containing dll, configuration json files, dependencies files, etc). The command output is ready for deployment to a hosting system for execution. You can publish the .NET application in 2 modes as follows:
- self-contained mode: This mode produces an application that includes the .NET runtime and libraries, and your application and its dependencies. Users of the application can run it on a machine that doesn't have the .NET runtime installed.
- framework-dependent: This mode produces an application that includes only your application itself and its dependencies. Users of the application have to separately install the .NET runtime.
Please note that both publishing modes produce a platform-specific executable by default. Framework-dependent applications can be created without an executable, and these applications are cross-platform.
Example: creates a framework-dependent executable for the current platform.
Result:
Example: creates a self-contained executable for the Windows platform.
Result:
Then you can copy a result directory with all dependencies files to deploy and run on your target machine using the ema_project binary file (based on your runtime).
To learn more about the publish and deployment options, please check the following resources:
- dotnet publish document.
- .NET runtime identifier catalog document.
- .NET application publishing overview documents.
That all I have to say about creating single EMA C# API Project using VS Code.
Create the EMA API Real-Time Application Solution
My next point is creating a solution. When you are doing a software development project, your application may needs multiple source code projects for easy management and implementation by multiple developers. A Visual Studio solution is a container to organize one or more related projects. When you open a solution, Visual Studio and Visual Studio Code automatically loads all the projects that the solution contains.
Initialize A Solution
Firstly, create a new folder name ema_solution in your workbench environment.
Next, access the ema_solution folder and create a new console project with the following command:
Example result:
Our EMA Solution has 2 projects as follows:
- A JSONUtil class library project that contains a POCO object for storing RIC data and transform the RIC data into a JSON message format
- A EMA C# console project that connects and consume data from RTO, and print the market price data in JSON message format using a JSONUtil class library above.
Initialize A Class Library Project
Let's start with a class library project. Firstly, create a new project inside ema_solution folder with the following dotnet CLI command.
Result:
Next, add this JSONUtil project to solution with the following command
Result:
This JSONUtil project uses Newtonsoft.Json package from the NuGet platform for serialize/deserialize JSON data, so we add this package from NuGet to the project via the following command.
Now the JSONUtil project is ready for implementing the class to JSON source code.
Add the Class Library Source Code
Once the package install succeed, open a solution with VS Code with the code . command in a ema_solution folder. The VS Code editor will be opened the EMA_SOLUTION solution like shown in the following image.
Open a Class.cs file and add the following POCO code to the file.
This POCO code just store RIC information such as Name, ServiceName, and Market Data information BID, ASK, and NETCHNG_1 fields data. It also contains a ToJSON() method that serialize self data from RIC object to JSON string message and sends that JSON string to a caller.
You can build entire solution by running dotnet build command inside a ema_solution folder or build just a JSONUtil project with a dotnet build command inside a ema_solution\JSONUtil folder.
Example (build entire solution):
Next, add this EMAConsumer project to solution with the following command
The newly created EMAConsumer project does not have access to the JSONUtil class library project, so we need to add a project reference to the JSONUtil project with the following command.
Example:
Once the EMAConsumer project is finished setup, the VS Code workspace contains both projects that you can develop in the same editor.
Add the Real-Time Application Source Code with EMA
That brings us to updating the source code to call EMA API interfaces and JSONUtil library to consume data from RTO and print that data as JSON message format.
Firstly, add a .env file to the ema_solution/EMAConsumer folder with the following Authentication Version 2 content:
Secondly, open the EMAConsumer/Program.cs file and add the following library import to the file header.
Next, modify the main() method to call the EMA API interfaces as follows:
The code above perform the following tasks:
- Create JSONUtil's RIC object.
- Create AppClient object and pass a RIC object to AppClient for storing data from the API.
- Create a OmmConsumerConfig object with the RTO Authentication Version 2 credential.
- Register the Login stream.
- Create a View request message that subscribes for NETCHNG_1, BID, and ASK fields, then subscribes item.
Now we come to the AppClient class path that needs to get a RIC object from the main class, update RIC object data with incoming data via the OnRefreshMsg and OnUpdateMsg callback methods and call RIC.ToJSON() method to print out incoming data as a JSON message.
Moving on the the Decode() method that iterates incoming FieldList message and updates a RIC object's NETCHNG_1, BID, and ASK properties.
The final step is to create the EmaConfig.xml file with the configurations like the ema_project above to configure the API to connect to RTO endpoint.
That covers the EMAConsumer project part.
Build and Run Real-Time Application Solution
Now, what about building the solution. You can build entire solution by running the dotnet build command in the ema_solution folder or build only this EMAConsumer project by running the dotnet build command in the ema_solution\EMAConsumer folder.
Example: Build entire solution
Unlike the Visual Studio IDE that you can set a solution default project and click the "Run" button on the IDE. With VS Code (and .NET CLI), you need to run the project in side a project folder using the dotnet run command or with dotnet run --project <project/project.csproj> (All required runtime file must be located on the solution home folder).
Run Result: Run inside the EMAConsumer project folder.
That’s all I have to say about how to build and run the EMA solution.
Publishing the Solution
So, now let’s look at how to publish our solution. You can publish the solution using the dotnet publish like the project by specify the the path and filename of a solution file (.sln extension) after the command.
Example:
All dotnet publish command arguments are supported in the solution level too.
Example: creates a self-contained executable for the Windows platform.
The publish result will be available inside each Project' /bin/<Debug/Release>/<dotnet target version> folder like the following example of the Class Library project.
About the EMAConsumer, the publish result also contains the JSONUtil class library's dll file because we have added a project reference to the JSONUtil project.
That covers the EMA Solution creation with VS Code.
Update June 2024, For the multiple .NET SDK versions
If you have multiple .NET SDK versions installed on your machine, you can run the following steps to configure the SDK version for the project/solution.
Firstly go to the project or solution root folder, and run the following command:
It shows all available SDK in your machine (based on your installation) as follows:
Next, run the following command to create a dotnet global.json file:
Open a newly generated global.json file, and change the value of the version property from the latest version in your machine to version 6.x in your machine as follows:
Conclusion and Next Steps
Before I finish, let me just say the RTSDK C# give developers access to the LSEG Real-Time platform's real-time streaming data with both low-level and high-levels APIs interfaces for every developers' requirements. For ultra-high performance applications, there is the ETA API that provides high performance, low latency, and open source low-level API interfaces for developers. For the majority of use cases, there is the ease-of-use EMA API with high-level API interfaces for developers. The C# edition SDK supports the cross-platform .NET SDK 6 (aka .NET Core 6) which makes the application can be developed on various types of development environments such as the full-feature Visual Studio 2022 IDE on Windows, or the .NET CLI tool with any editors on the supported platforms.
Visual Studio Code (or just VSCode) is a free, cross-platform source code editor that took over developers' popularity based on its fast and lightweight, supports a variety of programming languages with IntelliSense, and has complete development operations like debugging, task running, and version control. With the the free C# extension, the VS Code can do basic development tasks with .NET development including the RTSDK C# APIs using the editor with the .NET CLI tool. The combination of the VS Code C# extension and .NET CLI tool make they suitable for developing the real-time applications on non-Windows platforms, or even on Windows for developers who do not have the Visual Studio Professional/Enterprise subscriptions.
If you want more powerful development feature on VS Code for the RTSDK C# edition, there is the C# Dev kit extension that gives you the development experience much closer to the full feature Visual Studio IDE while maintain its lightweight and supports all major OS platforms. However, the C# Dev kit extension requires the Visual Studio Professional or Enterprise subscriptions license.
That’s all I have to say about the RTSDK C# development with VS Code.
References
For further details, please check out the following resources:
- Real-Time SDK C# page on the LSEG Developer Community website.
- Real-Time SDK Family page.
- Real-Time SDK C# Quick Start.
- Developer Article: 10 important things you need to know before you write an Enterprise Real Time application.
- Changes to Customer Access and Identity Management: Real-Time - Optimized.
- EMA C# API Library on NuGet platform.
- .NET SDK page.
- Tutorial: Create a .NET console application using Visual Studio Code.
- Tutorial: Create a .NET class library using Visual Studio Code.
- Setting up VS Code for .NET development page.
- Getting Started with C# in VS Code document.
- How YOU can get started with .NET Core and C# in VS Code blog post.
- Tutorial: Containerize a .NET app.
- .NET SDK on DockerHub platform.
- .NET Runtime on DockerHub platform.
For any question related to this article or the RTSDK page, please use the Developer Community Q&A Forum.