extended logs
This commit is contained in:
parent
687e66c742
commit
f49776bc4b
|
|
@ -356,6 +356,44 @@ public class InstanceInterface {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static String getAllLogs(String exchange, boolean retry) throws IOException {
|
||||||
|
//200 lines hard limit
|
||||||
|
Request logRequest = new Request.Builder()
|
||||||
|
.url(API_BASE_URL + "/statistics_server/fetch_full_log?exchange_name=" + exchange)
|
||||||
|
.header("X-API-KEY", API_KEY)
|
||||||
|
.build();
|
||||||
|
|
||||||
|
|
||||||
|
try (Response logResponse = httpClient.newCall(logRequest).execute()) {
|
||||||
|
if (!logResponse.isSuccessful()) {
|
||||||
|
if (logResponse.code() == 503 && retry) {
|
||||||
|
return getAllLogs(exchange,false);
|
||||||
|
}
|
||||||
|
throw new IOException("Unexpected code " + logResponse);
|
||||||
|
}
|
||||||
|
String dealsResponseBody = logResponse.body().string();
|
||||||
|
JsonElement jsonElement = JsonParser.parseString(dealsResponseBody);
|
||||||
|
if (!jsonElement.isJsonObject()) {
|
||||||
|
System.err.println("The parsed JSON response is not a JsonObject.");
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
JsonObject jsonObject = jsonElement.getAsJsonObject();
|
||||||
|
if (!jsonObject.has("line")) {
|
||||||
|
System.err.println("The parsed JSON response does not contain the last_lines key.");
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
JsonArray logsArray = jsonObject.getAsJsonArray("line");
|
||||||
|
List<String> logList = new ArrayList<>();
|
||||||
|
for (int i = logsArray.size()-1; i >= 0; i--) {
|
||||||
|
logList.add(logsArray.get(i).getAsString());
|
||||||
|
}
|
||||||
|
|
||||||
|
return String.join("\n", logList);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
private static double gibSoSize(double orderSize, int n, double safetyOrderScale) {
|
private static double gibSoSize(double orderSize, int n, double safetyOrderScale) {
|
||||||
double targetOrderSize = orderSize;
|
double targetOrderSize = orderSize;
|
||||||
for (int i = 0; i < n; i++) {
|
for (int i = 0; i < n; i++) {
|
||||||
|
|
|
||||||
|
|
@ -317,7 +317,7 @@ public class HomeFragment extends Fragment {
|
||||||
@Override
|
@Override
|
||||||
public boolean onMenuItemClick(MenuItem item) {
|
public boolean onMenuItemClick(MenuItem item) {
|
||||||
if (item.getItemId() == R.id.today_this_month_details) {
|
if (item.getItemId() == R.id.today_this_month_details) {
|
||||||
// Implement as in profit_report.py
|
// TODO: Implement as is profit_report.py
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
|
|
@ -382,8 +382,7 @@ public class HomeFragment extends Fragment {
|
||||||
@Override
|
@Override
|
||||||
public boolean onMenuItemClick(MenuItem item) {
|
public boolean onMenuItemClick(MenuItem item) {
|
||||||
if (item.getItemId() == R.id.log_details) {
|
if (item.getItemId() == R.id.log_details) {
|
||||||
// Handle the "Details..." option
|
fetchAllLogs(exchange);
|
||||||
// For example, navigate to a details fragment
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
|
|
@ -392,6 +391,18 @@ public class HomeFragment extends Fragment {
|
||||||
popupMenu.show();
|
popupMenu.show();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void fetchAllLogs(String exchange) {
|
||||||
|
new Thread(() -> {
|
||||||
|
try {
|
||||||
|
String result = InstanceInterface.getAllLogs(exchange, true);
|
||||||
|
new Handler(Looper.getMainLooper()).post(() -> showExtendedLogsDialog(exchange, result));
|
||||||
|
} catch (IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
new Handler(Looper.getMainLooper()).post(() -> Toast.makeText(getContext(), "Failed to fetch missing pairs", Toast.LENGTH_SHORT).show());
|
||||||
|
}
|
||||||
|
}).start();
|
||||||
|
}
|
||||||
|
|
||||||
// Adds a plus sign if the percentage is positive
|
// Adds a plus sign if the percentage is positive
|
||||||
private String formatPercentage(double value) {
|
private String formatPercentage(double value) {
|
||||||
if (value>=0) {
|
if (value>=0) {
|
||||||
|
|
@ -550,6 +561,24 @@ public class HomeFragment extends Fragment {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private void showExtendedLogsDialog(String exchange, String result) {
|
||||||
|
AlertDialog.Builder builder = new AlertDialog.Builder(getContext());
|
||||||
|
|
||||||
|
LayoutInflater inflater = LayoutInflater.from(getContext());
|
||||||
|
// Reuse trades_detail_dialog layout
|
||||||
|
View customLayout = inflater.inflate(R.layout.trades_detail_dialog, null);
|
||||||
|
TextView titleTextView = customLayout.findViewById(R.id.trades_details_title);
|
||||||
|
TextView detailsTextView = customLayout.findViewById(R.id.trades_details_content);
|
||||||
|
|
||||||
|
String title = exchange + "log";
|
||||||
|
titleTextView.setText(title);
|
||||||
|
detailsTextView.setText(result);
|
||||||
|
|
||||||
|
builder.setView(customLayout);
|
||||||
|
builder.setPositiveButton("OK", null);
|
||||||
|
builder.show();
|
||||||
|
}
|
||||||
|
|
||||||
private void showInstanceDetailsDialog(InstanceInterface.InstanceGlobalStatsData result) {
|
private void showInstanceDetailsDialog(InstanceInterface.InstanceGlobalStatsData result) {
|
||||||
AlertDialog.Builder builder = new AlertDialog.Builder(getContext());
|
AlertDialog.Builder builder = new AlertDialog.Builder(getContext());
|
||||||
builder.setTitle(result.getName() + " details");
|
builder.setTitle(result.getName() + " details");
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue