use of tech.cassandre.trading.bot.domain.ImportedCandle in project cassandre-trading-bot by cassandre-tech.
the class TickerFluxMock method marketService.
@Bean
@Primary
public MarketService marketService() {
// Removes everything from table.
backtestingCandleRepository.deleteAllInBatch();
// Creates the mock.
marketServiceBacktestingImplementation = new MarketServiceBacktestingImplementation(orderFlux, tradeFlux, orderRepository, tradeRepository, backtestingCandleRepository);
// Getting the list of files to import and insert them in database.
logger.info("Importing candles for backtesting...");
Set<CurrencyPairDTO> currencyPairUsed = new HashSet<>();
getCandlesFilesToLoad().stream().filter(resource -> resource.getFilename() != null).peek(resource -> logger.info("Importing {}...", resource.getFilename())).forEach(resource -> {
try {
// Insert the tickers in database.
AtomicLong sequence = new AtomicLong(1);
new CsvToBeanBuilder<ImportedCandle>(Files.newBufferedReader(resource.getFile().toPath())).withType(ImportedCandle.class).withIgnoreLeadingWhiteSpace(true).build().parse().forEach(importedCandle -> {
logger.debug("Importing candle {}", importedCandle);
BacktestingCandle candle = backtestingTickerMapper.mapToBacktestingCandle(importedCandle);
// Specific fields in Backtesting candle.
BacktestingCandleId id = new BacktestingCandleId();
id.setTestSessionId(marketServiceBacktestingImplementation.getTestSessionId());
id.setResponseSequenceId(sequence.getAndIncrement());
id.setCurrencyPair(importedCandle.getCurrencyPair());
candle.setId(id);
// Save in database.
backtestingCandleRepository.save(candle);
// We build a list of currency pairs listed in files.
currencyPairUsed.add(id.getCurrencyPairDTO());
});
} catch (IOException e) {
logger.error("Impossible to load candles for backtesting: {}", e.getMessage());
}
});
// Setting the flux size of each currency pair.
currencyPairUsed.forEach(currencyPairDTO -> marketServiceBacktestingImplementation.getFluxSize().put(currencyPairDTO, backtestingCandleRepository.findByIdCurrencyPair(currencyPairDTO.toString()).size()));
return marketServiceBacktestingImplementation;
}
use of tech.cassandre.trading.bot.domain.ImportedCandle in project cassandre-trading-bot by cassandre-tech.
the class StrategiesAutoConfiguration method loadCandlesFromFiles.
/**
* Load candles in database.
*/
private void loadCandlesFromFiles() {
// Deleting everything before import.
importedCandleRepository.deleteAllInBatch();
// Getting the list of files to import and insert them in database.
logger.info("Importing candles...");
AtomicLong counter = new AtomicLong(0);
getFilesToLoad("classpath*:candles-to-import*csv").stream().filter(resource -> resource.getFilename() != null).peek(resource -> logger.info("Importing candles from {}", resource.getFilename())).forEach(resource -> {
try {
// Insert the tickers in database.
new CsvToBeanBuilder<ImportedCandle>(Files.newBufferedReader(resource.getFile().toPath())).withType(ImportedCandle.class).withIgnoreLeadingWhiteSpace(true).build().parse().forEach(importedCandle -> {
logger.debug("Importing candle {}", importedCandle);
importedCandle.setUid(counter.incrementAndGet());
importedCandleRepository.save(importedCandle);
});
} catch (IOException e) {
logger.error("Impossible to load imported candles: {}", e.getMessage());
}
});
logger.info("{} candles imported", importedCandleRepository.count());
}
Aggregations