The article teaches how to get an instrument using it's symbol.
How to get an instrument by symbol
In this article, you will learn how to use the API to get an instrument using its symbol as the reference.
Before you can get an instrument using its symbol, you need to:
Create an instance of the instruments manager.
Get an instrument by symbol.
Step 1: Create an instance of the instrumentsManager.
The first step is to create an instance of the instrumentsManager.
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 instance of the instrumentsManager:
The instruments manager Hide
typescriptjavascriptsession.getInstrumentsManager().refresh(); // refresh it before using it to make sure it contains the latest info. let instrumentsManager = session.getInstrumentsManager();
For more information about the IInstrumentsManager interface, see the API reference.
Step 2: Get an instrument by symbol.
The next step is to get an instrument by its symbol.
A symbol is a unique identifier for an instrument, such as EUR/USD or USD/JPY.
You can use the getInstrumentBySymbol method of the instruments manager to get an instrument by its symbol.
This method takes a symbol as an argument and returns an instrument object if you have subscribed to it. Otherwise, it returns null.
Below, you can see some example code to get an instrument by symbol:
Get an instrument by symbol Hide
typescriptjavascriptlet instrument = instrumentsManager.getInstrumentBySymbol("USD/JPY");
For more information about the getInstrumentBySymbol getInstrumentBySymbol method, see the API reference.
Conclusion:
You have learned how to use the API to get an instrument by symbol.
You have created an instance of the instruments manager and got an instrument by symbol.
You can now use this knowledge to build your own applications that work with instruments.
Now that you have an instrument, you can subscribe or unsubscribe to it, or create orders.
See also IInstrumentsManager