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 {
|
public static double getTraderTime(String exchange) throws IOException {
|
||||||
Request uptimeRequest = new Request.Builder()
|
Request uptimeRequest = new Request.Builder()
|
||||||
.url(API_BASE_URL + "/" + exchange + "/trader_time")
|
.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()
|
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)
|
.header("X-API-KEY", API_KEY)
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
|
|
@ -135,7 +136,8 @@ public class InstanceInterface {
|
||||||
logList.add(logsArray.get(i).getAsString());
|
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 {
|
public static ExchangeStatsData getExchangeStatsData(String exchange) throws IOException {
|
||||||
//This needs to do A LOT of work
|
//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;
|
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) {
|
private static double getTodaysProfit(String jsonResponse) {
|
||||||
try {
|
try {
|
||||||
JsonElement jsonElement = JsonParser.parseString(jsonResponse);
|
JsonElement jsonElement = JsonParser.parseString(jsonResponse);
|
||||||
|
|
|
||||||
|
|
@ -19,8 +19,11 @@ import com.example.dcav2gui.MainActivity;
|
||||||
import com.example.dcav2gui.R;
|
import com.example.dcav2gui.R;
|
||||||
import com.example.dcav2gui.TickerTracker;
|
import com.example.dcav2gui.TickerTracker;
|
||||||
|
|
||||||
|
import java.lang.reflect.Array;
|
||||||
|
import java.util.List;
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
import java.util.concurrent.CompletableFuture;
|
import java.util.concurrent.CompletableFuture;
|
||||||
|
import java.util.concurrent.ExecutionException;
|
||||||
import java.util.concurrent.ExecutorService;
|
import java.util.concurrent.ExecutorService;
|
||||||
import java.util.concurrent.Executors;
|
import java.util.concurrent.Executors;
|
||||||
|
|
||||||
|
|
@ -342,48 +345,121 @@ 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
|
// 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
|
// Update UI
|
||||||
|
allFutures.thenAccept(voidResult -> {
|
||||||
try {
|
try {
|
||||||
TickerTracker.PriceChangeData priceData = future1.get();
|
requireActivity().runOnUiThread(() -> {
|
||||||
TickerTracker.PriceChangeData priceData2 = future2.get();
|
|
||||||
TickerTracker.PriceChangeData priceData3 = future3.get();;
|
|
||||||
|
|
||||||
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);
|
||||||
|
}
|
||||||
|
|
||||||
pricePair1.setText(String.format(Locale.ROOT,"%.2f", priceData.getCurrentPrice()));
|
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()));
|
pricePair124hPercentage.setText(formatPercentage(priceData.getPriceChangePercent24h()));
|
||||||
pricePair17dPercentage.setText(formatPercentage(priceData.getPriceChangePercent7d()));
|
pricePair17dPercentage.setText(formatPercentage(priceData.getPriceChangePercent7d()));
|
||||||
pricePair130dPercentage.setText(formatPercentage(priceData.getPriceChangePercent30d()));
|
pricePair130dPercentage.setText(formatPercentage(priceData.getPriceChangePercent30d()));
|
||||||
setPercentageColor(pricePair124hPercentage,priceData.getPriceChangePercent24h());
|
setPercentageColor(pricePair124hPercentage, priceData.getPriceChangePercent24h());
|
||||||
setPercentageColor(pricePair17dPercentage,priceData.getPriceChangePercent7d());
|
setPercentageColor(pricePair17dPercentage, priceData.getPriceChangePercent7d());
|
||||||
setPercentageColor(pricePair130dPercentage,priceData.getPriceChangePercent30d());
|
setPercentageColor(pricePair130dPercentage, priceData.getPriceChangePercent30d());
|
||||||
|
|
||||||
pricePair2.setText(String.format(Locale.ROOT,"%.2f", priceData2.getCurrentPrice()));
|
pricePair2.setText(String.format(Locale.ROOT, "%.2f", priceData2.getCurrentPrice()));
|
||||||
pricePair224hPercentage.setText(formatPercentage(priceData2.getPriceChangePercent24h()));
|
pricePair224hPercentage.setText(formatPercentage(priceData2.getPriceChangePercent24h()));
|
||||||
pricePair27dPercentage.setText(formatPercentage(priceData2.getPriceChangePercent7d()));
|
pricePair27dPercentage.setText(formatPercentage(priceData2.getPriceChangePercent7d()));
|
||||||
pricePair230dPercentage.setText(formatPercentage(priceData2.getPriceChangePercent30d()));
|
pricePair230dPercentage.setText(formatPercentage(priceData2.getPriceChangePercent30d()));
|
||||||
setPercentageColor(pricePair224hPercentage,priceData2.getPriceChangePercent24h());
|
setPercentageColor(pricePair224hPercentage, priceData2.getPriceChangePercent24h());
|
||||||
setPercentageColor(pricePair27dPercentage,priceData2.getPriceChangePercent7d());
|
setPercentageColor(pricePair27dPercentage, priceData2.getPriceChangePercent7d());
|
||||||
setPercentageColor(pricePair230dPercentage,priceData2.getPriceChangePercent30d());
|
setPercentageColor(pricePair230dPercentage, priceData2.getPriceChangePercent30d());
|
||||||
|
|
||||||
pricePair3.setText(String.format(Locale.ROOT,"%.2f", priceData3.getCurrentPrice()));
|
pricePair3.setText(String.format(Locale.ROOT, "%.2f", priceData3.getCurrentPrice()));
|
||||||
pricePair324hPercentage.setText(formatPercentage(priceData3.getPriceChangePercent24h()));
|
pricePair324hPercentage.setText(formatPercentage(priceData3.getPriceChangePercent24h()));
|
||||||
pricePair37dPercentage.setText(formatPercentage(priceData3.getPriceChangePercent7d()));
|
pricePair37dPercentage.setText(formatPercentage(priceData3.getPriceChangePercent7d()));
|
||||||
pricePair330dPercentage.setText(formatPercentage(priceData3.getPriceChangePercent30d()));
|
pricePair330dPercentage.setText(formatPercentage(priceData3.getPriceChangePercent30d()));
|
||||||
setPercentageColor(pricePair324hPercentage,priceData3.getPriceChangePercent24h());
|
setPercentageColor(pricePair324hPercentage, priceData3.getPriceChangePercent24h());
|
||||||
setPercentageColor(pricePair37dPercentage,priceData3.getPriceChangePercent7d());
|
setPercentageColor(pricePair37dPercentage, priceData3.getPriceChangePercent7d());
|
||||||
setPercentageColor(pricePair330dPercentage,priceData3.getPriceChangePercent30d());
|
setPercentageColor(pricePair330dPercentage, priceData3.getPriceChangePercent30d());
|
||||||
|
|
||||||
profitsToday.setText(String.format(Locale.ROOT,"%.2f", profitsData.getProfitsToday()));
|
profitsToday.setText(String.format(Locale.ROOT, "%.2f", profitsData.getProfitsToday()));
|
||||||
profitsThisMonth.setText(String.format(Locale.ROOT,"%.2f", profitsData.getProfitsThisMonth()));
|
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) {
|
} catch (Exception e) {
|
||||||
Toast.makeText(getContext(), "Error updating UI", Toast.LENGTH_SHORT).show();
|
Toast.makeText(getContext(), "Error updating UI", Toast.LENGTH_SHORT).show();
|
||||||
}
|
}
|
||||||
|
});
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
requireActivity().runOnUiThread(() ->
|
requireActivity().runOnUiThread(() ->
|
||||||
Toast.makeText(getContext(), "Failed to fetch price data. Check your connection.", Toast.LENGTH_SHORT).show()
|
Toast.makeText(getContext(), "Failed to fetch price data. Check your connection.", Toast.LENGTH_SHORT).show()
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue