Пример #1
0
        /// <summary>
        /// Filter orders that are already calculated
        /// </summary>
        /// <returns></returns>
        private List <Order> GetOrdersForCalculation()
        {
            //read orders synchronously
            var openOrders = _orderReader.GetActive();

            //prepare the list of orders
            var lastInvocationTime = CalcLastInvocationTime();
            var calculatedIds      = _overnightSwapCache.GetAll().Where(x => x.IsSuccess && x.Time >= lastInvocationTime)
                                     .Select(x => x.OpenOrderId).ToHashSet();
            //select only non-calculated orders, changed before current invocation time
            var filteredOrders =
                openOrders.Where(x => !calculatedIds.Contains(x.Id) && x.OpenDate <= lastInvocationTime).ToList();

            //detect orders for which last calculation failed and it was closed
            var failedClosedOrders = _overnightSwapHistoryRepository.GetAsync(lastInvocationTime, _currentStartTimestamp)
                                     .GetAwaiter().GetResult()
                                     .Where(x => !x.IsSuccess).Select(x => x.OpenOrderId)
                                     .Except(openOrders.Select(y => y.Id)).ToList();

            if (failedClosedOrders.Any())
            {
                _log.WriteErrorAsync(nameof(OvernightSwapService), nameof(GetOrdersForCalculation), new Exception(
                                         $"Overnight swap calculation failed for some orders and they were closed before recalculation: {string.Join(", ", failedClosedOrders)}."),
                                     DateTime.UtcNow).GetAwaiter().GetResult();
            }

            return(filteredOrders);
        }
Пример #2
0
        public List <OrderContract> GetPositionsByVolume([FromQuery] decimal volume)
        {
            var result = new List <OrderContract>();
            var orders = _ordersReader.GetActive();

            foreach (var order in orders)
            {
                if (order.GetMatchedVolume() >= volume)
                {
                    result.Add(order.ToBaseContract());
                }
            }

            return(result);
        }
Пример #3
0
        /// <summary>
        /// Filter orders that are already calculated
        /// </summary>
        /// <returns></returns>
        private IEnumerable <Order> GetOrdersForCalculation()
        {
            //read orders syncronously
            var openOrders = _orderReader.GetActive();

            //prepare the list of orders
            var lastInvocationTime = CalcLastInvocationTime;
            var lastCalculation    = _overnightSwapCache.GetAll().Where(x => x.Time > lastInvocationTime).ToList();
            var calculatedIds      = lastCalculation.Where(x => x.IsSuccess).SelectMany(x => x.OpenOrderIds).ToHashSet();
            var filteredOrders     = openOrders.Where(x => !calculatedIds.Contains(x.Id));

            //detect orders for which last calculation failed and it was closed
            var failedClosedOrders = lastCalculation.Where(x => !x.IsSuccess).SelectMany(x => x.OpenOrderIds)
                                     .Except(openOrders.Select(y => y.Id)).ToList();

            if (failedClosedOrders.Any())
            {
                _log.WriteErrorAsync(nameof(OvernightSwapService), nameof(GetOrdersForCalculation), new Exception(
                                         $"Overnight swap calculation failed for some orders and they were closed before recalculation: {string.Join(", ", failedClosedOrders)}."),
                                     DateTime.UtcNow).GetAwaiter().GetResult();
            }

            return(filteredOrders);
        }