removed duplicated calls
This commit is contained in:
parent
6b0ce801c2
commit
c018532098
|
|
@ -288,24 +288,39 @@ public class InstanceInterface {
|
|||
public static ExchangeStatsData getExchangeStatsData(String exchange) throws IOException {
|
||||
double lastSeen;
|
||||
double fundsAvailable;
|
||||
double fundsNeeded;
|
||||
int onlineWorkers;
|
||||
int longWorkers;
|
||||
int shortWorkers;
|
||||
double fundsNeeded = 0;
|
||||
int onlineWorkers = 0;
|
||||
int longWorkers = 0;
|
||||
int shortWorkers = 0;
|
||||
List<WorkerStatsData> workers;
|
||||
|
||||
|
||||
// Semaphore
|
||||
lastSeen = getTraderTime(exchange, true);
|
||||
|
||||
//Funds available
|
||||
fundsAvailable = getFundsAvailable(exchange, "USDT", true);
|
||||
|
||||
//Individual worker status needed to calculate this
|
||||
workers = getAllWorkersStats(exchange, true);
|
||||
CompletableFuture<Double> traderTimeFuture = CompletableFuture.supplyAsync(() -> {
|
||||
try {
|
||||
return getTraderTime(exchange, true);
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
});
|
||||
CompletableFuture<Double> fundsAvailableFuture = CompletableFuture.supplyAsync(() -> {
|
||||
try {
|
||||
return getFundsAvailable(exchange,"USDT", true);
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
});
|
||||
CompletableFuture<List<WorkerStatsData>> workerStatsFuture = CompletableFuture.supplyAsync(() -> {
|
||||
try {
|
||||
return getAllWorkersStats(exchange, true);
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
});
|
||||
CompletableFuture<Void> allFutures = CompletableFuture.allOf(traderTimeFuture, fundsAvailableFuture, workerStatsFuture);
|
||||
lastSeen = traderTimeFuture.join();
|
||||
fundsAvailable = fundsAvailableFuture.join();
|
||||
workers = workerStatsFuture.join();
|
||||
|
||||
//Funds needed
|
||||
fundsNeeded = 0;
|
||||
if (workers != null) {
|
||||
for (WorkerStatsData worker : workers) {
|
||||
if (!worker.isShort) {
|
||||
|
|
@ -320,13 +335,9 @@ public class InstanceInterface {
|
|||
//Online workers
|
||||
if (workers != null) {
|
||||
onlineWorkers = workers.size();
|
||||
} else {
|
||||
onlineWorkers = 0;
|
||||
}
|
||||
|
||||
//Long workers
|
||||
longWorkers = 0;
|
||||
shortWorkers = 0;
|
||||
if (workers != null) {
|
||||
for (WorkerStatsData worker : workers) {
|
||||
if (!worker.isShort) {
|
||||
|
|
|
|||
|
|
@ -309,7 +309,6 @@ public class HomeFragment extends Fragment {
|
|||
private void fetchAndDisplayData() {
|
||||
executorService.execute(() -> {
|
||||
try {
|
||||
// Fetch price data in background using CompletableFuture
|
||||
CompletableFuture<TickerTracker.PriceChangeData> future1 = CompletableFuture.supplyAsync(() -> {
|
||||
try {
|
||||
return TickerTracker.getPriceChanges(getString(R.string.ticker_1),true);
|
||||
|
|
@ -318,7 +317,6 @@ public class HomeFragment extends Fragment {
|
|||
return null;
|
||||
}
|
||||
});
|
||||
|
||||
CompletableFuture<TickerTracker.PriceChangeData> future2 = CompletableFuture.supplyAsync(() -> {
|
||||
try {
|
||||
return TickerTracker.getPriceChanges(getString(R.string.ticker_2), true);
|
||||
|
|
@ -327,7 +325,6 @@ public class HomeFragment extends Fragment {
|
|||
return null;
|
||||
}
|
||||
});
|
||||
|
||||
CompletableFuture<TickerTracker.PriceChangeData> future3 = CompletableFuture.supplyAsync(() -> {
|
||||
try {
|
||||
return TickerTracker.getPriceChanges(getString(R.string.ticker_3), true);
|
||||
|
|
@ -336,7 +333,6 @@ public class HomeFragment extends Fragment {
|
|||
return null;
|
||||
}
|
||||
});
|
||||
|
||||
CompletableFuture<InstanceInterface.ProfitStatsData> future4 = CompletableFuture.supplyAsync(() -> {
|
||||
try {
|
||||
return InstanceInterface.getProfitStatsData(true);
|
||||
|
|
@ -345,7 +341,6 @@ public class HomeFragment extends Fragment {
|
|||
return null;
|
||||
}
|
||||
});
|
||||
|
||||
CompletableFuture<String> future5 = CompletableFuture.supplyAsync(() -> {
|
||||
try {
|
||||
return InstanceInterface.getLastLogs("binance", true);
|
||||
|
|
@ -354,7 +349,6 @@ public class HomeFragment extends Fragment {
|
|||
return null;
|
||||
}
|
||||
});
|
||||
|
||||
CompletableFuture<String> future6 = CompletableFuture.supplyAsync(() -> {
|
||||
try {
|
||||
return InstanceInterface.getLastLogs("gateio", true);
|
||||
|
|
@ -363,7 +357,6 @@ public class HomeFragment extends Fragment {
|
|||
return null;
|
||||
}
|
||||
});
|
||||
|
||||
CompletableFuture<String> future7 = CompletableFuture.supplyAsync(() -> {
|
||||
try {
|
||||
return InstanceInterface.getLastLogs("kucoin", true);
|
||||
|
|
@ -372,7 +365,6 @@ public class HomeFragment extends Fragment {
|
|||
return null;
|
||||
}
|
||||
});
|
||||
|
||||
CompletableFuture<String> future8 = CompletableFuture.supplyAsync(() -> {
|
||||
try {
|
||||
return InstanceInterface.getLastLogs("okex", true);
|
||||
|
|
@ -381,7 +373,6 @@ public class HomeFragment extends Fragment {
|
|||
return null;
|
||||
}
|
||||
});
|
||||
|
||||
CompletableFuture<List<InstanceInterface.DealData>> future9 = CompletableFuture.supplyAsync(() -> {
|
||||
try {
|
||||
return InstanceInterface.getAllTrades();
|
||||
|
|
@ -390,7 +381,6 @@ public class HomeFragment extends Fragment {
|
|||
return null;
|
||||
}
|
||||
});
|
||||
|
||||
CompletableFuture<InstanceInterface.ExchangeStatsData> future10 = CompletableFuture.supplyAsync(() -> {
|
||||
try {
|
||||
return InstanceInterface.getExchangeStatsData("binance");
|
||||
|
|
@ -399,7 +389,6 @@ public class HomeFragment extends Fragment {
|
|||
return null;
|
||||
}
|
||||
});
|
||||
|
||||
CompletableFuture<InstanceInterface.ExchangeStatsData> future11 = CompletableFuture.supplyAsync(() -> {
|
||||
try {
|
||||
return InstanceInterface.getExchangeStatsData("gateio");
|
||||
|
|
@ -408,7 +397,6 @@ public class HomeFragment extends Fragment {
|
|||
return null;
|
||||
}
|
||||
});
|
||||
|
||||
CompletableFuture<InstanceInterface.ExchangeStatsData> future12 = CompletableFuture.supplyAsync(() -> {
|
||||
try {
|
||||
return InstanceInterface.getExchangeStatsData("kucoin");
|
||||
|
|
@ -417,7 +405,6 @@ public class HomeFragment extends Fragment {
|
|||
return null;
|
||||
}
|
||||
});
|
||||
|
||||
CompletableFuture<InstanceInterface.ExchangeStatsData> future13 = CompletableFuture.supplyAsync(() -> {
|
||||
try {
|
||||
return InstanceInterface.getExchangeStatsData("okex");
|
||||
|
|
@ -428,43 +415,10 @@ public class HomeFragment extends Fragment {
|
|||
|
||||
});
|
||||
|
||||
CompletableFuture<InstanceInterface.ExchangeStatsData> future14 = CompletableFuture.supplyAsync(() -> {
|
||||
try {
|
||||
return InstanceInterface.getExchangeStatsData("binance");
|
||||
} catch (IOException e) {
|
||||
System.err.print(e.toString());
|
||||
return null;
|
||||
}
|
||||
});
|
||||
CompletableFuture<InstanceInterface.ExchangeStatsData> future15 = CompletableFuture.supplyAsync(() -> {
|
||||
try {
|
||||
return InstanceInterface.getExchangeStatsData("gateio");
|
||||
} catch (IOException e) {
|
||||
System.err.print(e.toString());
|
||||
return null;
|
||||
}
|
||||
});
|
||||
CompletableFuture<InstanceInterface.ExchangeStatsData> future16 = CompletableFuture.supplyAsync(() -> {
|
||||
try {
|
||||
return InstanceInterface.getExchangeStatsData("kucoin");
|
||||
} catch (IOException e) {
|
||||
System.err.print(e.toString());
|
||||
return null;
|
||||
}
|
||||
});
|
||||
CompletableFuture<InstanceInterface.ExchangeStatsData> future17 = CompletableFuture.supplyAsync(() -> {
|
||||
try {
|
||||
return InstanceInterface.getExchangeStatsData("okex");
|
||||
} catch (IOException e) {
|
||||
System.err.print(e.toString());
|
||||
return null;
|
||||
}
|
||||
});
|
||||
|
||||
// Wait for all futures to complete
|
||||
CompletableFuture<Void> allFutures = CompletableFuture.allOf(
|
||||
future1, future2, future3, future4, future5, future6, future7, future8,
|
||||
future9, future10, future11, future12, future13, future14);
|
||||
future9, future10, future11, future12, future13);
|
||||
|
||||
// Update UI
|
||||
allFutures.thenAccept(voidResult -> {
|
||||
|
|
@ -501,7 +455,6 @@ public class HomeFragment extends Fragment {
|
|||
throw new RuntimeException(e);
|
||||
}
|
||||
|
||||
//Populate deals page
|
||||
try {
|
||||
List<InstanceInterface.DealData> deals = future9.get();
|
||||
if (deals != null) {
|
||||
|
|
@ -521,13 +474,10 @@ public class HomeFragment extends Fragment {
|
|||
}
|
||||
lastTrades.setText(dealsList);
|
||||
}
|
||||
} catch (ExecutionException e) {
|
||||
throw new RuntimeException(e);
|
||||
} catch (InterruptedException e) {
|
||||
} catch (ExecutionException | InterruptedException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
|
||||
|
||||
InstanceInterface.ExchangeStatsData binanceStats;
|
||||
InstanceInterface.ExchangeStatsData gateioStats;
|
||||
InstanceInterface.ExchangeStatsData kucoinStats;
|
||||
|
|
@ -678,37 +628,26 @@ public class HomeFragment extends Fragment {
|
|||
log4Content.setText(logs4);
|
||||
|
||||
// Exchange stats
|
||||
InstanceInterface.ExchangeStatsData binanceGlobalStats;
|
||||
InstanceInterface.ExchangeStatsData gateioGlobalStats;
|
||||
InstanceInterface.ExchangeStatsData kucoinGlobalStats;
|
||||
InstanceInterface.ExchangeStatsData okexGlobalStats;
|
||||
try {
|
||||
binanceGlobalStats = future14.get();
|
||||
gateioGlobalStats = future15.get();
|
||||
kucoinGlobalStats = future16.get();
|
||||
okexGlobalStats = future17.get();
|
||||
} catch (ExecutionException | InterruptedException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
|
||||
if (binanceGlobalStats != null) {
|
||||
exchange1WorkersOnline.setText(String.valueOf(binanceGlobalStats.getOnlineWorkers()));
|
||||
String longShortWorkers = String.valueOf(binanceGlobalStats.getLongWorkers()) + "/" + String.valueOf(binanceGlobalStats.getShortWorkers());
|
||||
|
||||
if (binanceStats != null) {
|
||||
exchange1WorkersOnline.setText(String.valueOf(binanceStats.getOnlineWorkers()));
|
||||
String longShortWorkers = String.valueOf(binanceStats.getLongWorkers()) + "/" + String.valueOf(binanceStats.getShortWorkers());
|
||||
exchange1WorkersLongShort.setText(longShortWorkers);
|
||||
}
|
||||
if (gateioGlobalStats != null) {
|
||||
exchange2WorkersOnline.setText(String.valueOf(gateioGlobalStats.getOnlineWorkers()));
|
||||
String longShortWorkers = String.valueOf(gateioGlobalStats.getLongWorkers()) + "/" + String.valueOf(gateioGlobalStats.getShortWorkers());
|
||||
if (gateioStats != null) {
|
||||
exchange2WorkersOnline.setText(String.valueOf(gateioStats.getOnlineWorkers()));
|
||||
String longShortWorkers = String.valueOf(gateioStats.getLongWorkers()) + "/" + String.valueOf(gateioStats.getShortWorkers());
|
||||
exchange2WorkersLongShort.setText(longShortWorkers);
|
||||
}
|
||||
if (kucoinGlobalStats != null) {
|
||||
exchange3WorkersOnline.setText(String.valueOf(kucoinGlobalStats.getOnlineWorkers()));
|
||||
String longShortWorkers = String.valueOf(kucoinGlobalStats.getLongWorkers()) + "/" + String.valueOf(kucoinGlobalStats.getShortWorkers());
|
||||
if (kucoinStats != null) {
|
||||
exchange3WorkersOnline.setText(String.valueOf(kucoinStats.getOnlineWorkers()));
|
||||
String longShortWorkers = String.valueOf(kucoinStats.getLongWorkers()) + "/" + String.valueOf(kucoinStats.getShortWorkers());
|
||||
exchange3WorkersLongShort.setText(longShortWorkers);
|
||||
}
|
||||
if (okexGlobalStats != null) {
|
||||
exchange4WorkersOnline.setText(String.valueOf(okexGlobalStats.getOnlineWorkers()));
|
||||
String longShortWorkers = String.valueOf(okexGlobalStats.getLongWorkers()) + "/" + String.valueOf(okexGlobalStats.getShortWorkers());
|
||||
if (okexStats != null) {
|
||||
exchange4WorkersOnline.setText(String.valueOf(okexStats.getOnlineWorkers()));
|
||||
String longShortWorkers = String.valueOf(okexStats.getLongWorkers()) + "/" + String.valueOf(okexStats.getShortWorkers());
|
||||
exchange4WorkersLongShort.setText(longShortWorkers);
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue