From d7d08ab35d783590a69f6c55294e7055eaf3ddd6 Mon Sep 17 00:00:00 2001 From: bh4r4th Date: Sun, 1 Nov 2020 04:18:15 -0800 Subject: [PATCH 1/2] properties, core runner --- .../{CoreApplicationProperties.java => CoreProperties.java} | 1 + 1 file changed, 1 insertion(+) rename src/main/java/dev/opentrading/core/spring/{CoreApplicationProperties.java => CoreProperties.java} (89%) diff --git a/src/main/java/dev/opentrading/core/spring/CoreApplicationProperties.java b/src/main/java/dev/opentrading/core/spring/CoreProperties.java similarity index 89% rename from src/main/java/dev/opentrading/core/spring/CoreApplicationProperties.java rename to src/main/java/dev/opentrading/core/spring/CoreProperties.java index a1ff82a..4ad0c4a 100644 --- a/src/main/java/dev/opentrading/core/spring/CoreApplicationProperties.java +++ b/src/main/java/dev/opentrading/core/spring/CoreProperties.java @@ -4,4 +4,5 @@ @ConfigurationProperties(prefix = "opentrading") public class CoreApplicationProperties { + public static class } From 82a6428b8e3e3e080c505df2f37e03673dd2beba Mon Sep 17 00:00:00 2001 From: bh4r4th Date: Sun, 1 Nov 2020 04:20:39 -0800 Subject: [PATCH 2/2] properties, core runner --- build.gradle | 4 +- settings.gradle | 2 +- .../spring/CoreApplicationConfiguration.java | 2 +- .../core/spring/CoreApplicationRunner.java | 48 +++++++++---- .../core/spring/CoreProperties.java | 29 +++++++- src/main/resources/application.yml | 69 ++++++++++++++++++- 6 files changed, 133 insertions(+), 21 deletions(-) diff --git a/build.gradle b/build.gradle index 47be3d8..8457e0a 100644 --- a/build.gradle +++ b/build.gradle @@ -28,11 +28,11 @@ dependencies { // maven: provided compileOnly 'org.projectlombok:lombok' - implementation 'javax.inject:javax.inject:1' - annotationProcessor 'org.projectlombok:lombok' annotationProcessor 'org.springframework.boot:spring-boot-configuration-processor' + implementation 'javax.inject:javax.inject:1' + testImplementation('org.springframework.boot:spring-boot-starter-test') { exclude group: 'org.junit.vintage', module: 'junit-vintage-engine' } diff --git a/settings.gradle b/settings.gradle index 3ab5c0d..43fc98b 100644 --- a/settings.gradle +++ b/settings.gradle @@ -1 +1 @@ -rootProject.name = 'opentrading-core' +rootProject.name = 'opentrading-core' \ No newline at end of file diff --git a/src/main/java/dev/opentrading/core/spring/CoreApplicationConfiguration.java b/src/main/java/dev/opentrading/core/spring/CoreApplicationConfiguration.java index 1ad7a9e..e1cb7d2 100644 --- a/src/main/java/dev/opentrading/core/spring/CoreApplicationConfiguration.java +++ b/src/main/java/dev/opentrading/core/spring/CoreApplicationConfiguration.java @@ -6,7 +6,7 @@ import org.springframework.context.annotation.Configuration; @Configuration -@EnableConfigurationProperties(CoreApplicationProperties.class) +@EnableConfigurationProperties(CoreProperties.class) public class CoreApplicationConfiguration { @Bean public ExitCodeGenerator exitCodeGenerator() { diff --git a/src/main/java/dev/opentrading/core/spring/CoreApplicationRunner.java b/src/main/java/dev/opentrading/core/spring/CoreApplicationRunner.java index 56a2487..a2c0a19 100644 --- a/src/main/java/dev/opentrading/core/spring/CoreApplicationRunner.java +++ b/src/main/java/dev/opentrading/core/spring/CoreApplicationRunner.java @@ -7,6 +7,10 @@ import org.springframework.core.annotation.Order; import javax.inject.Named; +import java.util.ArrayList; +import java.util.List; +import java.util.concurrent.CompletableFuture; +import java.util.stream.Collectors; /** * First runner @@ -15,12 +19,12 @@ @Named @Order(1) public abstract class CoreApplicationRunner implements ApplicationRunner { - private final CoreApplicationProperties applicationProperties; + private final CoreProperties coreProperties; private final CoreBootstrap coreBootstrap; - protected CoreApplicationRunner(CoreApplicationProperties applicationProperties, CoreBootstrap coreBootstrap) { - this.applicationProperties = applicationProperties; + protected CoreApplicationRunner(CoreProperties applicationProperties, CoreBootstrap coreBootstrap) { + this.coreProperties = applicationProperties; this.coreBootstrap = coreBootstrap; } @@ -39,18 +43,36 @@ public void run(ApplicationArguments args) { coreBootstrap.getTradingInstruments().thenAccept(tradingInstrument -> { log.info("Filtered trading instruments"); - coreBootstrap.initWebSocket().thenAccept(initWebsocket -> { + coreBootstrap. initWebSocket().thenApply(initialized -> { log.info("Initialized WebSocket"); - coreBootstrap.streamTicks().thenAccept(ScheduledStreamingTicks -> { - log.info("Started streaming ticks"); - - coreBootstrap.scheduleTicksAggregator().thenAccept(success -> { - log.info("Scheduled tick aggregator"); - - log.info("Started CoreApplicationRunner."); - }); - }); + List> completableFutureList = new ArrayList<>(); + if (coreProperties.getOptions().isStreamTicks()) { + completableFutureList.add((coreBootstrap. streamTicks() + .thenApply(scheduled -> { + log.info("Scheduled streaming ticks"); + return scheduled; + }))); + } + if (coreProperties.getOptions().isStreamTicksAggregator()) { + completableFutureList.add((coreBootstrap. scheduleTicksAggregator() + .thenApply(scheduled -> { + log.info("Scheduled ticks aggregator"); + return scheduled; + }))); + } + return initialized && completableFutureList.stream() + .map(CompletableFuture::join) + .collect(Collectors.toList()) + .stream() + .reduce(true, Boolean::logicalAnd); + }).whenComplete((initialized, throwable) -> { + if (throwable != null) { + log.error("Exception occurred. exception={}", throwable.getCause().getMessage()); + } + if (initialized) { + log.info("Started CoreApplicationRunner"); + } }); }); }); diff --git a/src/main/java/dev/opentrading/core/spring/CoreProperties.java b/src/main/java/dev/opentrading/core/spring/CoreProperties.java index 4ad0c4a..ce9a6f7 100644 --- a/src/main/java/dev/opentrading/core/spring/CoreProperties.java +++ b/src/main/java/dev/opentrading/core/spring/CoreProperties.java @@ -1,8 +1,31 @@ package dev.opentrading.core.spring; +import lombok.Data; import org.springframework.boot.context.properties.ConfigurationProperties; -@ConfigurationProperties(prefix = "opentrading") -public class CoreApplicationProperties { - public static class +import java.util.List; + +@Data +@ConfigurationProperties(prefix = "opentrading.core") +public class CoreProperties { + Options options; + MarketData marketData; + TradingData tradingData; + + @Data + public static class Options { + private boolean streamTicks; + private boolean streamTicksAggregator; + } + @Data + public static class MarketData { + private String openTime; + private String closeTime; + } + @Data + public static class TradingData { + private String startTime; + private String endTime; + private List instrumentGroups; + } } diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml index c5ed8d2..6bb25f5 100644 --- a/src/main/resources/application.yml +++ b/src/main/resources/application.yml @@ -1 +1,68 @@ -opentrading: \ No newline at end of file +# +# 1. core properties +# +opentrading.core: + options: + streamTicks: false + streamTicksAggregator: false + marketData: + openTime: 09-00 + closeTime: 15-30 + tradingData: + startTime: 09:30 + endTime: 15:00 + instrumentGroups: + - a + - b + orchestrator: +### + + +# +# 2. persistence properties +# +opentrading.persistence: +### + + +# +# 3. data properties +# +opentrading.data: + tickIntevalMillSeconds: 300000 +### + + +# +# 4. compute properties +# +opentrading.compute: +### + + +# +# 5. strategy properties +# +opentrading.strategy +### + + +# +# 6. analyzer properties +# +opentrading.analyzer +### + + +# +# 7. agent properties +# +opentrading.agent +### + + +# +# 8. simulator properties +# +opentrading.simulator +### \ No newline at end of file