use of tech.cassandre.trading.bot.domain.ImportedTicker in project cassandre-trading-bot by cassandre-tech.
the class StrategiesAutoConfiguration method loadImportedTickers.
/**
* Load imported tickers into database.
*/
private void loadImportedTickers() {
// Deleting everything before import.
importedTickersRepository.deleteAllInBatch();
// Getting the list of files to import and insert them in database.
logger.info("Importing tickers...");
AtomicLong counter = new AtomicLong(0);
getFilesToLoad().parallelStream().filter(resource -> resource.getFilename() != null).peek(resource -> logger.info("Importing file {}.", resource.getFilename())).forEach(resource -> {
try {
// Insert the tickers in database.
new CsvToBeanBuilder<ImportedTicker>(Files.newBufferedReader(resource.getFile().toPath())).withType(ImportedTicker.class).withIgnoreLeadingWhiteSpace(true).build().parse().forEach(importedTicker -> {
logger.debug("Importing ticker {}.", importedTicker);
importedTicker.setId(counter.incrementAndGet());
importedTickersRepository.save(importedTicker);
});
} catch (IOException e) {
logger.error("Impossible to load imported tickers: {}.", e.getMessage());
}
});
logger.info("{} tickers imported.", importedTickersRepository.count());
}
use of tech.cassandre.trading.bot.domain.ImportedTicker in project cassandre-trading-bot by cassandre-tech.
the class StrategiesAutoConfiguration method loadTickersFromFiles.
/**
* Load tickers in database.
*/
private void loadTickersFromFiles() {
// Deleting everything before import.
importedTickerRepository.deleteAllInBatch();
// Getting the list of files to import and insert them in database.
logger.info("Importing tickers...");
AtomicLong counter = new AtomicLong(0);
getFilesToLoad("classpath*:tickers-to-import*csv").stream().filter(resource -> resource.getFilename() != null).peek(resource -> logger.info("Importing tickers from {}", resource.getFilename())).forEach(resource -> {
try {
// Insert the tickers in database.
new CsvToBeanBuilder<ImportedTicker>(Files.newBufferedReader(resource.getFile().toPath())).withType(ImportedTicker.class).withIgnoreLeadingWhiteSpace(true).build().parse().forEach(importedTicker -> {
logger.debug("Importing ticker {}", importedTicker);
importedTicker.setUid(counter.incrementAndGet());
importedTickerRepository.save(importedTicker);
});
} catch (IOException e) {
logger.error("Impossible to load imported tickers: {}", e.getMessage());
}
});
logger.info("{} tickers imported", importedTickerRepository.count());
}
Aggregations