public async Task RecalculateAsync(string settlementId, string userId) { Settlement settlement = await GetByIdAsync(settlementId); if (settlement.Status != SettlementStatus.New) { throw new InvalidOperationException("Only new settlement can be recalculated"); } IndexPrice indexPrice = await _indexPriceService.GetByIndexAsync(settlement.IndexName); if (indexPrice == null) { throw new InvalidOperationException("Index price not found"); } settlement.Price = indexPrice.Price; await CalculateAssetSettlementsAsync(settlement, indexPrice.Weights); await ValidateBalanceAsync(settlement); await _settlementRepository.ReplaceAsync(settlement); _log.InfoWithDetails("Settlement recalculated", new { settlement, userId }); }