Dukascopy Support Board http://www.dukascopy.com/swiss/english/forex/jforex/forum/ |
|
Failing to unsubscribe to an instrument http://www.dukascopy.com/swiss/english/forex/jforex/forum/viewtopic.php?f=65&t=57517 |
Page 1 of 1 |
Author: | pouet300 [ Fri 01 Jan, 2021, 18:15 ] |
Post subject: | Failing to unsubscribe to an instrument |
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; |
Author: | API Support [ Tue 09 Feb, 2021, 17:53 ] |
Post subject: | Re: Failing to unsubscribe to an instrument |
Greetings. When strategy subscribes to instrument, request for full-depth subscription is sent asynchronously. Therefore, it can interleave with subsequent unsubscription request, with the result that instrument remains subscribed. Strategy should postpone unsubscription request to avoid interleaving with request for full-depth subscription: @Override public void onStart(IContext context) throws JFException{ console=context.getConsole(); ScheduledExecutorService scheduler = Executors.newScheduledThreadPool(1); @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 */ scheduler.schedule(() -> context.unsubscribeInstruments(s), 10, TimeUnit.SECONDS); nb++; } scheduler.shutdown(); } Instruments for conversion to account currency are automatically subscribed when strategy subscribes to some instrument. They remain subscribed after executing code above, because strategy does not sent request for unsubscribing from them. Regards. |
Page 1 of 1 |