use of tech.cassandre.trading.bot.domain.BacktestingCandleId 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;
}
Aggregations