SmartQuant Discussion

Automated Quantitative Strategy Development, SmartQuant Product Discussion and Technical Support Forums
It is currently Sat Sep 23, 2017 1:27 am

All times are UTC + 3 hours




Post new topic Reply to topic  [ 6 posts ] 
Author Message
PostPosted: Tue Feb 07, 2017 4:55 pm 
Offline

Joined: Tue Oct 13, 2009 12:19 pm
Posts: 195
Dear all,

I am quite familiar with Instrument strategies. And they tend to work alright.

Now, that I setup an "Strategy Project" only, I cannot get the OnTrade event running.

I do get quotes, if I open a QuoteMonitor and then I see the quotes/trades flowing in, but still, OnTrade does not fire.
I do not have any barfactory set, since I do not need bars, only realtime quotes. I have added a couple of instruments to the strategy itself, so there should be enough action.

As a second measure, I added BarFactory, but that does not fire either...

Anything special for just Strategy Projects?
How could I check, if the symbols are added to the strategy, are actually subscribing data?

Regards
Mike


Top
 Profile  
 
PostPosted: Tue Feb 07, 2017 5:49 pm 
Offline

Joined: Tue Oct 13, 2009 12:19 pm
Posts: 195
I also noticed, that when I use IQFeed, that no symbols got subscribed.

Normally, when I connect to dataprovider and start the strategy, the symbols connect and subscribe for the data.

What should the next step be?


Top
 Profile  
 
PostPosted: Wed Feb 08, 2017 4:39 pm 
Offline

Joined: Tue Oct 13, 2009 12:19 pm
Posts: 195
Dear all,

please find my code attached.

If I run it like that. Nothing happens. No OnBar or OnTrade gets fired.

If I add a Quate Window for IB, and add the "ES H17" contract - all of a sudden, bars start coming in. See output:

Code:
Build succeeded
Building Backtest
Build succeeded
Building Realtime
Build succeeded
2/8/2017 14:30:39.343 Event manager started at 2/8/2017 14:30:39.343
Run in Live mode.
2/8/2017 14:30:39.436 Scenario::StartStrategy Live
2/8/2017 14:30:39.436 StrategyManager::StartStrategy Debug RealTime
started strategy with 2 instruments
Provider Name IB status Connected
Dataprovider is null for SPY
Dataprovider is null for ES H17
InstrumentManager.Instruments.Count 21 instruments
SubscriptionManager::Subscribe provider id = 4 IB (Interactive Brokers TWS API) www.interactivebrokers.com ES H17 (E-mini S&P 500)
on bar fired ES H17 and Bar [2/8/2017 14:32:00.000 - 2/8/2017 14:32:10.000] Instrument=15 Type=Time Size=10 Open=2285.25 High=2285.25 Low=2285.25 Close=2285.25 Volume=13
on bar fired ES H17 and Bar [2/8/2017 14:32:10.000 - 2/8/2017 14:32:20.000] Instrument=15 Type=Time Size=10 Open=2285 High=2285 Low=2285 Close=2285 Volume=10


Now, can you let me know, how to fix this, that I do not need to manually setup a quote window? Or can you post a fix...
Thanks
Michael


Attachments:
Debug Strategy Solution.zip [10.39 KiB]
Downloaded 24 times
Top
 Profile  
 
PostPosted: Wed Feb 08, 2017 4:58 pm 
Offline

Joined: Tue Oct 13, 2009 12:19 pm
Posts: 195
dear all,

slowly:

If I add this:
SubscriptionManager sManager = new SubscriptionManager(framework);
sManager.Subscribe(dataProvider as IDataProvider, strategy.Instruments);

to Realtime - Scenario.cs just before: StartStrategy();

OnBar event is firing, without me added the symbol to the QuoteMonitor - but still no OnTrade event.

Any idea what is the cause of that?

Thanks
Mike


Top
 Profile  
 
PostPosted: Wed Feb 08, 2017 5:15 pm 
Offline

Joined: Wed May 05, 2010 9:49 pm
Posts: 367
You can try do it in two ways:
1) set providers before adding instruments in strategy + using strategy.AddInstrument instead strategy.Instruments.Add:
Code:
      public override void Run()
        {
         Initialize();
         strategy = new MyStrategy(framework, "Debug RealTime");
         //ToDo: check for rollovers....

         Provider dataProvider = ProviderManager.Providers["IB"] as Provider; //Provider quantRouter = ProviderManager.Providers["QuantRouter"] as Provider;
         if (dataProvider.Status == ProviderStatus.Disconnected)
            dataProvider.Connect();
         if (StrategyManager.Mode == StrategyMode.Live)
         {
            Provider executionProvider = ProviderManager.Providers["IB"] as Provider;
            if (executionProvider.Status == ProviderStatus.Disconnected)
               executionProvider.Connect();
            strategy.ExecutionProvider = executionProvider as IExecutionProvider;
            strategy.DataProvider = dataProvider as IDataProvider;
         }
         
         // Get trading instruments.
         List <string> symbols = new List<string>{"SPY"};
         BarFactory.Clear();
         foreach(string s in symbols)
         {
            Instrument instrument = InstrumentManager.Instruments[s];
            //strategy.Instruments.Add(instrument);  // and add trading instruments.
            strategy.AddInstrument(instrument);
            InstrumentManager.Save(instrument);
            BarFactory.Add(instrument, BarType.Time, 10);
         }
         // Get provider for realtime.
         

         Console.WriteLine("Run in {0} mode.", StrategyManager.Mode);
         StartStrategy(StrategyManager.Mode);
        }

2)set dataprovider directly to the instrument + using strategy.AddInstrument instead strategy.Instruments.Add:
Code:
     public override void Run()
        {
         Initialize();
         strategy = new MyStrategy(framework, "Debug RealTime");
         //ToDo: check for rollovers....

         // Get trading instruments.
         List <string> symbols = new List<string>{"SPY"};
         BarFactory.Clear();
         foreach(string s in symbols)
         {
            Instrument instrument = InstrumentManager.Instruments[s];
            instrument.DataProvider = ProviderManager.Providers["IB"] as IDataProvider;
            //strategy.Instruments.Add(instrument);  // and add trading instruments.
            strategy.AddInstrument(instrument);
            InstrumentManager.Save(instrument);
            BarFactory.Add(instrument, BarType.Time, 10);
         }
         // Get provider for realtime.
         
         Provider dataProvider = ProviderManager.Providers["IB"] as Provider; //Provider quantRouter = ProviderManager.Providers["QuantRouter"] as Provider;
         if (dataProvider.Status == ProviderStatus.Disconnected)
            dataProvider.Connect();
         if (StrategyManager.Mode == StrategyMode.Live)
         {
            Provider executionProvider = ProviderManager.Providers["IB"] as Provider;
            if (executionProvider.Status == ProviderStatus.Disconnected)
               executionProvider.Connect();
            strategy.ExecutionProvider = executionProvider as IExecutionProvider;
            //strategy.DataProvider = dataProvider as IDataProvider;
         }
         Console.WriteLine("Run in {0} mode.", StrategyManager.Mode);
         StartStrategy(StrategyManager.Mode);
        }


Top
 Profile  
 
PostPosted: Wed Feb 08, 2017 7:38 pm 
Offline

Joined: Tue Oct 13, 2009 12:19 pm
Posts: 195
Thanks for the reply.

Now, it all works.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 6 posts ] 

All times are UTC + 3 hours


Who is online

Users browsing this forum: No registered users and 2 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron
Powered by phpBB® Forum Software © phpBB Group