Now it displays the logs :D
This commit is contained in:
parent
ade62f87c6
commit
308fd87731
|
|
@ -45,6 +45,7 @@ public class InstanceInterface {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
public static double getTraderTime(String exchange) throws IOException {
|
||||
Request uptimeRequest = new Request.Builder()
|
||||
.url(API_BASE_URL + "/" + exchange + "/trader_time")
|
||||
|
|
@ -107,9 +108,9 @@ public class InstanceInterface {
|
|||
}
|
||||
}
|
||||
|
||||
public static List<String> getLastLogs() throws IOException {
|
||||
public static String getLastLogs(String exchange) throws IOException {
|
||||
Request logRequest = new Request.Builder()
|
||||
.url(API_BASE_URL + "/get_log_lisd")
|
||||
.url(API_BASE_URL + "/" + exchange + "/get_log_list")
|
||||
.header("X-API-KEY", API_KEY)
|
||||
.build();
|
||||
|
||||
|
|
@ -135,7 +136,8 @@ public class InstanceInterface {
|
|||
logList.add(logsArray.get(i).getAsString());
|
||||
}
|
||||
|
||||
return logList;
|
||||
//return String.join("\n",logList);
|
||||
return joinWithLineLimit("\n",globalSettings.amountOfLogLines,logList);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -143,22 +145,32 @@ public class InstanceInterface {
|
|||
|
||||
public static ExchangeStatsData getExchangeStatsData(String exchange) throws IOException {
|
||||
//This needs to do A LOT of work
|
||||
//All workers stats request
|
||||
Request allWorkersStatsRequest = new Request.Builder()
|
||||
.url(API_BASE_URL + "/" + exchange + "/get_all_worker_status")
|
||||
.header("X-API-KEY", API_KEY)
|
||||
.build();
|
||||
|
||||
//Instance global stats
|
||||
Request instanceGlobalStatsRequest = new Request.Builder()
|
||||
.url(API_BASE_URL + "/" + exchange + "/global_stats")
|
||||
.header("X-API-KEY", API_KEY)
|
||||
.build();
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
public static List<String> getAllWorkersStats(String exchange) throws IOException {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
public static String joinWithLineLimit(String delimiter, int maxLines, Iterable<String> elements) {
|
||||
StringBuilder result = new StringBuilder();
|
||||
int currentLineCount = 0;
|
||||
for (String element : elements) {
|
||||
if (currentLineCount >= maxLines) {
|
||||
break;
|
||||
}
|
||||
if (result.length() > 0) {
|
||||
result.append(delimiter);
|
||||
}
|
||||
result.append(element);
|
||||
currentLineCount++;
|
||||
}
|
||||
return result.toString();
|
||||
}
|
||||
|
||||
|
||||
private static double getTodaysProfit(String jsonResponse) {
|
||||
try {
|
||||
JsonElement jsonElement = JsonParser.parseString(jsonResponse);
|
||||
|
|
|
|||
|
|
@ -19,8 +19,11 @@ import com.example.dcav2gui.MainActivity;
|
|||
import com.example.dcav2gui.R;
|
||||
import com.example.dcav2gui.TickerTracker;
|
||||
|
||||
import java.lang.reflect.Array;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.Executors;
|
||||
|
||||
|
|
@ -342,17 +345,80 @@ public class HomeFragment extends Fragment {
|
|||
}
|
||||
});
|
||||
|
||||
CompletableFuture<String> future5 = CompletableFuture.supplyAsync(() -> {
|
||||
try {
|
||||
return InstanceInterface.getLastLogs("binance");
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
return null;
|
||||
}
|
||||
});
|
||||
|
||||
CompletableFuture<String> future6 = CompletableFuture.supplyAsync(() -> {
|
||||
try {
|
||||
return InstanceInterface.getLastLogs("gateio");
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
return null;
|
||||
}
|
||||
});
|
||||
|
||||
CompletableFuture<String> future7 = CompletableFuture.supplyAsync(() -> {
|
||||
try {
|
||||
return InstanceInterface.getLastLogs("kucoin");
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
return null;
|
||||
}
|
||||
});
|
||||
|
||||
CompletableFuture<String> future8 = CompletableFuture.supplyAsync(() -> {
|
||||
try {
|
||||
return InstanceInterface.getLastLogs("okex");
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
return null;
|
||||
}
|
||||
});
|
||||
|
||||
// Wait for all futures to complete
|
||||
CompletableFuture<Void> allFutures = CompletableFuture.allOf(future1, future2, future3, future4);
|
||||
CompletableFuture<Void> allFutures = CompletableFuture.allOf(future1, future2, future3, future4, future5, future6, future7, future8);
|
||||
|
||||
// Update UI
|
||||
allFutures.thenAccept(voidResult -> {
|
||||
try {
|
||||
TickerTracker.PriceChangeData priceData = future1.get();
|
||||
TickerTracker.PriceChangeData priceData2 = future2.get();
|
||||
TickerTracker.PriceChangeData priceData3 = future3.get();;
|
||||
requireActivity().runOnUiThread(() -> {
|
||||
|
||||
InstanceInterface.ProfitStatsData profitsData = future4.get();
|
||||
TickerTracker.PriceChangeData priceData = null;
|
||||
TickerTracker.PriceChangeData priceData2 = null;
|
||||
TickerTracker.PriceChangeData priceData3 = null;
|
||||
try {
|
||||
priceData = future1.get();
|
||||
priceData2 = future2.get();
|
||||
priceData3 = future3.get();
|
||||
} catch (ExecutionException | InterruptedException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
|
||||
InstanceInterface.ProfitStatsData profitsData = null;
|
||||
try {
|
||||
profitsData = future4.get();
|
||||
} catch (ExecutionException | InterruptedException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
|
||||
String logs1 = null;
|
||||
String logs2 = null;
|
||||
String logs3 = null;
|
||||
String logs4 = null;
|
||||
try {
|
||||
logs1 = future5.get();
|
||||
logs2 = future6.get();
|
||||
logs3 = future7.get();
|
||||
logs4 = future8.get();
|
||||
} catch (ExecutionException | InterruptedException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
|
||||
pricePair1.setText(String.format(Locale.ROOT, "%.2f", priceData.getCurrentPrice()));
|
||||
pricePair124hPercentage.setText(formatPercentage(priceData.getPriceChangePercent24h()));
|
||||
|
|
@ -381,9 +447,19 @@ public class HomeFragment extends Fragment {
|
|||
profitsToday.setText(String.format(Locale.ROOT, "%.2f", profitsData.getProfitsToday()));
|
||||
profitsThisMonth.setText(String.format(Locale.ROOT, "%.2f", profitsData.getProfitsThisMonth()));
|
||||
|
||||
|
||||
//Populate logs
|
||||
log1Content.setText(logs1);
|
||||
log2Content.setText(logs2);
|
||||
log3Content.setText(logs3);
|
||||
log4Content.setText(logs4);
|
||||
|
||||
});
|
||||
|
||||
} catch (Exception e) {
|
||||
Toast.makeText(getContext(), "Error updating UI", Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
});
|
||||
} catch (Exception e) {
|
||||
requireActivity().runOnUiThread(() ->
|
||||
Toast.makeText(getContext(), "Failed to fetch price data. Check your connection.", Toast.LENGTH_SHORT).show()
|
||||
|
|
|
|||
Loading…
Reference in New Issue