Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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'
}
Expand Down
2 changes: 1 addition & 1 deletion settings.gradle
Original file line number Diff line number Diff line change
@@ -1 +1 @@
rootProject.name = 'opentrading-core'
rootProject.name = 'opentrading-core'
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import org.springframework.context.annotation.Configuration;

@Configuration
@EnableConfigurationProperties(CoreApplicationProperties.class)
@EnableConfigurationProperties(CoreProperties.class)
public class CoreApplicationConfiguration {
@Bean
public ExitCodeGenerator exitCodeGenerator() {
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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;
}

Expand All @@ -39,18 +43,36 @@ public void run(ApplicationArguments args) {
coreBootstrap.getTradingInstruments().thenAccept(tradingInstrument -> {
log.info("Filtered trading instruments");

coreBootstrap.initWebSocket().thenAccept(initWebsocket -> {
coreBootstrap.<Boolean> initWebSocket().thenApply(initialized -> {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we don't need to make everything a completable future here like login, getMargin, getAllInstruments. If we're going to block on them all anyway, this chain of futures just adds boilerplate and a bunch of extra nesting. We should maybe only wrap things in futures if we want to launch tasks in parallel or need other specific capabilities.

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<CompletableFuture<Boolean>> completableFutureList = new ArrayList<>();
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We’re not doing any tick aggregation right now, right? Can we delete these, and start the scheduler here?

if (coreProperties.getOptions().isStreamTicks()) {
completableFutureList.add((coreBootstrap.<Boolean> streamTicks()
.thenApply(scheduled -> {
log.info("Scheduled streaming ticks");
return scheduled;
})));
}
if (coreProperties.getOptions().isStreamTicksAggregator()) {
completableFutureList.add((coreBootstrap.<Boolean> 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");
}
});
});
});
Expand Down
31 changes: 31 additions & 0 deletions src/main/java/dev/opentrading/core/spring/CoreProperties.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package dev.opentrading.core.spring;

import lombok.Data;
import org.springframework.boot.context.properties.ConfigurationProperties;

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<String> instrumentGroups;
}
}
69 changes: 68 additions & 1 deletion src/main/resources/application.yml
Original file line number Diff line number Diff line change
@@ -1 +1,68 @@
opentrading:
#
# 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
###