Search in sources :

Example 1 with ImportedTicker

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());
}
Also used : Arrays(java.util.Arrays) RequiredArgsConstructor(lombok.RequiredArgsConstructor) TradeService(tech.cassandre.trading.bot.service.TradeService) ExchangeParameters(tech.cassandre.trading.bot.util.parameters.ExchangeParameters) PathMatchingResourcePatternResolver(org.springframework.core.io.support.PathMatchingResourcePatternResolver) StrategyRepository(tech.cassandre.trading.bot.repository.StrategyRepository) BASIC_STRATEGY(tech.cassandre.trading.bot.dto.strategy.StrategyTypeDTO.BASIC_STRATEGY) TradeFlux(tech.cassandre.trading.bot.batch.TradeFlux) CsvToBeanBuilder(com.opencsv.bean.CsvToBeanBuilder) EnableConfigurationProperties(org.springframework.boot.context.properties.EnableConfigurationProperties) Map(java.util.Map) OrderFlux(tech.cassandre.trading.bot.batch.OrderFlux) Resource(org.springframework.core.io.Resource) ImportedTicker(tech.cassandre.trading.bot.domain.ImportedTicker) PositionDTO(tech.cassandre.trading.bot.dto.position.PositionDTO) UserService(tech.cassandre.trading.bot.service.UserService) AccountDTO(tech.cassandre.trading.bot.dto.user.AccountDTO) PositionRepository(tech.cassandre.trading.bot.repository.PositionRepository) ConfigurationException(tech.cassandre.trading.bot.util.exception.ConfigurationException) PositionService(tech.cassandre.trading.bot.service.PositionService) Set(java.util.Set) ZERO(java.math.BigDecimal.ZERO) TickerFlux(tech.cassandre.trading.bot.batch.TickerFlux) TradeDTO(tech.cassandre.trading.bot.dto.trade.TradeDTO) Collectors(java.util.stream.Collectors) OrderDTO(tech.cassandre.trading.bot.dto.trade.OrderDTO) UserDTO(tech.cassandre.trading.bot.dto.user.UserDTO) Configuration(org.springframework.context.annotation.Configuration) List(java.util.List) OrderRepository(tech.cassandre.trading.bot.repository.OrderRepository) Stream(java.util.stream.Stream) PositionServiceCassandreImplementation(tech.cassandre.trading.bot.service.PositionServiceCassandreImplementation) CassandreStrategy(tech.cassandre.trading.bot.strategy.CassandreStrategy) PostConstruct(javax.annotation.PostConstruct) Optional(java.util.Optional) CassandreStrategyInterface(tech.cassandre.trading.bot.strategy.CassandreStrategyInterface) TradeRepository(tech.cassandre.trading.bot.repository.TradeRepository) TickerDTO(tech.cassandre.trading.bot.dto.market.TickerDTO) BASIC_TA4J_STRATEGY(tech.cassandre.trading.bot.dto.strategy.StrategyTypeDTO.BASIC_TA4J_STRATEGY) Strategy(tech.cassandre.trading.bot.domain.Strategy) BasicCassandreStrategy(tech.cassandre.trading.bot.strategy.BasicCassandreStrategy) HashSet(java.util.HashSet) OPENING(tech.cassandre.trading.bot.dto.position.PositionStatusDTO.OPENING) StrategyDTO(tech.cassandre.trading.bot.dto.strategy.StrategyDTO) ConnectableFlux(reactor.core.publisher.ConnectableFlux) PositionFlux(tech.cassandre.trading.bot.batch.PositionFlux) CurrencyPairDTO(tech.cassandre.trading.bot.dto.util.CurrencyPairDTO) ExchangeService(tech.cassandre.trading.bot.service.ExchangeService) BaseConfiguration(tech.cassandre.trading.bot.util.base.configuration.BaseConfiguration) ImportedTickersRepository(tech.cassandre.trading.bot.repository.ImportedTickersRepository) BasicTa4jCassandreStrategy(tech.cassandre.trading.bot.strategy.BasicTa4jCassandreStrategy) Files(java.nio.file.Files) IOException(java.io.IOException) CLOSING(tech.cassandre.trading.bot.dto.position.PositionStatusDTO.CLOSING) ApplicationContext(org.springframework.context.ApplicationContext) AtomicLong(java.util.concurrent.atomic.AtomicLong) AccountFlux(tech.cassandre.trading.bot.batch.AccountFlux) Bean(org.springframework.context.annotation.Bean) Collections(java.util.Collections) AtomicLong(java.util.concurrent.atomic.AtomicLong) IOException(java.io.IOException) ImportedTicker(tech.cassandre.trading.bot.domain.ImportedTicker)

