public void LimitOrder() { var sec = new Security() { Id = 1, Type = SecurityType.Future, Group = "GC", Product = "GC", Contract = "GCZ6" }; var book = new OrderBook(sec); book.SetStatus(SecurityTradingStatus.Open); OrderCreatedEventArgs createdArgs = null; book.OrderCreated += (sender, e) => { createdArgs = e; }; book.CreateLimitOrder(1, TimeInForce.Day, null, Side.Buy, 100, 3); Debug.Assert(createdArgs != null); Debug.Assert(createdArgs.Order.Status == OrderStatus.Created); Debug.Assert(createdArgs.Order.Id == 1); Debug.Assert(createdArgs.Order.Price == 100); Debug.Assert(createdArgs.Order.Quantity == 3); Debug.Assert(createdArgs.Order.FilledQuantity == 0); Debug.Assert(createdArgs.Order.RemainingQuantity == 3); Debug.Assert(createdArgs.Order.Side == Side.Buy); Debug.Assert(createdArgs.Order.Type == OrderType.Limit); Debug.Assert(createdArgs.Order.TimeInForce == TimeInForce.Day); Debug.Assert(createdArgs.Order.Security == sec); OrderUpdateEventArgs updatedArgs = null; book.OrderUpdated += (sender, e) => { updatedArgs = e; }; book.UpdateLimitOrder(1, 105, 5); Debug.Assert(updatedArgs != null); Debug.Assert(updatedArgs.Order.Status == OrderStatus.Updated); Debug.Assert(updatedArgs.Order.Id == 1); Debug.Assert(updatedArgs.Order.Price == 105); Debug.Assert(updatedArgs.Order.Quantity == 5); Debug.Assert(updatedArgs.Order.FilledQuantity == 0); Debug.Assert(updatedArgs.Order.RemainingQuantity == 5); OrderDeletedEventArgs deletedArgs = null; book.OrderDeleted += (sender, e) => { deletedArgs = e; }; book.DeleteOrder(1); Debug.Assert(deletedArgs != null); Debug.Assert(deletedArgs.Order.Status == OrderStatus.Deleted); Debug.Assert(deletedArgs.Order.Id == 1); Debug.Assert(deletedArgs.Order.Price == 105); Debug.Assert(updatedArgs.Order.Quantity == 5); Debug.Assert(deletedArgs.Order.FilledQuantity == 0); Debug.Assert(deletedArgs.Order.RemainingQuantity == 0); Debug.Assert(deletedArgs.Reason == null); }
/// <summary> /// Trigger method called to raise the <see cref="OrderCreated"/> event /// </summary> protected virtual void OnOrderCreated(OrderDTO orderDTO, ICollection <OrderItemDTO> items) { //null test, without making a copy while keeping thread-safety OrderCreatedEventArgs args = new OrderCreatedEventArgs() { Order = orderDTO, Items = items }; OrderCreated?.Invoke(this, args); }
/// <summary> /// Method for handling order creation events /// </summary> protected void NewOrderCreated(object sender, OrderCreatedEventArgs args) { OrderDTO order = args.Order; ICollection <OrderItemDTO> items = args.Items; // check the inventory service to see if there is enough inventory to fill this order // although probably not a good business practice, we are only going to process the order // if it can be filled ENTIRELY. If not, it will be rejected. bool reject_order = false; foreach (OrderItemDTO item in items) { if (item.quantity > _inventoryService.InventoryAmount(order.store_id, item.product_id)) { reject_order = true; break; } } if (reject_order) { SetOrderAsRejected(order, items); // inform the inventory service that an order needs additional inventory foreach (OrderItemDTO item in items) { _inventoryService.ProductRequired(order.store_id, item.product_id, item.quantity); } } else { SetOrderAsProcessing(order, items); // might have references to talk to a shipping business object to start the shipping process // OR the shipping service might be listening for the OrderIsProcessing event } }
private void HandleOrderCreateAccepted(object sender, OrderCreatedEventArgs args) { ordersToClients[args.Order.Id].Send(new NewOrderAck(args.Order, orderInfos[args.Order.Id])); SendBookUpdates(args.Order.Security); }