private void HandleUpdateOrderMessage(JToken data) { var order = _orderCreator.Create(data); if (!_myOrders.ContainsKey(order.NumberMarket)) { SendLogMessage($"Order with number {order.NumberUser} has been removed from the FTXServer cache.", LogMessageType.Error); return; } var localOrder = _myOrders[order.NumberMarket]; if (order.State != localOrder.State) { if (order.State == OrderStateType.Done) { var currentTime = DateTime.Now; if (localOrder.State == OrderStateType.Cancel) { localOrder.TimeCancel = currentTime; SendLogMessage($"Order num {localOrder.NumberUser} is canceled.", LogMessageType.Trade); } else { localOrder.TimeDone = currentTime; } _myOrders.Remove(localOrder.NumberMarket); } localOrder.State = order.State; OnOrderEvent(localOrder); } }
private void HandleUpdateMessage(JToken response) { var channel = response.SelectToken("channel").ToString(); switch (channel) { case "orderbook": OnMarketDepthEvent(_marketDepthCreator.Update(response)); break; case "trades": OnTradeEvent(_tradesCreator.Create(response)); break; case "ticker": break; case "fills": OnMyTradeEvent(_tradesCreator.CreateMyTrade(response)); break; case "orders": var order = _orderCreator.Create(response); if (order.State == OrderStateType.Done) { _orderCreator.RemoveMyOrder(order); } OnOrderEvent(order); break; default: SendLogMessage("Unhandeled channel :" + channel, LogMessageType.System); break; } }