SmartQuant Discussion
http://www.smartquant.com/forums/

OnTrade event
http://www.smartquant.com/forums/viewtopic.php?f=44&t=8711
Page 1 of 1

Author:  vortex [ Thu Jan 27, 2011 10:44 am ]
Post subject:  OnTrade event

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

Author:  Dr. Anton Fokin [ Thu Jan 27, 2011 11:34 am ]
Post subject:  Re: OnTrade event

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

Author:  vortex [ Thu Jan 27, 2011 11:43 am ]
Post subject:  Re: OnTrade event

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

Author:  Dr. Anton Fokin [ Thu Jan 27, 2011 11:47 am ]
Post subject:  Re: OnTrade event

What data feed do you use?

Author:  Baraz Sergey [ Thu Jan 27, 2011 2:24 pm ]
Post subject:  Re: OnTrade event

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.

Author:  vortex [ Thu Jan 27, 2011 7:35 pm ]
Post subject:  Re: OnTrade event

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);
}

Author:  vortex [ Thu Jan 27, 2011 7:38 pm ]
Post subject:  Re: OnTrade event

I forgot to answer your questions. There is my time from local mashime in the prefix, New York time.

Author:  vortex [ Thu Jan 27, 2011 7:42 pm ]
Post subject:  Re: OnTrade event

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

Page 1 of 1 All times are UTC + 3 hours
Powered by phpBB® Forum Software © phpBB Group
https://www.phpbb.com/