Exemplo n.º 1
0
        public async Task <AccountHistoryBackendResponse> GetAccountHistory(string clientId, string accountId)
        {
            var now = DateTime.UtcNow;

            var accounts = (await _accountsHistoryRepository.GetAsync(new[] { accountId }, now.AddYears(-1), now))
                           .Where(item => item.Type != AccountHistoryType.OrderClosed)
                           .OrderByDescending(item => item.Date);

            var historyOrders = (await _ordersHistoryRepository.GetHistoryAsync(clientId, new[] { accountId }, now.AddYears(-1), now))
                                .Where(item => item.Status != OrderStatus.Rejected);

            var openPositions = _ordersCache.ActiveOrders.GetOrdersByAccountIds(accountId);

            return(BackendContractFactory.CreateAccountHistoryBackendResponse(accounts, openPositions, historyOrders));
        }
Exemplo n.º 2
0
        public async Task <AccountHistoryBackendResponse> GetAccountHistory([FromBody] AccountHistoryBackendRequest request)
        {
            var clientAccountIds = string.IsNullOrEmpty(request.AccountId)
                    ? _accountsCacheService.GetAll(request.ClientId).Select(item => item.Id).ToArray()
                    : new[] { request.AccountId };

            var accounts = (await _accountsHistoryRepository.GetAsync(clientAccountIds, request.From, request.To))
                           .Where(item => item.Type != AccountHistoryType.OrderClosed);

            var orders = (await _ordersHistoryRepository.GetHistoryAsync(request.ClientId, clientAccountIds, request.From, request.To))
                         .Where(item => item.Status != OrderStatus.Rejected);

            var openPositions = _ordersCache.ActiveOrders.GetOrdersByAccountIds(clientAccountIds).ToList();

            var result = BackendContractFactory.CreateAccountHistoryBackendResponse(accounts, openPositions, orders);

            return(result);
        }