Minor refactoring (organizing in packages)

This commit is contained in:
Dennis Thiessen
2017-07-13 22:46:30 +02:00
parent e119a8c354
commit 0a50e8babb
11 changed files with 49 additions and 55 deletions

View File

@@ -6,10 +6,16 @@
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src/main/java" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/main/resources" type="java-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/test/java" isTestSource="true" />
<excludeFolder url="file://$MODULE_DIR$/target" />
</content>
<orderEntry type="jdk" jdkName="1.8" jdkType="JavaSDK" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="library" name="Maven: com.googlecode.json-simple:json-simple:1.1.1" level="project" />
<orderEntry type="library" name="Maven: junit:junit:4.10" level="project" />
<orderEntry type="library" name="Maven: org.hamcrest:hamcrest-core:1.1" level="project" />
<orderEntry type="library" name="Maven: org.jgrapht:jgrapht-core:1.0.1" level="project" />
<orderEntry type="library" name="Maven: jgraph:jgraph:5.13.0.0" level="project" />
<orderEntry type="library" name="Maven: com.mashape.unirest:unirest-java:1.4.9" level="project" />
<orderEntry type="library" name="Maven: org.apache.httpcomponents:httpclient:4.3.6" level="project" />
<orderEntry type="library" name="Maven: org.apache.httpcomponents:httpcore:4.3.3" level="project" />

View File

@@ -1,11 +0,0 @@
public class CryptoCoin {
public String shortname;
public double price;
public double change5Min;
public CryptoCoin(String shortname, Double price){
this.shortname = shortname;
this.price = price;
}
}

View File

@@ -5,6 +5,13 @@ import com.mashape.unirest.http.exceptions.UnirestException;
import org.apache.commons.math3.stat.regression.SimpleRegression;
import org.json.JSONArray;
import org.json.JSONObject;
import storage.Funds;
import storage.Order;
import storage.OrderHistory;
import storage.TradeHistory;
import utils.DrawGraph;
import utils.MovingAverage;
import javax.swing.*;
import java.awt.*;
@@ -57,7 +64,7 @@ public class Main {
public static void main(String[] args) throws InterruptedException {
System.out.println("Starting DekaBot...");
System.out.println("Starting simulation... initializing Funds...");
System.out.println("Starting simulation... initializing storage.Funds...");
funds.addFund("ETH", VALUE_ETH);
funds.addFund("EUR", VALUE_EUR);
@@ -139,7 +146,7 @@ public class Main {
if (order.ordertype != null) doOrder(order);
buyindicator = 0;
System.out.println("Funds: " + funds.getFundsStringOutput());
System.out.println("storage.Funds: " + funds.getFundsStringOutput());
srbuyvolume.clear();
srsellvolume.clear();
@@ -184,7 +191,7 @@ public class Main {
}
break;
default:
System.out.println("ERROR: Order not recognized: " + order.type);
System.out.println("ERROR: storage.Order not recognized: " + order.type);
break;
}
@@ -426,7 +433,7 @@ public class Main {
if (order.ordertype != null) doOrder(order);
buyindicator = 0;
if(!regressionbacktest) System.out.println("Funds: " + funds.getFundsStringOutput());
if(!regressionbacktest) System.out.println("storage.Funds: " + funds.getFundsStringOutput());
srbuyvolume.clear();
srsellvolume.clear();
@@ -437,7 +444,7 @@ public class Main {
counter++;
}
System.out.println("DrawGraph -- "+graphValues1.size());
System.out.println("utils.DrawGraph -- "+graphValues1.size());
drawGraph("Threshold: "+BUY_THRESHOLD+" Iterations: "+NUM_ITERATIONS_FOR_ORDER, graphValuesBase, graphValues1, graphValues2);
} catch (IOException e) {

View File

@@ -1,20 +1,14 @@
package storage;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* Created by dennis on 28.05.2017.
*/
public class Funds {
Map<String, Double> funds = new HashMap<String, Double>();
public Funds(){
public Funds(){}
}
public void clearFunds(){
if(funds != null) funds.clear();
}
public void clearFunds(){ if(funds != null) funds.clear(); }
public void addFund(String name, double value){
funds.put(name, value);

View File

@@ -1,6 +1,5 @@
/**
* Created by dennis on 28.05.2017.
*/
package storage;
public class Order {
public String pair;
public String type;
@@ -10,9 +9,7 @@ public class Order {
public Double volume;
public String leverage = "none";
public Order(){
}
public Order(){}
public Order(String ordertype){
this.ordertype = ordertype;

View File

@@ -1,15 +1,11 @@
import java.util.ArrayList;
import java.util.List;
package storage;
import java.util.ArrayList;
/**
* Created by dennis on 28.05.2017.
*/
public class OrderHistory {
public ArrayList<Order> orders = new ArrayList<Order>();
public OrderHistory(){
}
public OrderHistory(){}
public void clearOrders(){
if(orders != null) orders.clear();

View File

@@ -1,3 +1,5 @@
package storage;
public class Trade {
public double price;
public double volume;

View File

@@ -1,3 +1,5 @@
package storage;
import java.util.ArrayList;
import org.json.JSONArray;
@@ -14,11 +16,11 @@ public class TradeHistory {
public TradeHistory(JSONArray array, long sinceid){
if(array.length() < 1) return;
double price = 0.0;
double value = 0.0;
int timestamp = 0;
String buyorsell = "";
String marketorlimit = "";
double price;
double value;
int timestamp;
String buyorsell;
String marketorlimit;
for(int i = 0;i < array.length();i++){
price = array.getJSONArray(i).getDouble(0);
@@ -42,8 +44,7 @@ public class TradeHistory {
this.timeframesec = array.getJSONArray(array.length()-1).getInt(2) - array.getJSONArray(0).getInt(2);
}
public TradeHistory(){
}
public TradeHistory(){}
public TradeHistory getNumberAndVolumeOfBuyTradesInPastSec(int timeframe){
int currenttimestamp = (int) (System.currentTimeMillis() / 1000L);

View File

@@ -1,14 +1,12 @@
import org.apache.commons.math3.stat.regression.SimpleRegression;
import org.json.JSONArray;
import org.json.JSONObject;
package testing;
import org.apache.commons.math3.stat.regression.SimpleRegression;
import storage.Funds;
import storage.OrderHistory;
import storage.TradeHistory;
import java.io.*;
import java.nio.charset.Charset;
import java.util.*;
/**
* Created by denni on 09.06.2017.
*/
public class Backtest {
private static final String APP_NAME = "den_ac_deka_var2";
private static final double VALUE_ETH = 100.0;

View File

@@ -1,3 +1,5 @@
package utils;
import java.awt.BasicStroke;
import java.awt.Color;
import java.awt.Dimension;

View File

@@ -1,3 +1,5 @@
package utils;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.util.LinkedList;