Skip to content

Commit 43ed73c

Browse files
committed
improved webserver and log output
1 parent 31de10e commit 43ed73c

File tree

2 files changed

+63
-26
lines changed

2 files changed

+63
-26
lines changed

src/main/java/org/netno/TradingBot.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ public void executeTrade() {
199199

200200
// Display current status of the coin
201201
log("DEBUG", String.format(
202-
"Status for %s: Held Amount: %.6f, Purchase Price: %.6f, Current Price: %.6f, Profit Level: %d (%.2f%%), Highest Price: %.6f, Stop-Loss: %.6f, Difference: %.2f%%, Averaged Down Step: %d",
202+
"%s: Amount: %.6f, Purchase $: %.6f, Current $: %.6f, Profit Lv: %d (%.2f%%), Highest $: %.6f, Stop-Loss: %.6f, Performance: %.2f%%, A/D Step: %d",
203203
coin, tradeInfo.amount, tradeInfo.purchasePrice, currentPrice, tradeInfo.profitLevelIndex,
204204
config.profitLevels.get(tradeInfo.profitLevelIndex), tradeInfo.highestPrice,
205205
tradeInfo.trailingStopLoss, priceDifference, tradeInfo.averageDownStepIndex));

src/main/java/org/netno/WebServer.java

Lines changed: 62 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -46,29 +46,59 @@ private String generateHtmlResponse() {
4646
html.append("<html>");
4747
html.append("<head>");
4848
html.append("<meta http-equiv='refresh' content='10'>"); // Auto-refresh every 10 seconds
49-
html.append("<title>Held Coins</title>");
49+
html.append("<title>CoinbaseBot</title>");
5050
html.append("<style>");
51-
html.append("table { border-collapse: collapse; width: 80%; margin: auto; }");
52-
html.append("th, td { border: 1px solid black; padding: 3px; text-align: center; }");
51+
html.append("body { font-family: Arial, sans-serif; margin: 0; padding: 0; }");
52+
html.append("table { border-collapse: collapse; width: 90%; margin: auto; }");
53+
html.append("th, td { border: 1px solid black; padding: 8px; text-align: center; }");
5354
html.append("th { background-color: #f2f2f2; }");
5455
html.append(".profit { color: green; }");
5556
html.append(".loss { color: red; }");
57+
html.append(".cash-info { text-align: center; font-size: 18px; margin-top: 20px; }");
58+
html.append(".datetime { position: absolute; top: 10px; left: 10px; font-size: 12px; color: gray; }");
59+
html.append(".collapsible { cursor: pointer; padding: 10px; text-align: left; background-color: #f2f2f2; border: none; outline: none; width: 90%; margin: auto; font-size: 16px; }");
60+
html.append(".content { padding: 10px 15px; display: none; background-color: #ffffff; width: 90%; margin: auto; }");
61+
html.append(".collapsible:after { content: '\\002B'; float: right; }");
62+
html.append(".active:after { content: '\\2212'; }");
63+
html.append("@media screen and (max-width: 600px) { table { font-size: 12px; } th, td { padding: 5px; } }");
5664
html.append("</style>");
65+
html.append("<script>");
66+
html.append("document.addEventListener('DOMContentLoaded', () => {");
67+
html.append(" const collapsibles = document.querySelectorAll('.collapsible');");
68+
html.append(" collapsibles.forEach(button => {");
69+
html.append(" button.addEventListener('click', () => {");
70+
html.append(" button.classList.toggle('active');");
71+
html.append(" const content = button.nextElementSibling;");
72+
html.append(" if (content.style.display === 'block') {");
73+
html.append(" content.style.display = 'none';");
74+
html.append(" } else {");
75+
html.append(" content.style.display = 'block';");
76+
html.append(" }");
77+
html.append(" });");
78+
html.append(" });");
79+
html.append("});");
80+
html.append("</script>");
5781
html.append("</head>");
5882
html.append("<body>");
83+
84+
// Current Date and Time
85+
html.append("<div class='datetime'>").append(LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"))).append("</div>");
86+
87+
// Held Coins Table
5988
html.append("<h1 style='text-align:center;'>Held Coins</h1>");
6089
html.append("<table>");
6190
html.append("<tr>");
6291
html.append("<th>Coin</th>");
6392
html.append("<th>Purchase Date</th>");
6493
html.append("<th>Days Held</th>");
65-
html.append("<th>Average Purchase Price</th>");
66-
html.append("<th>Current Price</th>");
94+
html.append("<th>Avg. Purchase $</th>");
95+
html.append("<th>Current coin $</th>");
96+
html.append("<th>Total value</th>");
6797
html.append("<th>Stop Loss at</th>");
6898
html.append("<th>Win/Loss (%)</th>");
69-
html.append("<th>Win/Loss (USDC)</th>");
70-
html.append("<th>Highest Profit Level</th>");
71-
html.append("<th>Average Down Steps</th>");
99+
html.append("<th>Win/Loss ($)</th>");
100+
html.append("<th>Highest Profit Lv.</th>");
101+
html.append("<th>A/D Steps</th>");
72102
html.append("</tr>");
73103

74104
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
@@ -82,49 +112,56 @@ private String generateHtmlResponse() {
82112
currentPrice = 0.0; // Fallback if fetching fails
83113
}
84114

115+
double currentValue = currentPrice * tradeInfo.getAmount();
85116
double winLossPercent = ((currentPrice - tradeInfo.getPurchasePrice()) / tradeInfo.getPurchasePrice()) * 100;
86-
double winLossUSDC = (currentPrice - tradeInfo.getPurchasePrice()) * tradeInfo.getAmount();
117+
double winLossUSDC = currentValue - (tradeInfo.getAmount() * tradeInfo.getPurchasePrice());
87118
long daysHeld = ChronoUnit.DAYS.between(tradeInfo.getPurchaseDate(), LocalDateTime.now());
88119
String profitLevel = String.format("%d (%.2f%%)", tradeInfo.getProfitLevelIndex(),
89120
tb.config.profitLevels.get(tradeInfo.getProfitLevelIndex()));
90121
String averageDownStep = String.format("%d (%.2f%%)", tradeInfo.getAverageDownStepIndex(),
91122
tb.config.averageDownSteps.get(tradeInfo.getAverageDownStepIndex()));
92-
123+
93124
html.append("<tr>");
94125
html.append("<td>").append(coin).append("</td>");
95126
html.append("<td>").append(tradeInfo.getPurchaseDate().format(formatter)).append("</td>");
96127
html.append("<td>").append(daysHeld).append("</td>");
97-
html.append("<td>").append(String.format("%.6f", tradeInfo.getPurchasePrice()).replaceAll("\\.?0+$", "")).append("</td>");
98-
html.append("<td>").append(String.format("%.6f", currentPrice).replaceAll("\\.?0+$", "")).append("</td>");
99-
html.append("<td>").append(String.format("%.6f", tradeInfo.getTrailingStopLoss()).replaceAll("\\.?0+$", "")).append("</td>");
128+
html.append("<td>").append(String.format("%.6f $", tradeInfo.getPurchasePrice()).replaceAll("\\.?0+$", "")).append("</td>");
129+
html.append("<td>").append(String.format("%.6f $", currentPrice).replaceAll("\\.?0+$", "")).append("</td>");
130+
html.append("<td>").append(String.format("%.2f $", currentValue)).append("</td>");
131+
html.append("<td>").append(String.format("%.6f $", tradeInfo.getTrailingStopLoss()).replaceAll("\\.?0+$", "")).append("</td>");
100132
html.append("<td class='").append(winLossPercent >= 0 ? "profit" : "loss").append("'>")
101-
.append(String.format("%.2f%%", winLossPercent)).append("</td>");
133+
.append(String.format("%.2f% %", winLossPercent)).append("</td>");
102134
html.append("<td class='").append(winLossUSDC >= 0 ? "profit" : "loss").append("'>")
103-
.append(String.format("%.2f USDC", winLossUSDC)).append("</td>");
135+
.append(String.format("%.2f $", winLossUSDC)).append("</td>");
104136
html.append("<td>").append(tradeInfo.getProfitLevelIndex() > 0 ? profitLevel : "None").append("</td>");
105137
html.append("<td>").append(tradeInfo.getAverageDownStepIndex() > 0 ? averageDownStep : "None").append("</td>");
106138
html.append("</tr>");
107139
});
108140

109141
html.append("</table>");
110142

111-
// Add Profit Levels Section
112-
html.append("<h2 style='text-align:center;'>Profit Levels</h2>");
113-
html.append("<ul style='width: 80%; margin: auto;'>");
143+
// Display Current USDC Cash
144+
html.append("<div class='cash-info'>");
145+
html.append("Current USDC Cash: ").append(String.format("%.2f $", tb.usdcBalance));
146+
html.append("</div>");
147+
148+
// Collapsible Profit Levels Section
149+
html.append("<button class='collapsible'>Profit Levels</button>");
150+
html.append("<div class='content'>");
114151
List<Double> profitLevels = tb.config.profitLevels;
115152
for (int i = 0; i < profitLevels.size(); i++) {
116-
html.append("<li>Level ").append(i).append(": ").append(profitLevels.get(i)).append("%</li>");
153+
html.append("<p>Level ").append(i).append(": ").append(profitLevels.get(i)).append("%</p>");
117154
}
118-
html.append("</ul>");
155+
html.append("</div>");
119156

120-
// Add Average Down Steps Section
121-
html.append("<h2 style='text-align:center;'>Average Down Levels</h2>");
122-
html.append("<ul style='width: 80%; margin: auto;'>");
157+
// Collapsible Average Down Steps Section
158+
html.append("<button class='collapsible'>Average Down Levels</button>");
159+
html.append("<div class='content'>");
123160
List<Double> averageDownSteps = tb.config.averageDownSteps;
124161
for (int i = 0; i < averageDownSteps.size(); i++) {
125-
html.append("<li>Step ").append(i).append(": ").append(averageDownSteps.get(i)).append("%</li>");
162+
html.append("<p>Step ").append(i).append(": ").append(averageDownSteps.get(i)).append("%</p>");
126163
}
127-
html.append("</ul>");
164+
html.append("</div>");
128165

129166
html.append("</body>");
130167
html.append("</html>");

0 commit comments

Comments
 (0)