Refinitiv Data Library for TypeScript

Tutorial Source Code

TypeScript Examples

Examples referenced

  • 2.2-Pricing\pricing-streamingCache.ts
Last Update March 2022
Compiler/Runtime See Getting Started with TypeScript.
Pre-requisites Enable the session environment as outlined within the Getting Started guide.


Whether accessing from the desktop, directly to the cloud, or through your deployed managed streaming services, the Refinitiv Data Libraries provide ease-of-use interfaces to retrieve real-time streaming content from the platform. By utilizing streaming interfaces, developers can easily define properties to request, receive, and process market data in real-time.

The following tutorial requests for a small watchlist of instruments, retrieving level 1 (MarketPrice) streaming content that will automatically update an internally-manage cache in real-time.  The Pricing interface includes a number of powerful features, one of which is the ability to cache real-time events in the background for the purpose of fast and easy retrieval.  The clear advantage is the convenience and simplicity when accessing live prices but also provides fast access by avoiding the need to traverse the network whenever there is a choice to retrieve up-to-date prices. 

Executing the Application

In our example, we're requesting to stream 3 instruments.  The goal of the example is to show the initial values coming in and how they change as market conditions change.  The example does not capture and display the real-time changes but rather updates an internally managed cache behind the scenes.  The example demonstrates the ability to retrieve values from the Pricing cache and shows values changing every few seconds.  For example, the following output highlights the initial values for one of the instruments and what happens a few seconds later when we display the cache.  We will see the new values based on the changes in the market for that specific instrument.

Within the source code package, select the source code example within the Delivery section.  To execute the example, refer to the pre-requisites section at the top of this tutorial.

The expected output should look similar to this:

How to request and extract live values from the cache

The following code segment requests for a small watchlist of items from the streaming services defined within the platform:


// specify a list of items and fields to retrieve a snapshot of prices

const pricingDefinition = Pricing.Definition({

    universe: ['EUR=', 'CAD=', 'GBP='],

    fields: ['DSPLY_NAME', 'BID', 'ASK', 'OPEN_PRC', 'PCTCHNG'],




const stream = pricingDefinition.getStream(session);


// open the stream in streaming mode


The above code segment was intentionally broken out into 3 distinct steps for the purpose of explanation, but also provides flexibility when using the interfaces.  In general, the above code performs the following:

  • Define a Pricing request
    The Pricing interface provides the ability to specify a list of instruments to stream.  In addition, includes a number of other options, including the ability to specify a list of fields.  It's worth noting that if no fields are specified in the definition, all available fields will be returned.  While not specifying the fields is a convenient way to look at all available fields, in practice, it's best to limit the fieldset based on requirements to optimize performance.

  • Retrieve a stream interface
    Using the pricing definition, retrieve a streaming interface providing the ability to request and manage real-time streaming data.

  • Open the stream
    Using the stream interface, open the stream.  Opening a stream performs 2 distinct actions.  First, the request will instruct the streaming services to deliver a complete image, or refresh, of the latest values for the specified fields.  Second, the streaming services will begin to deliver real-time updates based on changes in the live market.  The stream interface will automatically react to these real-time events in order to properly maintain a live pricing cache.

Once in place, we can begin to perform different actions on our streams to extract live data.  For example, the following code segment will extract a snapshot of the live cache of all the field values.



  'EUR=': stream.getFields('EUR='),

  'CAD=': stream.getFields('CAD='),

  'GBP=': stream.getFields('GBP=')


While the above will allow the ability to extract a snapshot of the cache, the interface also supports simple cache access methods to pull out a specific instrument without the need to extract a copy of the cache.  For example:


// get one field from the cache

stream.getFieldValue('CAD=', 'BID')


// get multiple fields from the cache

stream.getFields('GBP=', ['DSPLY_NAME', 'BID', 'ASK'])


Closing the stream

When you wish to stop the flow of live updates, you will need to issue a close on the stream.  The following code segment will close the stream:


// close the open stream

 await stream.close();

In our example code, we included a simple way to extract a snapshot of the entire cache.  However, the interface also supports the ability to snapshot a single or subset of items from the cache as opposed to copying the whole collection.  In addition, the interface also allows the specification of individual fields to be extracted when performing a cache snapshot.  In the last example code snippet, we showed a convenient way to access elements directly from the stream as opposed to performing a cache snapshot.  The choice between accessing the stream directly or performing an explicit cache snapshot depends on the specific workflow and use case.

It's worth noting that the Pricing interface inherently creates a live cache as part of its design.  While this is automatic and convenient, users may choose to manage their own cache by utilizing the event capabilities of streaming.  Users can optionally utilize the OMM Stream interface defined within the Delivery layer if they choose to have more control over how items are cached within their applications or if they prefer to forego the need for a cache.

The Pricing interface defined within the Refinitiv Data Library includes other useful features, such as the ability to retrieve real-time prices available within the RDP snapshot pricing service.  This capability can be extremely useful for users that may not have access to or require the need to stream prices through real-time streaming services.  Refer to the tutorial package for additional examples.  In addition, we encourage the use of IntelliSense documentation within your Visual Studio Code editor to discover other useful capabilities.