is it right way to do it? is there any in built version of the api?
private double CalculateAverageFillPrice(Account account)
{
double totalFillPrice = 0;
int tradeCount = 0;
lock (account.Executions){
Print("CalculateAverageFillPrice " + account.Executions.Count);
foreach (Execution execution in account.Executions)
{
if (execution.Instrument.FullName != Instrument.FullName || execution.Order.OrderAction != OrderAction.Buy) {
continue;
}
Print("execution " + execution.Instrument.FullName + " " + execution.Time.Date + " price " + execution.Price + " today " + DateTime.Now.Date);
DateTime executionTime = execution.Time;
if (executionTime.Date == DateTime.Now.Date)
{
totalFillPrice += execution.Price;
tradeCount++;
}
}
if (tradeCount > 0)
{
return totalFillPrice / tradeCount;
}
else
{
return 0.0;
}
}
return 0.0;
}

Comment