public QBExecutionSimulator(Framework framework) : base(framework) { Id = QuantBoxConst.PIdSimExec; Name = "QuantBoxExecutionSimulator"; url = "www.quantbox.cn"; this.framework = framework; BarFilter = new BarFilter(); CheckSubPositions = this.framework.Configuration.UseSubPositions; SlippageProvider = new TickSizeSlippageProvider(); CommissionProvider = new CommissionProvider(); }
public void Fill(Order order, double price, int size) { if (!PartialFills) { _ordersToRemove.Add(order); var report = new ExecutionReport(order); report.DateTime = framework.Clock.DateTime; report.ExecType = ExecType.ExecTrade; report.OrdStatus = OrderStatus.Filled; report.CumQty = order.LeavesQty; report.LastQty = order.LeavesQty; report.LeavesQty = 0.0; report.LastPx = price; if (CommissionProvider != null) { report.Commission = CommissionProvider.GetCommission(report); } else { //Console.WriteLine("ExecutionSimulator::Fill Warning - CommissionProvider is null"); } if (SlippageProvider != null) { report.LastPx = SlippageProvider.GetPrice(report); } else { //Console.WriteLine("ExecutionSimulator::Fill Warning - SlippageProvider is null"); } _reports[order.Id] = new SimulatorExecutionReport(report); EmitExecutionReport(report, Queued); return; } else { if (size <= 0) { Console.WriteLine("ExecutionSimulator::Fill Error - using partial fills, size can not be zero"); return; } ExecutionReport report = new ExecutionReport(order); report.DateTime = framework.Clock.DateTime; report.ExecType = ExecType.ExecTrade; double leaves = order.LeavesQty; if (!_partiallyFilledOrders.ContainsKey(order)) { _partiallyFilledOrders.Add(order, 0.0); } else { leaves = order.Qty - _partiallyFilledOrders[order]; } if (size >= leaves) { Dictionary <Order, double> dictionary = _partiallyFilledOrders; dictionary[order] += leaves; _ordersToRemove.Add(order); report.OrdStatus = OrderStatus.Filled; report.CumQty = _partiallyFilledOrders[order]; report.LastQty = leaves; report.LeavesQty = 0.0; report.LastPx = price; } else if (size < leaves) { Dictionary <Order, double> dictionary = _partiallyFilledOrders; dictionary[order] += size; report.OrdStatus = OrderStatus.PartiallyFilled; report.CumQty = _partiallyFilledOrders[order]; report.LastQty = size; report.LeavesQty = leaves - size; report.LastPx = price; } if (CommissionProvider != null) { report.Commission = CommissionProvider.GetCommission(report); } else { //Console.WriteLine("ExecutionSimulator::Fill Warning - CommissionProvider is null"); } if (SlippageProvider != null) { report.LastPx = SlippageProvider.GetPrice(report); } else { //Console.WriteLine("ExecutionSimulator::Fill Warning - SlippageProvider is null"); } _reports[order.Id] = new SimulatorExecutionReport(report); EmitExecutionReport(report, Queued); } }