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

v0.11.0 (Major rework) #29

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
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
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -82,3 +82,6 @@ fabric.properties

# Executable config
/exe/
/ks.jks
/TradeBot.p12
/ts.jks
6 changes: 5 additions & 1 deletion .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 0 additions & 14 deletions config.txt

This file was deleted.

23 changes: 23 additions & 0 deletions configs/example.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
moneyPerTrade: 0.1
trailingSl: 0.1
takeProfit: 0.15

confluenceToOpen: 2
confluenceToClose: 2
indicators:
- !<RSI>
weight: 1
period: 14
positiveMax: 15
positiveMin: 30
negativeMax: 70
negativeMin: 80
- !<MACD>
weight: 1
shortPeriod: 12
longPeriod: 26
signalPeriod: 9
requiredChange: 0.15
- !<DBB>
weight: 1
period: 20
24 changes: 24 additions & 0 deletions configs/full.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#TODO: Everything should be documented in here
moneyPerTrade: 0.1
trailingSl: 0.1
takeProfit: 0.15

confluenceToOpen: 2
# confluenceToClose: 2
indicators:
- !<RSI>
weight: 1
period: 14
positiveMax: 15
positiveMin: 30
negativeMax: 70
negativeMin: 80
- !<MACD>
weight: 1
shortPeriod: 12
longPeriod: 26
signalPeriod: 9
requiredChange: 0.15
- !<DBB>
weight: 1
period: 20
15 changes: 15 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,16 @@
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>2.12.3</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.dataformat</groupId>
<artifactId>jackson-dataformat-yaml</artifactId>
<version>2.12.3</version>
</dependency>
<dependency>
<groupId>com.github.binance-exchange</groupId>
<artifactId>binance-java-api</artifactId>
Expand All @@ -29,5 +39,10 @@
<artifactId>commons-io</artifactId>
<version>2.8.0</version>
</dependency>
<dependency>
<groupId>com.ea.async</groupId>
<artifactId>ea-async</artifactId>
<version>1.2.3</version>
</dependency>
</dependencies>
</project>
25 changes: 0 additions & 25 deletions src/main/java/data/PriceReader.java

This file was deleted.

86 changes: 86 additions & 0 deletions src/main/java/data/config/Config.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
package data.config;

import com.binance.api.client.domain.general.RateLimit;
import com.binance.api.client.domain.general.RateLimitType;
import com.fasterxml.jackson.core.JsonFactory;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.dataformat.yaml.YAMLFactory;
import system.BinanceAPI;
import trading.Currency;
import trading.LocalAccount;
import trading.Trade;

import java.io.File;
import java.io.IOException;
import java.util.Arrays;

public class Config {
private static final int REQUEST_LIMIT = BinanceAPI.get().getExchangeInfo().getRateLimits().stream()
.filter(rateLimit -> rateLimit.getRateLimitType().equals(RateLimitType.REQUEST_WEIGHT))
.findFirst().map(RateLimit::getLimit).orElse(1200);

private final File configFile;
private final ConfigData data;

public Config(String path) throws ConfigException {
configFile = new File(path);
data = readValues();
}

public String name() {
return configFile.getName();
}

public static ConfigData get(Trade trade) {
return trade.getCurrency().getAccount().getInstance().getConfig();
}

public static ConfigData get(Currency currency) {
return currency.getAccount().getInstance().getConfig();
}

public static ConfigData get(LocalAccount account) {
return account.getInstance().getConfig();
}

public static int getRequestLimit() {
return REQUEST_LIMIT;
}

public ConfigData getData() {
return data;
}

public ConfigData readValues() throws ConfigException {
ObjectMapper objectMapper = new ObjectMapper(new YAMLFactory());
try {
return objectMapper.readValue(configFile, ConfigData.class);
} catch (IOException e) {
throw new ConfigException("Failed to read config file due to: " + e.getMessage());
}
}

public void update() throws ConfigException {
data.update(readValues());
}

public String toJson() {
ObjectMapper objectMapper = new ObjectMapper(new JsonFactory());
try {
return objectMapper.writeValueAsString(data);
} catch (JsonProcessingException e) {
return "Failed to serialize config: " + e.getMessage();
}
}

@Override
public String toString() {
ObjectMapper objectMapper = new ObjectMapper(new YAMLFactory());
try {
return objectMapper.writeValueAsString(data);
} catch (JsonProcessingException e) {
return "Failed to serialize config: " + e.getMessage();
}
}
}
102 changes: 102 additions & 0 deletions src/main/java/data/config/ConfigData.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
package data.config;

