how to list all selected instruments ?

Custom indicators, trading strategies, data export and recording and more...
jeff87
Posts: 3
Joined: Sat Jan 16, 2021 8:59 am
Has thanked: 1 time

how to list all selected instruments ?

Post by jeff87 » Thu Mar 18, 2021 5:15 pm

Hi,

I want to select one of all instruments displayed in bookmap using a combo inside a settings dialog.

i tried to get all instruments into a list using :
   public void onInstrumentAdded(InstrumentInfo info) 

it works but it's not populated before the first time i display my settings dialog.


 

Andry API support
Posts: 548
Joined: Mon Jul 09, 2018 11:18 am
Has thanked: 25 times
Been thanked: 85 times

Re: how to list all selected instruments ?

Post by Andry API support » Tue Mar 23, 2021 11:49 am

Hi jeff87,
you need to implement Layer1ApiInstrumentSpecificEnabledStateProvider to manage actions triggered by strategy checkbox changed state. Please check this interface description in the javadoc.
You can get active instruments adding an instrument listener (adapter) to its provider.
I forgot to mention this example is for Core API. It is not possible to do it with Simplified API.
(just a simple example)

Code: Select all

public class InstrumentReceiver implements Layer1ApiInstrumentSpecificEnabledStateProvider, Layer1ApiFinishable {

    Layer1ApiProvider provider;
    
    public InstrumentReceiver(Layer1ApiProvider provider) {
        super();
        this.provider = provider;
        provider.addListener(new Layer1ApiInstrumentAdapter() {
            @Override
            public void onInstrumentAdded(String alias, InstrumentInfo instrumentInfo) {
                System.out.println("from Layer1ApiProvider provider added " + alias);
            }
        });
    }
    // ...

Post Reply