class RateService {

	@Transactional
	public void addHistoricalRates(List<Quote> quotes) {

		List<HistoricalRate> ratesToAdd = new ArrayList<>();

		for (Quote quote : quotes) {

			BooleanExpression exp = historicalRate.fromcur.code.eq(quote.getCode())
					.and(historicalRate.tocur.code.eq(quote.getCurrency()))
					.and(historicalRate.date.eq(quote.getTime()));

			if (!historicalRateRepository.exists(exp)) {
				SymbolEntity symbolCode = symbolRepository.findById(quote.getCode()).get();
				SymbolEntity symbolCurrency = symbolRepository.findById(quote.getCurrency()).get();

				ratesToAdd.add(new HistoricalRate(symbolCode, symbolCurrency, quote.getPrice(), quote.getTime()));
			}
		}

		historicalRateRepository.saveAll(ratesToAdd);

		log.debug("{} saved", ratesToAdd.size());
	}

}