void order_ExecutionReport(object sender, ExecutionReportEventArgs args) { SingleOrder order = sender as SingleOrder; ExecutionReport report = args.ExecutionReport; //Console.WriteLine("Execution report type : " + report.ExecType); if (report.ExecType == ExecType.Fill || report.ExecType == ExecType.PartialFill) { //Console.WriteLine("Fill report, average fill price = {0}@{1:#.00}", report.OrderQty, report.AvgPx); //Console.WriteLine( "*** {0} Report {1} cum {2} leaves {3} last {4} total {5} ", // instrument.Symbol, report.OrdStatus, report.CumQty, report.LeavesQty, report.LastQty, report.OrderQty ); switch (order.Side) { case Side.Buy: PositionFilled += (int)Math.Round(report.LastQty); break; case Side.Sell: PositionFilled -= (int)Math.Round(report.LastQty); break; } } if (report.ExecType == ExecType.Fill) { if (ordersTag.ContainsKey(order.ClOrdID)) { EOrderTag tag = (EOrderTag)ordersTag[order.ClOrdID]; if (EOrderTag.Entry == tag) { AvgEntryPrice = report.AvgPx; switch (EntrySignal) { case ESignal.Long: HardStopPrice = AvgEntryPrice - HardStopDelta; // this may not work if we have multiple partial fills SoftStopPrice = AvgEntryPrice - TrailingStopDelta; break; case ESignal.Short: HardStopPrice = AvgEntryPrice + HardStopDelta; // this may not work if we have multiple partial fills SoftStopPrice = AvgEntryPrice + TrailingStopDelta; break; } } } } }
void order_StatusChanged(object sender, EventArgs e) { SingleOrder order = sender as SingleOrder; //Console.WriteLine( "*** {0} Status {1} cum {2} leaves {3} last {4} total {5}", // instrument.Symbol, order.OrdStatus, order.CumQty, order.LeavesQty, order.LastQty, order.OrderQty ); bool CheckStop = false; switch (order.OrdStatus) { case OrdStatus.PartiallyFilled: if (0 != order.LeavesQty) { Console.WriteLine("*** {0} Remaining quantity = {1}", instrument.Symbol, order.LeavesQty); } if (!ordersPartiallyFilled.ContainsKey(order.ClOrdID)) { if (ordersSubmitted.ContainsKey(order.ClOrdID)) { ordersSubmitted.Remove(order.ClOrdID); } ordersPartiallyFilled.Add(order.ClOrdID, order); } //CheckStop = true; // need to fix this sometime break; case OrdStatus.Filled: //Console.WriteLine("Average fill price = {0}@{1:#.00} {2} {3}", order.OrderQty, order.AvgPx, order.Side, order.OrdStatus); if (ordersSubmitted.ContainsKey(order.ClOrdID)) { ordersSubmitted.Remove(order.ClOrdID); } if (ordersPartiallyFilled.ContainsKey(order.ClOrdID)) { ordersPartiallyFilled.Remove(order.ClOrdID); } ordersFilled.Add(order.ClOrdID, order); CheckStop = true; // HardStopPrice on set on 'Filled' break; case OrdStatus.Cancelled: if (ordersSubmitted.ContainsKey(order.ClOrdID)) { ordersSubmitted.Remove(order.ClOrdID); } ordersCancelled.Add(order.ClOrdID, order); break; case OrdStatus.PendingCancel: // not used during simulation // signalled during realtime trading break; default: Console.WriteLine("*** {0} Order status changed to : {1}", instrument.Symbol, order.OrdStatus.ToString()); break; } if (CheckStop) { if (ordersTag.ContainsKey(order.ClOrdID)) { EOrderTag tag = (EOrderTag)ordersTag[order.ClOrdID]; if (EOrderTag.Entry == tag) { SetHardStop(); } if (EOrderTag.HardStop == tag) { State = EState.CleanUp; } } } OutStandingOrdersExist = ((0 != ordersSubmitted.Count) || (0 != ordersPartiallyFilled.Count)); //Console.WriteLine( "{0} status {1} {2} {3} {4}", order.ClOrdID, order.OrdStatus, // OutStandingOrdersExist, ordersSubmitted.Count, ordersPartiallyFilled.Count ); }