Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bxbot restapi #37

Merged
merged 17 commits into from
Sep 10, 2016
Merged
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
25 changes: 15 additions & 10 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -12,30 +12,35 @@ buildscript {
}
}

ext.versions = [
springBootVersion:'1.4.0.RELEASE',
springCoreVersion:'4.3.2.RELEASE'
]

ext.libraries = [
spring_boot_starter: dependencies.create("org.springframework.boot:spring-boot-starter:1.4.0.RELEASE") {
spring_boot_starter: dependencies.create("org.springframework.boot:spring-boot-starter:" + ext.versions.springBootVersion) {
exclude module: "spring-boot-starter-logging"
force = true
},
spring_boot_starter_log4j2: dependencies.create("org.springframework.boot:spring-boot-starter-log4j2:1.4.0.RELEASE"),
spring_boot_starter_web: dependencies.create("org.springframework.boot:spring-boot-starter-web:1.4.0.RELEASE") {
spring_boot_starter_log4j2: dependencies.create("org.springframework.boot:spring-boot-starter-log4j2:" + ext.versions.springBootVersion),
spring_boot_starter_web: dependencies.create("org.springframework.boot:spring-boot-starter-web:" + ext.versions.springBootVersion) {
exclude module: "logback-classic"
force = true
},
spring_boot_starter_actuator: dependencies.create("org.springframework.boot:spring-boot-starter-actuator:1.4.0.RELEASE") {
spring_boot_starter_actuator: dependencies.create("org.springframework.boot:spring-boot-starter-actuator:" + ext.versions.springBootVersion) {
exclude module: "logback-classic"
force = true
},
spring_boot_starter_security: dependencies.create("org.springframework.boot:spring-boot-starter-security:1.4.0.RELEASE") {
spring_boot_starter_security: dependencies.create("org.springframework.boot:spring-boot-starter-security:" + ext.versions.springBootVersion) {
exclude module: "logback-classic"
force = true
},
spring_boot_starter_data_jpa: dependencies.create("org.springframework.boot:spring-boot-starter-data-jpa:1.4.0.RELEASE") {
spring_boot_starter_data_jpa: dependencies.create("org.springframework.boot:spring-boot-starter-data-jpa:" + ext.versions.springBootVersion) {
exclude module: "logback-classic"
force = true
},
spring_core: dependencies.create("org.springframework:spring-core:4.3.1.RELEASE"),
spring_tx: dependencies.create("org.springframework:spring-tx:4.3.1.RELEASE"),
spring_core: dependencies.create("org.springframework:spring-core:" + ext.versions.springCoreVersion),
spring_tx: dependencies.create("org.springframework:spring-tx:" + ext.versions.springCoreVersion),
spring_security_oauth2: dependencies.create("org.springframework.security.oauth:spring-security-oauth2:2.0.11.RELEASE"),
google_guava: dependencies.create("com.google.guava:guava:19.0"),
google_gson: dependencies.create("com.google.code.gson:gson:2.7"),
Expand All @@ -52,7 +57,7 @@ ext.libraries = [
},
objenesis: dependencies.create("org.objenesis:objenesis:2.1"),
cglib_nodep: dependencies.create("cglib:cglib-nodep:2.2.2"),
spring_boot_starter_test: dependencies.create("org.springframework.boot:spring-boot-starter-test:1.4.0.RELEASE")
spring_boot_starter_test: dependencies.create("org.springframework.boot:spring-boot-starter-test:" + ext.versions.springBootVersion)
]

allprojects {
Expand All @@ -61,7 +66,7 @@ allprojects {
apply plugin: 'maven'

group = 'com.gazbert.bxbot'
version = '0.5-beta-SNAPSHOT'
version = '0.5-beta-SNAPSHOT'
}

subprojects {
Expand Down
2 changes: 1 addition & 1 deletion bxbot-app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ description = 'BX-bot App'

apply plugin: 'spring-boot'
bootRepackage {
mainClass = 'com.gazbert.bxbot.core.BXBot'
mainClass = 'com.gazbert.bxbot.BXBot'
}

dependencies {
Expand Down
2 changes: 1 addition & 1 deletion bxbot-app/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
</parent>
<properties>
<springframework.version>4.3.1.RELEASE</springframework.version>
<start-class>com.gazbert.bxbot.core.BXBot</start-class>
<start-class>com.gazbert.bxbot.BXBot</start-class>
</properties>
<dependencies>
<dependency>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/

package com.gazbert.bxbot.core;
package com.gazbert.bxbot;

import com.gazbert.bxbot.core.engine.TradingEngine;
import org.springframework.beans.factory.annotation.Autowired;
Expand All @@ -41,10 +41,8 @@ public class BXBot implements CommandLineRunner {
private TradingEngine tradingEngine;

/*
* Can't use constructor injection within @SpringBootApplication:
* Don't seem to be able to use constructor injection within @SpringBootApplication:
* http://stackoverflow.com/questions/36696803/spring-boot-no-default-constructor-found-on-springbootapplication-class
*
* New feature coming in Boot 4.3: https://jira.spring.io/browse/SPR-13471
*/
// @Autowired
// public BXBot(TradingEngine tradingEngine) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public interface MarketConfigRepository {

MarketConfig findById(String id);

MarketConfig saveMarket(MarketConfig config);
MarketConfig createMarket(MarketConfig config);

MarketConfig updateMarket(MarketConfig config);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,9 @@ public interface StrategyConfigRepository {

StrategyConfig findById(String id);

StrategyConfig updateStrategy(String id, StrategyConfig config);
StrategyConfig updateStrategy(StrategyConfig config);

StrategyConfig saveStrategy(StrategyConfig config);
StrategyConfig createStrategy(StrategyConfig config);

StrategyConfig deleteStrategyById(String id);
}
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,8 @@ public MarketConfig findById(String id) {
}

@Override
public MarketConfig saveMarket(MarketConfig config) {
throw new UnsupportedOperationException("saveMarket not coded yet!");
public MarketConfig createMarket(MarketConfig config) {
throw new UnsupportedOperationException("createMarket not coded yet!");
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@
import org.springframework.transaction.annotation.Transactional;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.stream.Collectors;

Expand Down Expand Up @@ -78,7 +80,7 @@ public StrategyConfig findById(String id) {
}

@Override
public StrategyConfig updateStrategy(String id, StrategyConfig config) {
public StrategyConfig updateStrategy(StrategyConfig config) {

LOG.info(() -> "About to update: " + config);

Expand All @@ -87,7 +89,7 @@ public StrategyConfig updateStrategy(String id, StrategyConfig config) {

final List<StrategyType> strategyTypes = internalStrategiesConfig.getStrategies()
.stream()
.filter((item) -> item.getId().equals(id))
.filter((item) -> item.getId().equals(config.getId()))
.distinct()
.collect(Collectors.toList());

Expand All @@ -104,22 +106,74 @@ public StrategyConfig updateStrategy(String id, StrategyConfig config) {
return adaptInternalToExternalConfig(
updatedInternalStrategiesConfig.getStrategies()
.stream()
.filter((item) -> item.getId().equals(id))
.filter((item) -> item.getId().equals(config.getId()))
.distinct()
.collect(Collectors.toList()));
} else {
// no matching id :-(
return new StrategyConfig();
}
}

@Override
public StrategyConfig saveStrategy(StrategyConfig config) {
throw new UnsupportedOperationException("saveStrategy not coded yet");
public StrategyConfig createStrategy(StrategyConfig config) {

final TradingStrategiesType internalStrategiesConfig = ConfigurationManager.loadConfig(TradingStrategiesType.class,
STRATEGIES_CONFIG_XML_FILENAME, STRATEGIES_CONFIG_XSD_FILENAME);

final List<StrategyType> strategyTypes = internalStrategiesConfig.getStrategies()
.stream()
.filter((item) -> item.getId().equals(config.getId()))
.distinct()
.collect(Collectors.toList());

if (strategyTypes.isEmpty()) {

internalStrategiesConfig.getStrategies().add(adaptExternalToInternalConfig(config));
ConfigurationManager.saveConfig(TradingStrategiesType.class, internalStrategiesConfig,
STRATEGIES_CONFIG_XML_FILENAME);

final TradingStrategiesType updatedInternalStrategiesConfig = ConfigurationManager.loadConfig(
TradingStrategiesType.class, STRATEGIES_CONFIG_XML_FILENAME, STRATEGIES_CONFIG_XSD_FILENAME);

return adaptInternalToExternalConfig(
updatedInternalStrategiesConfig.getStrategies()
.stream()
.filter((item) -> item.getId().equals(config.getId()))
.distinct()
.collect(Collectors.toList()));
} else {
// already have a matching id :-(
return new StrategyConfig();
}
}

@Override
public StrategyConfig deleteStrategyById(String id) {
throw new UnsupportedOperationException("deleteStrategyById not coded yet");

LOG.info(() -> "Deleting config for Strategy id: " + id);

final TradingStrategiesType internalStrategiesConfig = ConfigurationManager.loadConfig(TradingStrategiesType.class,
STRATEGIES_CONFIG_XML_FILENAME, STRATEGIES_CONFIG_XSD_FILENAME);

final List<StrategyType> strategyTypes = internalStrategiesConfig.getStrategies()
.stream()
.filter((item) -> item.getId().equals(id))
.distinct()
.collect(Collectors.toList());

if (!strategyTypes.isEmpty()) {

final StrategyType strategyToRemove = strategyTypes.get(0); // will only be 1 unique strat
internalStrategiesConfig.getStrategies().remove(strategyToRemove);
ConfigurationManager.saveConfig(TradingStrategiesType.class, internalStrategiesConfig,
STRATEGIES_CONFIG_XML_FILENAME);

return adaptInternalToExternalConfig(Collections.singletonList(strategyToRemove));
} else {
// no matching id :-(
return new StrategyConfig();
}
}

// ------------------------------------------------------------------------------------------------
Expand Down
Loading