SmartQuant Discussion

Automated Quantitative Strategy Development, SmartQuant Product Discussion and Technical Support Forums
It is currently Thu Apr 02, 2020 7:18 am

All times are UTC + 3 hours




Post new topic Reply to topic  [ 6 posts ] 
Author Message
PostPosted: Tue Oct 05, 2010 11:06 pm 
Offline

Joined: Mon Oct 04, 2010 11:20 pm
Posts: 19
Hi,

can't get the function gethistorical bars working. I am using Open E Cry. When I run the code below for FDAX or any other EUREX instrument, OpenQuant freezes as if it is waiting for an answer. But nothing happens. No exception is thrown. No logfile entries. Code editing and saving still possible. Stopping the strategy is only possible by killing the task in the task manager.

Could you please have a look? What am I doing wrong?

Thanks very much!




public override void OnTrade(Trade trade)
{
try
{
Console.WriteLine("Before retrieving... " + trade.Price);
BarSeries bs = GetHistoricalBars("Open E Cry",Clock.Now.AddDays(-2),Clock.Now.AddDays(-1),86400);
Console.WriteLine("After retrieving");
foreach (Bar b in bs)
{
Console.WriteLine("bar " + b.ToString());
}
}
catch(Exception e)
{
Console.WriteLine("Exception caught {0}",e);
}
}


Top
 Profile  
 
PostPosted: Wed Oct 06, 2010 10:48 am 
Offline
Site Admin

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

Are you able to get these historical bars via OpenQuant UI (Tools->Historical Data Import) ?

Btw, it is not good idea to request historical data from the OnTrade callback.
First, this callback is called very often and, second, it is possible to have a deadlock because GetHistoricalBars is a blocking call, but OEC plugin cannot execute it since it waits while you are processing the current tick...

Regards,
Alex

_________________
SmartQuant Development Team


Top
 Profile  
 
PostPosted: Wed Oct 06, 2010 9:04 pm 
Offline

Joined: Mon Oct 04, 2010 11:20 pm
Posts: 19
Thanks for the quick reply!

After putting the gethistoricalbars call into OnStrategyStart everthing works fine. I wanted to call it just once in onTrade, the code I sent was for debugging. But calling it in OnStrategyStart is fine as well.

Cheers,

put3000


Top
 Profile  
 
PostPosted: Mon Nov 29, 2010 11:43 am 
Offline

Joined: Tue Oct 13, 2009 12:19 pm
Posts: 265
Dear Team,
I am using V: 2.9.12
I have issues with gethistoricalbars as well.

In my strategy, I call it at OnStrategyStart, my market dataprovider is IB (Interactive Brokers) and sometimes, the call, does not get a response nor a timeout, so then, the Strategy hangs and waits for data.
The only option to restart is to kill the process itself.

Is there a way to set a timeout value for historical requests - so that if it fails, it gives back an error msg?

Thanks for your support
Michael

P.S.: I have IB logging enabled, so I see the request which goes out. Below is an example right before OQ just hung up.
<message direction="Out" id="20" name="MsgRequestHistoricalData"><datetime>2010-11-29 03:39:02.539</datetime><version>4</version><fields><TickerId type="System.Int32">35036</TickerId><Contract><ConId type="System.Int32">0</ConId><Symbol type="System.String">ES</Symbol><SecType type="System.String">FUT</SecType><Expiry type="System.String">201012</Expiry><Strike type="System.Double">0</Strike><Right type="System.String">NULL</Right><Multiplier type="System.String">NULL</Multiplier><Exchange type="System.String">GLOBEX</Exchange><Currency type="System.String">USD</Currency><LocalSymbol type="System.String">NULL</LocalSymbol><PrimaryExch type="System.String">NULL</PrimaryExch><IncludeExpired type="System.Boolean">False</IncludeExpired><ComboLegsDescrip type="System.String">NULL</ComboLegsDescrip></Contract><EndDateTime type="System.String">20101129 03:39:00</EndDateTime><DurationStr type="System.String">660 S</DurationStr><BarSize type="System.String">1 MIN</BarSize><WhatToShow type="System.String">TRADES</WhatToShow><UseRTH type="System.Boolean">False</UseRTH><FormatDate type="System.Int32">1</FormatDate></fields></message>


Top
 Profile  
 
PostPosted: Mon Nov 29, 2010 12:23 pm 
Offline
Site Admin

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

Unfortunately, there is no way to set timeout for this call at the moment.
But, you are able to call this method async and wait N seconds for result.
f,ex., in OnStrategyStart method
Code:

use System.Threading;

ManualResetEvent handle = new ManualResetEvent(false);

ThreadPool.QueueUserWorkItem(delegate(object obj)
{
   GetHistoricalBars("IB"....

   handle.Set();
}
);

if (handle.WaitOne(5000)) // wait 5 sec for "normal" exit from GetHistoricalBars method
{
   // "normal" exit
}
else
{
  // timeout
}


Regards,
Alex

_________________
SmartQuant Development Team


Top
 Profile  
 
PostPosted: Mon Nov 29, 2010 1:10 pm 
Offline

Joined: Tue Oct 13, 2009 12:19 pm
Posts: 265
Alex, thank you for the super fast response! I appreciate it!
It works like a charm.


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 3 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