예제 #1
0
        private async Task ExecuteAsync(Order[] orders)
        {
            var internalTrades = new List <InternalTrade>();

            var now = DateTime.UtcNow;

            //foreach (var trade in orders.SelectMany(x => x.Trades))
            //{
            //    _log.Info("Lykke trade handled", new
            //    {
            //        TradeId = trade.TradeId,
            //        TradeTimestamp = trade.Timestamp,
            //        Now = now,
            //        Latency = (now - trade.Timestamp).TotalMilliseconds
            //    });
            //}

            foreach (Order order in orders)
            {
                // The limit order fully executed. The remaining volume is zero.
                if (order.Status == OrderStatus.Matched)
                {
                    internalTrades.AddRange(Map(order, true));
                }

                // The limit order partially executed.
                if (order.Status == OrderStatus.PartiallyMatched)
                {
                    internalTrades.AddRange(Map(order, false));
                }

                // The limit order was cancelled by matching engine after processing trades.
                // In this case order partially executed and remaining volume is less than min volume allowed by asset pair.
                if (order.Status == OrderStatus.Cancelled)
                {
                    internalTrades.AddRange(Map(order, true));
                }
            }

            Task processTask = _positionService.OpenAsync(internalTrades);
            Task delayTask   = Task.Delay(TimeSpan.FromMinutes(1));

            Task task = await Task.WhenAny(processTask, delayTask);

            if (task == delayTask)
            {
                _log.WarningWithDetails("Trades processing takes more than one minute", internalTrades);
            }

            await processTask;

            await _hedgeService.ExecuteAsync();
        }
 protected override Task OnExecuteAsync(CancellationToken cancellation)
 {
     return(_hedgeService.ExecuteAsync());
 }