SmartQuant Discussion

Automated Quantitative Strategy Development, SmartQuant Product Discussion and Technical Support Forums
It is currently Fri Feb 28, 2020 10:00 pm

All times are UTC + 3 hours




Post new topic Reply to topic  [ 8 posts ] 
Author Message
 Post subject: OnTrade event
PostPosted: Thu Jan 27, 2011 10:44 am 
Offline

Joined: Sat Jan 22, 2011 1:40 am
Posts: 73
Hello,

From documentation I concluded that OnTrade event will be fired as soon as the new trade happened for the symbol and it should be fired just once per trade.
I decided to print the information about the trade like this:


Console.WriteLine("OnTrade started, "+this.Instrument.Symbol +", Price: "+trade.Price +", time" + trade.DateTime.ToString("HH:mm:ss") );

To my surprise I found multiple printings in Output window for the same symbol and for the same price and time.

How OnTrade is working?

Thank you very much,
Paul


Top
 Profile  
 
 Post subject: Re: OnTrade event
PostPosted: Thu Jan 27, 2011 11:34 am 
Offline

Joined: Tue Aug 05, 2003 3:43 pm
Posts: 6816
It's working as you described, but there can be many trades per second in liquid markets (sometimes you can observe 50 trades per second or more for MSFT or AAPL).

Regards,
Anton


Top
 Profile  
 
 Post subject: Re: OnTrade event
PostPosted: Thu Jan 27, 2011 11:43 am 
Offline

Joined: Sat Jan 22, 2011 1:40 am
Posts: 73
Anton,

Thank you very much for your reply. But I tested 2 hours ago. There is my printing. New York time.



02:03:03 Notice:! OnTrade started, CIEN, Price: 23.31, time19:53:02
02:03:04 Notice:! OnTrade started, CINF, Price: 32.41, time18:12:59
02:03:05 Notice:! OnTrade started, CIEN, Price: 23.31, time19:53:02
02:03:05 Notice:! OnTrade started, CINF, Price: 32.41, time18:12:59
02:03:09 Notice:! OnTrade started, CIEN, Price: 23.31, time19:53:02
02:03:10 Notice:! OnTrade started, CINF, Price: 32.41, time18:12:59
02:03:10 Notice:! OnTrade started, CIEN, Price: 23.31, time19:53:02

Regards,
Paul


Top
 Profile  
 
 Post subject: Re: OnTrade event
PostPosted: Thu Jan 27, 2011 11:47 am 
Offline

Joined: Tue Aug 05, 2003 3:43 pm
Posts: 6816
What data feed do you use?


Top
 Profile  
 
 Post subject: Re: OnTrade event
PostPosted: Thu Jan 27, 2011 2:24 pm 
Offline

Joined: Wed Oct 08, 2003 1:06 pm
Posts: 833
Hi,

Could you please specify in which handler you write this info to the Output? Maybe you can copy/paste a pirce code here? This "02:03:03 Notice:!" prefix is confusing me while in the sample Console.WriteLine there is no such a prefix, what is this "2:03:03" here - local machine time, Clock.Now or something else? In which mode does it happen, with which market data provider?

Regards,
Sergey.


Top
 Profile  
 
 Post subject: Re: OnTrade event
PostPosted: Thu Jan 27, 2011 7:35 pm 
Offline

Joined: Sat Jan 22, 2011 1:40 am
Posts: 73
Sergey,

I am just adding a time stamp to my message. I use IQFeed. I just lost Console.WriteLine output, but it looked the same without timestamp prefix.

There is a code:
public override void OnTrade(Trade trade)
{

logNotice("OnTrade started, "+this.Instrument.Symbol +", Price: "+trade.Price +", time" + trade.DateTime.ToString("HH:mm:ss") );
}



public void logNotice(string message)
{
try
{
message = getTimeStamp() + (
char)9 + "Notice:! " + message;
writeLogStringToFile(this.GetLogFileName(), message);
}
catch { }
}

private void writeLogStringToFile(string fileName, string message)
{
if(this.Mode != StrategyMode.Simulation)
{
try
{
FileInfo fi = new FileInfo(fileName);
DirectoryInfo directory = fi.Directory;
if (directory.Exists == false)
{
directory.Create();
}
else
{
// removes more than 1 day old files
foreach (FileInfo logFile in directory.GetFiles())
{
if (((TimeSpan)(DateTime.Now - logFile.CreationTime)).TotalDays > 1)
{
logFile.Delete();
}
}
}
using (StreamWriter sw = File.AppendText(fileName))
{
lock (sw)
{
sw.WriteLine(message);
sw.Flush();
}
}
}
catch { }
}
else
{
// Console.WriteLine(message);
}
Console.WriteLine(message);
}


Top
 Profile  
 
 Post subject: Re: OnTrade event
PostPosted: Thu Jan 27, 2011 7:38 pm 
Offline

Joined: Sat Jan 22, 2011 1:40 am
Posts: 73
I forgot to answer your questions. There is my time from local mashime in the prefix, New York time.


Top
 Profile  
 
 Post subject: Re: OnTrade event
PostPosted: Thu Jan 27, 2011 7:42 pm 
Offline

Joined: Sat Jan 22, 2011 1:40 am
Posts: 73
There is 1 function missing in my code:


private string getTimeStamp()
{
return DateTime.Now.ToString("HH:mm:ss");
}

I used paper trading mode.

Regards,
Paul


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

All times are UTC + 3 hours


Who is online

Users browsing this forum: No registered users and 0 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