Get Available Instruments

Brief

The article teaches how to get a list of available instruments.

Details

How to get a list of available instruments Overview

In this article you will learn how to use the API to get available instruments.
Before you can get available instruments, you need to:

Step 1: Create an instrument manager object

The first step is to create an instrument manager object. This is an object that provides methods for managing instruments.

You can use the IInstrumentsManager interface to access its methods and properties.

Below, you can see some example code to create an instrument manager object:

Obtain a list of instruments Hide

typescriptjavascriptjava
let instrumentsManager = session.getInstrumentsManager();

For more information about the IInstrumentsManager interface, see the API reference.

Step 2: Subscribe to the instrument manager state change event

The second step is to subscribe to the instrument manager state change event.
This event is triggered when the instrument manager's state changes, such as when it is loading, loaded, or not loaded.
You can use the IDataManagerStateChangeListener interface to define a listener function for this event.

Below, you can see some example code to subscribe to the instrument manager state change event:

subscribe to the instrument manager state change event Hide

typescriptjavascriptjava
instrumentsManager.subscribeInstrumentChange(new InstrumentChangeListener(instrumentsManager, session));

For more information about the IDataManagerStateChangeListener interface, see the API reference.

Step 3: Refresh the instrument manager object

The third step is to refresh the instrument manager object.
This is a method that requests the latest data from the API and updates the instrument manager's state and data.
You can use the refresh method of the instrument manager object to perform this action.

Below, you can see some example code to refresh the instrument manager object:

subscribe to the instrument manager state change event Hide

typescriptjavascriptjava
session.getInstrumentsManager().refresh();

For more information about the IInstrumentsManager interface, see the API reference.

Step 4: Get the list of instrument descriptors

The final step is to get a list of instrument descriptors.
These are objects that contain short descriptions of available instruments, such as their offer ID, symbol, subscription status, and price stream ID.
You can use the getAllInstrumentDescriptors method of the instrument manager object to get a list of instrument descriptors.
This method returns an array of InstrumentDescriptor objects.

Below, you can see some example code to get the list of instrument descriptors:

subscribe to the instrument manager state change event Hide

typescriptjavascriptjava
let descriptors = instrumentsManager.getAllInstrumentDescriptors();

The class Descriptor allows you to get the offer ID, subscription status, symbol, and other information, full information about the instrument is available only after subscription.

See also InstrumentDescriptor, getOfferId, getPriceStreamId, getSortOrder, getSubscriptionStatus, getSymbol

Now that you have your list of instruments, you are ready to subscribe to them or perform other actions on them.

For more information about the InstrumentDescriptor interface and its methods, see the API reference.

Conclusion:

You have learned how to use the API to get the available instruments. You have created an instrument manager object, subscribed to the instrument manager state change event, refreshed the instrument manager object, and got the list of instrument descriptors. You can now use this knowledge to build your own applications that work with the available instruments.

Download the sample TypeScript, JavaScript.

back