Refinitiv Data Library for TypeScript

Session Layer

Summary

Accessing to the Refinitiv Data Platform to retrieve content requires your application to authenticate and to manage connection semantics in order to keep the user session live. Refinitiv Data Platform Libraries provide this managed access through an interface called a Session. The session is the interface to the data platform and is responsible for defining authentication details, managing connection resources, and implementing the necessary protocol to communicate with the data platform. Depending on the access point your application uses to connect to the platform, it can choose from one of the session implementations to initiate the connection. With the exception of the creation phase, all Session implementations expose the same API and behave the same.

Once the session is created and opened, the application can use it in conjunction with objects of the Content Layer or objects of the Delivery layer to get access to the breadth and depth of content and services available on the Refinitiv Data Platform.

Depending on the access point your application uses to connect to the Refinitiv Data Platform, it will create and open one of the following sessions:

  • DesktopSession: This type of session is used to connect to the Refinitiv Data Platform either via Eikon or via Refinitiv Workspace. It requires Eikon or Refinitiv Workspace to be running alongside with your application. This type of session does not work with Eikon Web or Refinitiv Workspace for Web.

  • ContainerSession: This type of session is for applications integrated into a Refinitiv container (e.g. Refinitiv Workspace or Refinitiv Workspace for Web) and that need to connect to the Refinitiv Data Platform via this container.
    Note: This session type is only available with the Refinitiv Data Library for TypeScript/JavaScript.

  • PlatformSession: This type of session is used to connect directly to the Refinitiv Data Platform or via a local real-time enterprise platform. It requires a Refinitiv Data Platform account (either a user account or a machine account) if you would like to connect directly to RDP, in this cases you will need to provide Refinitiv Data Platform credentials to create the session. If you would like to work via local platform, it requires the IP of the local platform and a user name (a.k.a. DACS user name).

All these session types require an App Key that uniquely identifies your application. Please refer to the Refinitiv Data Platform Libraries Quick Start guides to learn how to create an App Key for your application.

Installation

Coming soon...

Note: Installation instructions will be included in an updated version of this document that will come along with the first release of the library.

Example of usageu:

1. Setup a session to connect to the data platform.

Note: The type of session (PlatformSession, DesktopSession or ContainerSession) depends on your use case.

  • For Platform Session:
import { PlatformSession, PlatformSessionParams } from '@refinitiv-data/data';

const params: PlatformSessionParams = {
    appKey: process.env.APP_KEY,
    userName: process.env.USERNAME,
    password: process.env.PASSWORD,
    host: '0.0.0.0:15000',
};

const platformSession = PlatformSession.Definition(params).getSession();

await platformSession.open();
  • For Desktop Session:
import { DesktopSession } from '@refinitiv-data/data';

const desktopSession: Session = DesktopSession.Definition({ appKey: process.env.APP_KEY! }).getSession();

await desktopSession.open();
  • For Container Session in Refinitiv Workspace application:
import { ContainerSession, Session } from '@refinitiv-data/data-containersession';

const containerSession: Session = ContainerSession.Definition({ appKey: process.env.APP_KEY! }).getSession();

await containerSession.open();

2. Use Content Layer objects to retrieve data

  • Fundamental data retrieval:
import { contentFactory, FundamentalAndReference} from '@refinitiv-data/data';

// Session setup from the previous code block

(async () => {
    await session.open();

    try {

        const response = await FundamentalAndReference.Definition({
                    universe: ['IBM', 'GOOGL.O', 'MSFT.O'],
                    fields: ['TR.CompanyNumEmploy', 'TR.EmployeeSatisfaction']
        }).getData(session);

        console.log('response: ', response);

    } catch (err) {
        console.log(err);
    } finally {
        session.close();
    }
})();
  • Pricing stream subscription:
import { Pricing, PricingDefinition } from '@refinitiv-data/data';

// Session setup from the previous code block

(async () => {
    try {
        await session.open();

        // Create the stream and register callbacks to reveive events
        const pricingStream = Pricing.Definition({
            universe: ['EUR=', 'UAH='],
            fields: ['DSPLY_NAME', 'BID_NET_CH'],
        })
        .getStream(session)
        .on(Pricing.StreamEvent.Refresh, (data, instrument) => console.log(data));
        .on(Pricing.StreamEvent.Update, (data, instrument) => console.log(data));
        .on(Pricing.StreamEvent.Status, (data, instrument) => console.log(data));
        .on(Pricing.StreamEvent.Complete, sp => console.log('Complete'));
        .on(Pricing.StreamEvent.Error, err => console.error(err));

        // Open the stream to start receiving events
        await pricingStream.open();

        // Optionally the latest values can be retrieved from the memory cache
        console.log(pricingStream.getFields('EUR='));
        console.log(pricingStream.getFields('EUR=', ['BID_NET_CH', 'CURRENCY']));
        console.log(pricingStream.getFieldValue('EUR=', 'BID_NET_CH'));
        console.log(pricingStream.getItemStatus('EUR='));

        await pricingStream.close();
    } catch (err) {
        console.log(err);
    } finally {
        session.close();
    }
})();

3. Alternatively the Delivery Layer can be used to retrieve data.

Note: The low level Delivery Layer is generally used to retrieve data from Refinitiv Data Platform APIs that don't have any dedicated content object yet.

  • Getting data from a RESTful API of the Refinitiv Data Platform
import { EndpointRequest, EndpointRequestDefinitionParams } from '@refinitiv-data/data';

// Session setup from the previous code block

session
    .open()
    .then(() => {
        const endpointRequestDefinition = EndpointRequest.Definition({
            url: '/data/news/v1/analyze',
            method: EndpointRequest.Method.GET,
            query: {
                query: 'USA',
            },
        });

        return endpointRequestDefinition.getData(session);
    })
    .then(data => /*handle received data*/)
    .catch(err => /*handle error*/)
    .then(() => session.close());
  • Opening a stream
import { OMMStream } from '@refinitiv-data/data';

session
  .open()
  .then(() => {
    const ommStream = OMMStream.Definition('EUR=').getStream(session);

    ommStream.on(OMMStream.Event.Refresh, (data) => console.log('Refresh:', data));
    ommStream.on(OMMStream.Event.Update, (data) => console.log('Update:', data));
    ommStream.on(OMMStream.Event.Status, (data) => console.log('Status:', data));
    ommStream.on(OMMStream.Event.Complete, ommStream => console.log('Complete'));
    ommStream.on(OMMStream.Event.StateChanged, (ommStream, state) => console.log('State:', state));
    ommStream.on(OMMStream.Event.Error, err => console.log('Error:', err));

    return ommStream.open();
  })
  .then(data => ommStream.close())
  .catch(err => /*handle error*/)
  .then(() => session.close());

Other examples

You will find other examples on the Refinitiv Developer Community portal.