public async Task <AccountHistoryResponse> ByTypes([FromQuery] AccountHistoryRequest request) { request.From = request.From?.ToUniversalTime(); request.To = request.To?.ToUniversalTime(); var clientAccountIds = string.IsNullOrEmpty(request.AccountId) ? (await _accountsRepository.GetAllAsync(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.OpenDate != null && // remove cancel pending order rows created before OrderUpdateType was introduced item.OrderUpdateType == OrderUpdateType.Close); var openPositions = await _ordersSnapshotReaderService.GetActiveByAccountIdsAsync(clientAccountIds); return(new AccountHistoryResponse { Account = accounts.Select(AccountHistoryExtensions.ToBackendContract) .OrderByDescending(item => item.Date).ToArray(), OpenPositions = openPositions.Select(OrderExtensions.ToBackendHistoryContract) .OrderByDescending(item => item.OpenDate).ToArray(), PositionsHistory = orders.Select(OrderHistoryExtensions.ToBackendHistoryContract) .OrderByDescending(item => item.OpenDate).ToArray(), }); }
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); }
public async Task <Dictionary <string, AccountHistoryBackendContract[]> > GetAllAccountsHistory( [FromQuery] string accountId = null, [FromQuery] DateTime?from = null, [FromQuery] DateTime?to = null) { var accountIds = accountId != null ? new[] { accountId } : _accountsCacheService.GetAll().Select(item => item.Id).ToArray(); var history = await _accountHistoryRepository.GetAsync(accountIds, from, to); return(history.GroupBy(i => i.AccountId) .ToDictionary(g => g.Key, g => g.Select(i => i.ToBackendContract()).ToArray())); }
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)); }