private bool updateOrder(Order order, IExecutionReportMessage er) { // stupid protocol...but this is what the API sends... if (er.ExecType == ExecTypeEnum.etPartiallyFilled || er.ExecType == ExecTypeEnum.etFilled) { order.avgPx = (order.avgPx * order.cumQty + er.OrderQty * er.Price) / (order.cumQty + er.OrderQty); order.cumQty += er.OrderQty; } else if (er.ExecType == ExecTypeEnum.etReplaced) { if (!PriceUtils.isZero(er.OrderQty)) { order.quantity = er.OrderQty; } if (!PriceUtils.isZero(er.Price)) { order.price = er.Price; } } ExecType? execType = FieldConverter.convert(er.ExecType, order); OrdStatus?ordStatus = FieldConverter.convert(er.OrderStatus, order); if (null != execType && null != ordStatus) { order.exchangeOrderId = er.OrderID; order.ordStatus = ordStatus ?? order.ordStatus; order.execType = execType ?? order.execType; order.lastMsg = er.Text; return(true); } return(false); }
public void amendOrder(String exchangeOrderId, double price, double qty) { logger.Info("Amend Order: " + "exchangeOrderId=" + exchangeOrderId + "; price=" + price + "; qty=" + qty); Order order; if (!orders.TryGetValue(exchangeOrderId, out order)) { throw new DownStreamException("Amend order not found: " + exchangeOrderId); } if (PriceUtils.EqualGreaterThan(qty, order.quantity)) { throw new DownStreamException("Can't amend quantity up: " + exchangeOrderId); } if (PriceUtils.EqualLessThan(qty, order.cumQty)) { throw new DownStreamException("Can't amend quantity to equal or less than filled quantity: " + exchangeOrderId); } if (!PriceUtils.isZero(price) && !PriceUtils.Equal(price, order.price) && !PriceUtils.isZero(qty) && !PriceUtils.Equal(qty, order.quantity)) { throw new DownStreamException("Can't amend both price and quantity: " + exchangeOrderId); } if (price == order.price && qty == order.quantity) { throw new DownStreamException("Can't amend price and qty to same value: " + exchangeOrderId); } OrderMessage.ReplaceOrderMessage replaceOrderMessage = new OrderMessage.ReplaceOrderMessage(); replaceOrderMessage.AE = user; replaceOrderMessage.Account = account; replaceOrderMessage.BrokerID = brokerID; replaceOrderMessage.Symbol = order.symbol; replaceOrderMessage.OrderID = order.exchangeOrderId; replaceOrderMessage.Side = FieldConverter.convert(order.orderSide); if (!PriceUtils.isZero(price) && !PriceUtils.Equal(price, order.price)) { replaceOrderMessage.Price = price; } if (!PriceUtils.isZero(qty) && !PriceUtils.Equal(qty, order.quantity)) { replaceOrderMessage.OrderQty = (int)qty; } replaceOrderMessage.Data = formatData(replaceOrderMessage.OrderQty, order.account); replaceOrderMessage.NID = exchangeConnection.GenerateUniqueID(this.market, OrderMessage.MessageTypeEnum.mtReplace); exchangeConnection.ReplaceOrder(replaceOrderMessage); }