예제 #1
0
        public async Task <Dictionary <string, string> > CancelGroupAsync([FromQuery] string accountId,
                                                                          [FromQuery] string assetPairId = null,
                                                                          [FromQuery] OrderDirectionContract?direction = null,
                                                                          [FromQuery] bool includeLinkedToPositions    = false,
                                                                          [FromBody] OrderCancelRequest request        = null)
        {
            accountId.RequiredNotNullOrWhiteSpace(nameof(accountId));

            var failedOrderIds = new Dictionary <string, string>();

            foreach (var order in _ordersCache.GetPending()
                     .Where(x => x.AccountId == accountId &&
                            (string.IsNullOrEmpty(assetPairId) || x.AssetPairId == assetPairId) &&
                            (direction == null || x.Direction == direction.ToType <OrderDirection>()) &&
                            (includeLinkedToPositions || string.IsNullOrEmpty(x.ParentPositionId))))
            {
                try
                {
                    await CancelAsync(order.Id, request, accountId);
                }
                catch (Exception exception)
                {
                    await _log.WriteWarningAsync(nameof(OrdersController), nameof(CancelGroupAsync),
                                                 $"Failed to cancel order {order.Id}", exception);

                    failedOrderIds.Add(order.Id, exception.Message);
                }
            }

            return(failedOrderIds);
        }
예제 #2
0
        public Task Invoke()
        {
            using (_contextFactory.GetWriteSyncContext($"{nameof(PendingMarginInstrumentMigration)}.{nameof(Invoke)}"))
            {
                //open orders from cache
                var allOrders     = _orderCache.GetAll().ToList();
                var pendingOrders = _orderCache.GetPending().Where(x => string.IsNullOrEmpty(x.MarginCalcInstrument)).ToList();
                if (!pendingOrders.Any())
                {
                    return(Task.CompletedTask);
                }

                foreach (var order in pendingOrders)
                {
                    HandleOrder(order);
                }

                //reinit orders cache with modified data
                _orderCache.InitOrders(allOrders);
            }

            return(Task.CompletedTask);
        }