TickerTracker optimization mkII

This commit is contained in:
Nicolás Sánchez 2024-12-12 17:26:32 -03:00
parent 0893c4670c
commit d9c3607b0a
1 changed files with 2 additions and 2 deletions

View File

@ -19,7 +19,7 @@ public class TickerTracker {
public static PriceChangeData getPriceChanges(String symbol) throws IOException { public static PriceChangeData getPriceChanges(String symbol) throws IOException {
// Construct the API request URL for 24h change // Construct the API request URL for 24h change
Request historicalRequest = new Request.Builder() Request historicalRequest = new Request.Builder()
.url("https://api.binance.com/api/v3/klines?symbol=" + symbol.toUpperCase(Locale.ROOT) + "&interval=15m&limit=722") .url("https://api.binance.com/api/v3/klines?symbol=" + symbol.toUpperCase(Locale.ROOT) + "&interval=1h&limit=722")
.build(); .build();
try (Response historicalResponse = httpClient.newCall(historicalRequest).execute()) { try (Response historicalResponse = httpClient.newCall(historicalRequest).execute()) {
@ -67,7 +67,7 @@ public class TickerTracker {
int backwards = 721; int backwards = 721;
double currentPrice = klines.get(backwards).getAsJsonArray().get(4).getAsDouble(); double currentPrice = klines.get(backwards).getAsJsonArray().get(4).getAsDouble();
double periodEndPrice = klines.get(backwards-hours-1).getAsJsonArray().get(1).getAsDouble(); double periodEndPrice = klines.get(backwards-hours).getAsJsonArray().get(1).getAsDouble();
// Calculate percentage change // Calculate percentage change
return ((currentPrice-periodEndPrice) / periodEndPrice * 100); return ((currentPrice-periodEndPrice) / periodEndPrice * 100);