Skip to content

Commit 372e2ca

Browse files
Added functionality to go back to mode selection. (#14)
* Added functionality to go back to mode selection. * Added currency closing * Added checks for enough funds before buying logic and before checking * Bump version number Co-authored-by: Markus Aksli <markusaksli@hotmail.com>
1 parent 5a6721c commit 372e2ca

9 files changed

Lines changed: 235 additions & 170 deletions

File tree

src/main/java/modes/Backtesting.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
import java.util.List;
88
import java.util.Scanner;
99

10-
//TODO: Clean up Backtesting class.
1110
public final class Backtesting {
1211
private static final List<Currency> currencies = new ArrayList<>();
1312
private static LocalAccount localAccount;

src/main/java/modes/Collection.java

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -94,18 +94,20 @@ public static void setLastMessage(String lastMessage) {
9494
printProgress();
9595
}
9696

97-
private static void collectionInterface() {
97+
private static boolean collectionInterface() {
9898
if (backtestingFolder.exists() && backtestingFolder.isDirectory()) {
9999
String[] backtestingFiles = getDataFiles();
100100
if (backtestingFiles.length == 0) {
101101
System.out.println("---No backtesting files detected");
102-
return;
102+
return true;
103103
}
104104

105105
String input = "";
106106
while (!input.equalsIgnoreCase("new")) {
107107
if (input.equalsIgnoreCase("quit")) {
108108
System.exit(0);
109+
} else if (input.equalsIgnoreCase("modes")) {
110+
return false;
109111
}
110112
if (input.matches("\\d+")) {
111113
int index = Integer.parseInt(input);
@@ -118,12 +120,14 @@ private static void collectionInterface() {
118120
System.out.println("[" + (i + 1) + "] " + backtestingFiles[i]);
119121
}
120122
System.out.println("\nEnter \"new\" to start collecting a new data file");
121-
System.out.println("Enter \"quit\" to exit the program\n");
123+
System.out.println("Enter \"quit\" to exit the program");
124+
System.out.println("Enter \"modes\" to return to mode selection.\n");
122125
input = sc.nextLine();
123126
}
124127
} else {
125128
System.out.println("---No backtesting files detected");
126129
}
130+
return true;
127131
}
128132

129133
public static String[] getDataFiles() {
@@ -162,21 +166,28 @@ public static void startCollection() {
162166

163167
System.out.println("\n---Collection completed, result in "
164168
+ new File(filename).getAbsolutePath());
165-
System.out.println("---Files may only appear after quitting");
166169

167170
describe(filename);
168171
} catch (Exception e) {
169172
e.printStackTrace();
170173
System.out.println("---Recovery failed, removing temp files");
171174
deleteTemp();
175+
try {
176+
Files.deleteIfExists(Path.of(filename));
177+
} catch (IOException ioException) {
178+
ioException.printStackTrace();
179+
}
172180
}
173181
}
174182
}
175183
} else {
176184
deleteTemp();
177185
}
178186
}
179-
collectionInterface();
187+
boolean returnToModes = collectionInterface();
188+
if (!returnToModes) {
189+
return;
190+
}
180191
System.out.println("Enter collectable currency (BTC, LINK, ETH...)");
181192
while (true) {
182193
try {
@@ -261,6 +272,8 @@ public void run() {
261272
}
262273
}
263274
}, requestDelay, requestDelay);
275+
276+
Collection.setLastMessage("Sending requests...");
264277
int id = 0;
265278
while (true) {
266279
long diff = end - start;
@@ -294,7 +307,6 @@ public void run() {
294307
System.out.println("\n---Collection completed in "
295308
+ Formatter.formatDuration(System.currentTimeMillis() - initTime) + ", result in "
296309
+ new File(filename).getAbsolutePath());
297-
System.out.println("---Files may only appear after quitting");
298310

299311
describe(filename);
300312

src/main/java/modes/Live.java

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
import com.binance.api.client.domain.account.AssetBalance;
44
import com.binance.api.client.domain.general.FilterType;
55
import com.binance.api.client.domain.general.SymbolFilter;
6-
import com.binance.api.client.exception.BinanceApiException;
76
import system.ConfigSetup;
87
import system.Formatter;
98
import trading.*;
@@ -16,7 +15,7 @@
1615
import java.util.Optional;
1716
import java.util.Scanner;
1817

19-
//TODO: Clean up Live class
18+
2019
public final class Live {
2120
private static LocalAccount localAccount;
2221
private static final List<Currency> currencies = new ArrayList<>();
@@ -34,6 +33,16 @@ public static List<Currency> getCurrencies() {
3433
return currencies;
3534
}
3635

36+
public static void close() {
37+
for (Currency currency : currencies) {
38+
try {
39+
currency.close();
40+
} catch (IOException e) {
41+
e.printStackTrace();
42+
}
43+
}
44+
}
45+
3746
public static void init() {
3847
boolean fileFailed = true;
3948
if (credentialsFile.exists()) {

src/main/java/modes/Simulation.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import trading.BuySell;
77
import trading.Currency;
88

9+
import java.io.IOException;
910
import java.util.ArrayList;
1011
import java.util.List;
1112

@@ -26,6 +27,16 @@ public static LocalAccount getAccount() {
2627
return localAccount;
2728
}
2829

30+
public static void close() {
31+
for (Currency currency : currencies) {
32+
try {
33+
currency.close();
34+
} catch (IOException e) {
35+
e.printStackTrace();
36+
}
37+
}
38+
}
39+
2940
public static void init() {
3041
localAccount = new LocalAccount("Investor Toomas", STARTING_VALUE);
3142
BuySell.setAccount(localAccount);

src/main/java/system/ConfigSetup.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
import com.binance.api.client.domain.general.RateLimitType;
55
import indicators.MACD;
66
import indicators.RSI;
7-
import modes.Backtesting;
87
import modes.Simulation;
98
import trading.BuySell;
109
import trading.Currency;
@@ -99,7 +98,7 @@ public static void readConfig() {
9998
Trade.TAKE_PROFIT = Double.parseDouble(arr[1]);
10099
break;
101100
case "Confluence":
102-
Currency.CONFLUENCE = Integer.parseInt(arr[1]);
101+
Currency.CONFLUENCE_TARGET = Integer.parseInt(arr[1]);
103102
break;
104103
case "Close confluence":
105104
Trade.CLOSE_CONFLUENCE = Integer.parseInt(arr[1]);

0 commit comments

Comments
 (0)