private void InsertOrderHistoryEntry( HiddenOrderEntry orderToClose, OrderStatus status, DateTime closeTime) { OrderHistory.InsertOne( new OrderHistoryEntry { CreateTime = orderToClose.EntryTime, CloseTime = closeTime, User = orderToClose.User, AccountId = orderToClose.AccountId, Instrument = orderToClose.Instrument, Qty = orderToClose.Qty, Side = orderToClose.Side, // Closed stop order Type = OrderType.Stop, // Stop order does not fill quantity, it only creates a limit order FilledQty = 0, LimitPrice = null, StopPrice = orderToClose.StopPrice, // TODO from stop loss and take profit //ChildrenIds DurationType = orderToClose.DurationType, Duration = orderToClose.Duration, Status = status, } ); }
internal void CreateOrder(CreateOrderEventEntry createOrder) { _logger.LogDebug("Called create order @ version number " + createOrder.VersionNumber); switch (createOrder.Type) { case OrderType.Limit: var limitOrder = new OrderBookEntry { EntryTime = createOrder.EntryTime, CreatedOnVersionId = createOrder.VersionNumber, User = createOrder.User, AccountId = createOrder.AccountId, Instrument = createOrder.Instrument, Qty = createOrder.Qty, Side = createOrder.Side, FilledQty = 0m, LimitPrice = createOrder.LimitPrice.Value, // TODO from stop loss and take profit //ChildrenIds DurationType = createOrder.DurationType, Duration = createOrder.Duration, }; OrderBook.InsertOne(limitOrder); break; case OrderType.Stop: var stopOrder = new HiddenOrderEntry { EntryTime = createOrder.EntryTime, CreatedOnVersionId = createOrder.VersionNumber, User = createOrder.User, AccountId = createOrder.AccountId, Instrument = createOrder.Instrument, Qty = createOrder.Qty, Side = createOrder.Side, StopPrice = createOrder.StopPrice.Value, // TODO from stop loss and take profit //ChildrenIds DurationType = createOrder.DurationType, Duration = createOrder.Duration, }; HiddenOrders.InsertOne(stopOrder); break; case OrderType.Market: OrderHistory.InsertOne( new OrderHistoryEntry { CreateTime = createOrder.EntryTime, CloseTime = createOrder.EntryTime, User = createOrder.User, AccountId = createOrder.AccountId, Instrument = createOrder.Instrument, Qty = createOrder.Qty, Side = createOrder.Side, // Closed market order Type = OrderType.Market, // The market order will be filled by the following match orders FilledQty = createOrder.FilledMarketOrderQty, // The most expensive accepted limit price will be shown to the user LimitPrice = createOrder.LimitPrice.Value, StopPrice = null, // TODO from stop loss and take profit //ChildrenIds DurationType = createOrder.DurationType, Duration = createOrder.Duration, Status = OrderStatus.Filled, } ); break; default: throw new ArgumentOutOfRangeException(nameof(createOrder.Type)); } _logger.LogDebug("Persisted create order @ version number " + createOrder.VersionNumber); }