TickerTracker optimization mkII
This commit is contained in:
parent
0893c4670c
commit
d9c3607b0a
|
|
@ -19,7 +19,7 @@ public class TickerTracker {
|
|||
public static PriceChangeData getPriceChanges(String symbol) throws IOException {
|
||||
// Construct the API request URL for 24h change
|
||||
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();
|
||||
|
||||
try (Response historicalResponse = httpClient.newCall(historicalRequest).execute()) {
|
||||
|
|
@ -67,7 +67,7 @@ public class TickerTracker {
|
|||
|
||||
int backwards = 721;
|
||||
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
|
||||
return ((currentPrice-periodEndPrice) / periodEndPrice * 100);
|
||||
|
|
|
|||
Loading…
Reference in New Issue