Example 2 with ImportedTicker

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());
}
Also used : Arrays(java.util.Arrays) RequiredArgsConstructor(lombok.RequiredArgsConstructor) TradeService(tech.cassandre.trading.bot.service.TradeService) ExchangeParameters(tech.cassandre.trading.bot.util.parameters.ExchangeParameters) PathMatchingResourcePatternResolver(org.springframework.core.io.support.PathMatchingResourcePatternResolver) StrategyRepository(tech.cassandre.trading.bot.repository.StrategyRepository) CassandreStrategyInterface(tech.cassandre.trading.bot.strategy.internal.CassandreStrategyInterface) TradeFlux(tech.cassandre.trading.bot.batch.TradeFlux) CsvToBeanBuilder(com.opencsv.bean.CsvToBeanBuilder) EnableConfigurationProperties(org.springframework.boot.context.properties.EnableConfigurationProperties) Map(java.util.Map) OrderFlux(tech.cassandre.trading.bot.batch.OrderFlux) Resource(org.springframework.core.io.Resource) ImportedTicker(tech.cassandre.trading.bot.domain.ImportedTicker) PositionDTO(tech.cassandre.trading.bot.dto.position.PositionDTO) UserService(tech.cassandre.trading.bot.service.UserService) AccountDTO(tech.cassandre.trading.bot.dto.user.AccountDTO) PositionRepository(tech.cassandre.trading.bot.repository.PositionRepository) ConfigurationException(tech.cassandre.trading.bot.util.exception.ConfigurationException) PositionService(tech.cassandre.trading.bot.service.PositionService) Set(java.util.Set) ZERO(java.math.BigDecimal.ZERO) TickerFlux(tech.cassandre.trading.bot.batch.TickerFlux) TradeDTO(tech.cassandre.trading.bot.dto.trade.TradeDTO) Collectors(java.util.stream.Collectors) OrderDTO(tech.cassandre.trading.bot.dto.trade.OrderDTO) UserDTO(tech.cassandre.trading.bot.dto.user.UserDTO) ImportedTickerRepository(tech.cassandre.trading.bot.repository.ImportedTickerRepository) Configuration(org.springframework.context.annotation.Configuration) ImportedCandle(tech.cassandre.trading.bot.domain.ImportedCandle) List(java.util.List) OrderRepository(tech.cassandre.trading.bot.repository.OrderRepository) Stream(java.util.stream.Stream) CassandreStrategy(tech.cassandre.trading.bot.strategy.CassandreStrategy) PostConstruct(javax.annotation.PostConstruct) Optional(java.util.Optional) TradeRepository(tech.cassandre.trading.bot.repository.TradeRepository) TickerDTO(tech.cassandre.trading.bot.dto.market.TickerDTO) Strategy(tech.cassandre.trading.bot.domain.Strategy) HashSet(java.util.HashSet) OPENING(tech.cassandre.trading.bot.dto.position.PositionStatusDTO.OPENING) StrategyDTO(tech.cassandre.trading.bot.dto.strategy.StrategyDTO) ConnectableFlux(reactor.core.publisher.ConnectableFlux) PositionFlux(tech.cassandre.trading.bot.batch.PositionFlux) ImportedCandleRepository(tech.cassandre.trading.bot.repository.ImportedCandleRepository) CurrencyPairDTO(tech.cassandre.trading.bot.dto.util.CurrencyPairDTO) ExchangeService(tech.cassandre.trading.bot.service.ExchangeService) BaseConfiguration(tech.cassandre.trading.bot.util.base.configuration.BaseConfiguration) Files(java.nio.file.Files) CassandreStrategyDependencies(tech.cassandre.trading.bot.strategy.internal.CassandreStrategyDependencies) IOException(java.io.IOException) CassandreStrategyConfiguration(tech.cassandre.trading.bot.strategy.internal.CassandreStrategyConfiguration) CLOSING(tech.cassandre.trading.bot.dto.position.PositionStatusDTO.CLOSING) ApplicationContext(org.springframework.context.ApplicationContext) AtomicLong(java.util.concurrent.atomic.AtomicLong) AccountFlux(tech.cassandre.trading.bot.batch.AccountFlux) Collections(java.util.Collections) AtomicLong(java.util.concurrent.atomic.AtomicLong) IOException(java.io.IOException) ImportedTicker(tech.cassandre.trading.bot.domain.ImportedTicker)

Aggregations

CsvToBeanBuilder (com.opencsv.bean.CsvToBeanBuilder)2 IOException (java.io.IOException)2 ZERO (java.math.BigDecimal.ZERO)2 Files (java.nio.file.Files)2 Arrays (java.util.Arrays)2 Collections (java.util.Collections)2 HashSet (java.util.HashSet)2 List (java.util.List)2 Map (java.util.Map)2 Optional (java.util.Optional)2 Set (java.util.Set)2 AtomicLong (java.util.concurrent.atomic.AtomicLong)2 Collectors (java.util.stream.Collectors)2 Stream (java.util.stream.Stream)2 PostConstruct (javax.annotation.PostConstruct)2 RequiredArgsConstructor (lombok.RequiredArgsConstructor)2 EnableConfigurationProperties (org.springframework.boot.context.properties.EnableConfigurationProperties)2 ApplicationContext (org.springframework.context.ApplicationContext)2 Configuration (org.springframework.context.annotation.Configuration)2 Resource (org.springframework.core.io.Resource)2