private void CreateOrder(Order order) { order.Status = OrderStatus.Created; order.Time = DateTime.UtcNow; orders.Add(order); Console.WriteLine($"order added to book: {order}"); var bid = WorkingOrders(Side.Buy).FirstOrDefault(); if (bid != null && bid.Price > sessionMaxBidPrice) { sessionMaxBidPrice = bid.Price; } var ask = WorkingOrders(Side.Sell).FirstOrDefault(); if (ask != null && ask.Price > sessionMinAskPrice) { sessionMinAskPrice = ask.Price; } OrderCreated?.Invoke(this, new OrderCreatedEventArgs(order)); }
/// <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); }
public void AddOrder(Order order) { if (_orders.Any(o => o.Id == order.Id)) { OrderRejected?.Invoke(this, new OrderEventArgs(order.Id, order.CustomerName)); } else { _orders.Add(order); OrderCreated?.Invoke(this, new OrderEventArgs(order.Id, order.CustomerName)); } }
IEnumerator SpawnOrders() { while (true) { if (activeOrders.Count < maxConcurrentOrders) { var generatedOrder = new Order(GetRandomRecipe(), UnityEngine.Random.Range(recipeExpireTimeSecondsMin, recipeExpireTimeSecondsMax)); generatedOrder.OrderExpired += OnOrderExpired; activeOrders.Add(generatedOrder); OrderCreated?.Invoke(generatedOrder); } yield return(new WaitForSeconds(UnityEngine.Random.Range(waitForSpawningSecondsMin, waitForSpawningSecondsMax))); } }