import java.util.List;

public class ConfigData {
private double moneyPerTrade;
private double trailingSl;
private double takeProfit;
private int confluenceToOpen;
private Integer confluenceToClose; //Number of indicators can't be changed

private List<IndicatorConfig> indicators;

public ConfigData(double moneyPerTrade, double trailingSl, double takeProfit, int confluenceToOpen, Integer confluenceToClose, List<IndicatorConfig> indicators) {
this.moneyPerTrade = moneyPerTrade;
this.trailingSl = trailingSl;
this.takeProfit = takeProfit;
this.confluenceToOpen = confluenceToOpen;
this.confluenceToClose = confluenceToClose;
this.indicators = indicators;
}

public ConfigData() {
}

public void update(ConfigData newConfig) throws ConfigUpdateException {
if (newConfig.getIndicators().size() != indicators.size())
throw new ConfigUpdateException("Number of indicators has changed");
for (int i = 0; i < indicators.size(); i++) {
indicators.get(i).update(newConfig.getIndicators().get(i));
}
moneyPerTrade = newConfig.moneyPerTrade;
trailingSl = newConfig.trailingSl;
takeProfit = newConfig.takeProfit;
confluenceToOpen = newConfig.confluenceToOpen;
confluenceToClose = newConfig.confluenceToClose;
}

public double getMoneyPerTrade() {
return moneyPerTrade;
}

public void setMoneyPerTrade(double moneyPerTrade) {
this.moneyPerTrade = moneyPerTrade;
}

public double getTrailingSl() {
return trailingSl;
}

public void setTrailingSl(double trailingSl) {
this.trailingSl = trailingSl;
}

public double getTakeProfit() {
return takeProfit;
}

public void setTakeProfit(double takeProfit) {
this.takeProfit = takeProfit;
}

public int getConfluenceToOpen() {
return confluenceToOpen;
}

public void setConfluenceToOpen(int confluenceToOpen) {
this.confluenceToOpen = confluenceToOpen;
}

public Integer getConfluenceToClose() {
return confluenceToClose;
}

public void setConfluenceToClose(Integer confluenceToClose) {
this.confluenceToClose = confluenceToClose;
}

public List<IndicatorConfig> getIndicators() {
return indicators;
}

public void setIndicators(List<IndicatorConfig> indicators) {
this.indicators = indicators;
}

public boolean useConfluenceToClose() {
return confluenceToClose != null;
}

@Override
public String toString() {
return "ConfigData{" +
"indicators=" + indicators +
", moneyPerTrade=" + moneyPerTrade +
", trailingSl=" + trailingSl +
", takeProfit=" + takeProfit +
", confluenceToOpen=" + confluenceToOpen +
", confluenceToClose=" + confluenceToClose +
'}';
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package system;
package data.config;

public class ConfigException extends Exception {
public ConfigException(String message) {
Expand Down
7 changes: 7 additions & 0 deletions src/main/java/data/config/ConfigUpdateException.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package data.config;

public class ConfigUpdateException extends ConfigException {
public ConfigUpdateException(String message) {
super("Failed to update config: " + message);
}
}
49 changes: 49 additions & 0 deletions src/main/java/data/config/DbbConfig.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
package data.config;

import indicators.DBB;
import indicators.Indicator;

import java.util.List;

public class DbbConfig extends IndicatorConfig {
private int period;

public DbbConfig(int weight, int period) {
setWeight(weight);
this.period = period;
}

public DbbConfig() {
}

public int getPeriod() {
return period;
}

public void setPeriod(int period) {
this.period = period;
}

@Override
public Indicator toIndicator(List<Double> warmupData) {
return new DBB(warmupData, this);
}

@Override
public void update(IndicatorConfig newConfig) throws ConfigUpdateException {
super.update(newConfig);
DbbConfig newDbbConfig = (DbbConfig) newConfig;
if (newDbbConfig.getPeriod() != period) {
throw new ConfigUpdateException("DBB period has changed from " + period + " to " + newDbbConfig.period
+ ". Period cannot be changed because DBB values are affected by the size of the rolling window.");
}
}

@Override
public String toString() {
return "DbbData{" +
"weight=" + getWeight() +
"period=" + period +
'}';
}
}
Loading