Hello,
I'm struggling to unsubscribe to instruments with my strategy
.
I need to fetch historic data on many markets and perform a scoring, then to enter market on best fitted instruments only.
Basically, I would like to subscribe to instruments one by one, fetch history then unsubscribe.
When scoring is done, only subscribe to the p best...
The below sample code reproduce the issue with minimal steps, when I run the strategy, the subscribed instruments grows (not expected).
And the bars still continue to come such as message related to those instruments
This cause significative performance issues and I can't implement my strategy because of that.
Do you have any recommendation how to properly unsubscribe?
I have tried with all charts closed, I guess there are implied data feed subscribed with IContext.setSubscribedInstruments
Many thanks for your help.
package lu.panacea.stock;
import java.util.Collections;
import java.util.Set;
import com.dukascopy.api.IAccount;
import com.dukascopy.api.IBar;
import com.dukascopy.api.IConsole;
import com.dukascopy.api.IContext;
import com.dukascopy.api.IMessage;
import com.dukascopy.api.IStrategy;
import com.dukascopy.api.ITick;
import com.dukascopy.api.Instrument;
import com.dukascopy.api.JFException;
import com.dukascopy.api.Period;
import com.dukascopy.api.instrument.IFinancialInstrument;
import com.dukascopy.api.instrument.IInstrumentGroup;
public class Issue implements IStrategy{
private IConsole console;
private static final String STOCK_GROUP="STK_CASH";
@Override
public void onStart(IContext context) throws JFException{
console=context.getConsole();
@SuppressWarnings("deprecation")
IInstrumentGroup group=context.getFinancialInstrumentProvider().getGroup(STOCK_GROUP);
int nb=0;
for(IFinancialInstrument instrument:group.getInstruments()){
Instrument instr=(Instrument)instrument;
if(instr.getCountry().equals("US")) continue;
if(nb==10) break;
Set<Instrument> s=Collections.singleton(instr);
context.setSubscribedInstruments(s,true);
/*
Technical analysis on price history here
*/
context.unsubscribeInstruments(s);
nb++;
}
}
@Override
public void onTick(Instrument instrument, ITick tick) throws JFException{
console.getInfo().println("Tick >>>"+instrument+" -- "+tick);
}
@Override
public void onBar(Instrument instrument, Period period, IBar askBar, IBar bidBar) throws JFException{
console.getInfo().println("Bar >>> "+instrument+" "+period+" "+askBar+" "+bidBar);
}
@Override
public void onMessage(IMessage message) throws JFException{
console.getInfo().println("MSG >>> "+message);
}
@Override
public void onAccount(IAccount account) throws JFException{
console.getInfo().println("Account >>> "+account);
}
@Override
public void onStop() throws JFException{}
}