SmartQuant Discussion

Automated Quantitative Strategy Development, SmartQuant Product Discussion and Technical Support Forums
It is currently Wed Oct 28, 2020 11:32 am

All times are UTC + 3 hours




Post new topic Reply to topic  [ 10 posts ] 
Author Message
 Post subject: GetHistoricalBars
PostPosted: Thu Aug 26, 2010 10:42 pm 
Offline

Joined: Wed Apr 27, 2005 4:41 pm
Posts: 609
Location: Helsinki, Finland
Hi,

any idea why the following code returns nothing on the first run, but when I stop the strategy and rerun it, the history bars are retreived just fine? And also on the on the following runs as well. If I restart whole OQ then I need to run the code twice again to get the historybars from IB.

Code:
   DateTime dateTimeNow = OpenQuant.API.Clock.Now;          
   BarSeries gotBars = GetHistoricalBars("IB", Instrument, dateTimeNow.AddMinutes(-2), dateTimeNow.AddMinutes(-1), 60);


Top
 Profile  
 
 Post subject:
PostPosted: Mon Aug 30, 2010 6:16 pm 
Offline

Joined: Wed Apr 27, 2005 4:41 pm
Posts: 609
Location: Helsinki, Finland
Any ideas around this?

Thanks,
Eelofi


Top
 Profile  
 
 Post subject:
PostPosted: Tue Aug 31, 2010 11:04 am 
Offline
Site Admin

Joined: Thu Jul 17, 2003 10:39 am
Posts: 1478
Hi,

I have put this code into OnStrategyStart method and got 2 bars when run the strategy first time. Next, I have restarted OQ, ran the strategy and got 2 bars again.

Regards,
Alex

_________________
SmartQuant Development Team


Top
 Profile  
 
 Post subject:
PostPosted: Tue Aug 31, 2010 1:07 pm 
Offline

Joined: Wed Apr 27, 2005 4:41 pm
Posts: 609
Location: Helsinki, Finland
Hmmmm, any ideas why it doesn't work for me in onstrategystart?

Thanks,
Eelofi


Top
 Profile  
 
 Post subject:
PostPosted: Tue Aug 31, 2010 1:13 pm 
Offline

Joined: Tue Aug 05, 2003 3:43 pm
Posts: 6817
Could you please send us your strategy code? (Or just extract a portion of code that reproduces your problem).

Regards,
Anton


Top
 Profile  
 
 Post subject:
PostPosted: Wed Sep 01, 2010 5:29 pm 
Offline

Joined: Wed Apr 27, 2005 4:41 pm
Posts: 609
Location: Helsinki, Finland
Hi Sergey,

here's the code. Same symptoms as in my real code. First time round just show the last bar in the database and nothing else, not even the WriteLine from the catch. Second time round gets the bars ok. Instrument = SPY, broker = IB, 1min bars.

Thanks,
Eelofi

Code:
using System;
using System.Drawing;

using OpenQuant.API;
using OpenQuant.API.Indicators;

public class MyStrategy : Strategy
{
   public override void OnStrategyStart()
   {
      if (base.Mode == StrategyMode.Live)
      {
         try
         {
            BarSeries barit = DataManager.GetHistoricalBars(Instrument,BarType.Time, 60);
            DateTime dateTimePrev = barit.Last.DateTime;
            Console.WriteLine("Last bar in database {0} ", dateTimePrev);
            if (base.Mode == StrategyMode.Live)
            {
               DateTime dateTimeNow = OpenQuant.API.Clock.Now;                         
               foreach (Bar bar in GetHistoricalBars("IB", Instrument, dateTimePrev, dateTimeNow, 60))
               {
                  Console.WriteLine(bar);
                  DataManager.Add(Instrument, bar); //Add to database
               }
            }
            
         }
         catch
         {
            Console.WriteLine ("Couldn't retreive the bars from IB");
         }
      }

   }

   public override void OnBar(Bar bar)
   {
   }
}


Top
 Profile  
 
 Post subject:
PostPosted: Wed Sep 15, 2010 10:55 pm 
Offline

Joined: Wed Apr 27, 2005 4:41 pm
Posts: 609
Location: Helsinki, Finland
I noticed one bit on this today to be aware of.

If you request data for a period when the stock exchange is not yet open IB provides you with an error message: "historical market data service error message: invalid step: 60". In my eyes this implies that the bars which I'm asking for are somehow in the wrong period lenght or something.

But in reality asking for data from the same date starting after the exchange is already open makes it work. Asking for data before the exhange is open yields the error message from IB.


Top
 Profile  
 
 Post subject: Re: GetHistoricalBars
PostPosted: Mon Nov 29, 2010 11:47 am 
Offline

Joined: Tue Oct 13, 2009 12:19 pm
Posts: 271
For me, this did not make a difference, either if I request for even the last x minutes in RTH, my gethistoricalbars still hangs and like you wrote, I also do not get any kind of Exception thrown or therelike.

Regards
Michael


Top
 Profile  
 
 Post subject: Re: GetHistoricalBars
PostPosted: Tue Nov 30, 2010 9:52 am 
Offline

Joined: Wed Apr 27, 2005 4:41 pm
Posts: 609
Location: Helsinki, Finland
Mike,
having used the gethistoricalbars for a while now, I can only say that it's really unrealiable. One day it works, the other it doesn't - restart, reboot etc make no difference. I have no facts on it, but I beleive it's due to IB, as I don't change anything on the OQ side.

BR,
Eelofi


Top
 Profile  
 
 Post subject: Re: GetHistoricalBars
PostPosted: Tue Nov 30, 2010 10:07 am 
Offline

Joined: Tue Oct 13, 2009 12:19 pm
Posts: 271
Dear Eelofi,

this helped me to at least not get into a freeze - a sort of timeout workaround;-)
viewtopic.php?f=60&t=8433

Regards
Mike


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

All times are UTC + 3 hours


Who is online

Users browsing this forum: No registered users and 1 guest


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