private async Task HandleCommonStuff(OrderBase order) { var id = await _identityGenerator.GenerateNewIdAsync(); order.Id = id; order.Status = OrderStatus.Registered; order.Registered = DateTime.UtcNow; }
public static OrderEntity Create(OrderBase src) { var result = new OrderEntity { PartitionKey = GeneratePartitionAsAllOrders(src.Status), RowKey = GenerateRowKey(src.Id) }; result.SetOrder(src); return result; }
public void SetOrder(OrderBase order) { foreach (var orderType in OrderTypes) if (orderType.Value == order.GetType()) { Type = orderType.Key; OrderData = Newtonsoft.Json.JsonConvert.SerializeObject(order); return; } throw new Exception("Can not set order. Unknown order type: "+order.GetType()); }
public async Task RegisterOrderAsync(OrderBase order) { var newEntity = OrderEntity.Create(order); await _tableStorage.InsertAsync(newEntity); newEntity.PartitionKey = OrderEntity.GeneratePartitionKey(order.TraderId); await _tableStorage.InsertAsync(newEntity); }
public async Task UpdateOrderAsync(OrderBase updatedOrder) { var partitionKey = OrderEntity.GeneratePartitionKey(updatedOrder.TraderId); var rowKey = OrderEntity.GenerateRowKey(updatedOrder.Id); var oldStatus = OrderStatus.Registered; await _tableStorage.ReplaceAsync(partitionKey, rowKey, itm => { oldStatus = itm.GetOrder().Status; itm.SetOrder(updatedOrder); return itm; }); if (oldStatus == updatedOrder.Status) { await _tableStorage.ReplaceAsync(OrderEntity.GeneratePartitionAsAllOrders(oldStatus), rowKey, itm => { itm.SetOrder(updatedOrder); return itm; }); return; } partitionKey = OrderEntity.GeneratePartitionAsAllOrders(oldStatus); await _tableStorage.DeleteAsync(partitionKey, rowKey); var newEntity = OrderEntity.Create(updatedOrder); await _tableStorage.InsertOrReplaceAsync(newEntity); }
private static OrderList SeparateOrders(OrderBase[] orders) { var result = new OrderList(); foreach (var orderBase in orders) { var marketOrder = orderBase as MarketOrder; if (marketOrder != null) result.MarketOrders.Add(marketOrder); var limitOrder = orderBase as LimitOrder; if (limitOrder != null) { if (limitOrder.Action == OrderAction.Buy) result.LimitOrdersBuy.Add(OrderWrapper.Create(limitOrder)); if (limitOrder.Action == OrderAction.Sell) result.LimitOrdersSell.Add(OrderWrapper.Create(limitOrder)); } } result.MarketOrders = result.MarketOrders.OrderBy(itm => itm.Id).ToList(); result.LimitOrdersBuy = result.LimitOrdersBuy.OrderByDescending(itm => itm.Order.Price).ToList(); result.LimitOrdersSell = result.LimitOrdersSell.OrderBy(itm => itm.Order.Price).ToList(); return result; }