From ddc3e272bc3b007383c3d832be8356f2f59556ff Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicol=C3=A1s=20S=C3=A1nchez?= Date: Thu, 27 Mar 2025 11:56:35 -0300 Subject: [PATCH] bugfix with empty old_long --- .../example/dcav2gui/InstanceInterface.java | 24 +++++++++++-------- .../com/example/dcav2gui/WorkerInterface.java | 16 +++++++------ 2 files changed, 23 insertions(+), 17 deletions(-) diff --git a/app/src/main/java/com/example/dcav2gui/InstanceInterface.java b/app/src/main/java/com/example/dcav2gui/InstanceInterface.java index f32690e..9fefeb0 100644 --- a/app/src/main/java/com/example/dcav2gui/InstanceInterface.java +++ b/app/src/main/java/com/example/dcav2gui/InstanceInterface.java @@ -650,9 +650,11 @@ public class InstanceInterface { double price = value.has("price") && value.get("price").isJsonPrimitive() ? value.get("price").getAsDouble() : 0.0; double takeProfitPrice = value.has("take_profit_price") && value.get("take_profit_price").isJsonPrimitive() ? value.get("take_profit_price").getAsDouble() : 0.0; double nextSoPrice = value.has("next_so_price") && value.get("next_so_price").isJsonPrimitive() ? value.get("next_so_price").getAsDouble() : 0.0; - String tpOrderId = value.has("tp_order_id") && value.get("tp_order_id").isJsonPrimitive() ? value.get("tp_order_id").getAsString() : null; + String tpOrderId = ""; + //String tpOrderId = value.has("tp_order_id") && value.get("tp_order_id").isJsonPrimitive() ? value.get("tp_order_id").getAsString() : null; JsonObject takeProfitOrder = value.get("take_profit_order").getAsJsonObject(); - String safetyOrderId = value.has("so_order_id") && value.get("so_order_id").isJsonPrimitive() ? value.get("so_order_id").getAsString() : null; + String safetyOrderId = ""; + //String safetyOrderId = value.has("so_order_id") && value.get("so_order_id").isJsonPrimitive() ? value.get("so_order_id").getAsString() : null; JsonObject safetyOrder = value.get("safety_order").getAsJsonObject(); double feesPaidInBase = value.has("fees_paid_in_base") && value.get("fees_paid_in_base").isJsonPrimitive() ? value.get("fees_paid_in_base").getAsDouble() : 0.0; double feesPaidInQuote = value.has("fees_paid_in_quote") && value.get("fees_paid_in_quote").isJsonPrimitive() ? value.get("fees_paid_in_quote").getAsDouble() : 0.0; @@ -665,13 +667,15 @@ public class InstanceInterface { OldLongDictionary oldLongDictionary = null; if (value.has("old_long")) { oldLong = value.get("old_long").getAsJsonObject(); - oldLongDictionary = new OldLongDictionary( - oldLong.get("datetime").getAsString(), - oldLong.get("fees_paid_in_quote").getAsDouble(), - oldLong.get("quote_spent").getAsDouble(), - oldLong.get("tp_amount").getAsDouble(), - oldLong.get("tp_price").getAsDouble() - ); + if (!oldLong.entrySet().isEmpty()) { + oldLongDictionary = new OldLongDictionary( + oldLong.get("datetime").getAsString(), + oldLong.get("fees_paid_in_quote").getAsDouble(), + oldLong.get("quote_spent").getAsDouble(), + oldLong.get("tp_amount").getAsDouble(), + oldLong.get("tp_price").getAsDouble() + ); + } } valueToReturn.add(new WorkerStatsData( @@ -710,7 +714,7 @@ public class InstanceInterface { statusString )); } catch (Exception e) { - System.err.println("Error processing JSON for key '" + key + "': " + e.getMessage()); + System.err.println("In getAllWorkerStats: Error processing JSON for key '" + key + "': " + e.getMessage()); } } } diff --git a/app/src/main/java/com/example/dcav2gui/WorkerInterface.java b/app/src/main/java/com/example/dcav2gui/WorkerInterface.java index 7b1a16a..323c609 100644 --- a/app/src/main/java/com/example/dcav2gui/WorkerInterface.java +++ b/app/src/main/java/com/example/dcav2gui/WorkerInterface.java @@ -108,13 +108,15 @@ public class WorkerInterface { InstanceInterface.OldLongDictionary oldLongDictionary = null; if (value.has("old_long")) { oldLong = value.get("old_long").getAsJsonObject(); - oldLongDictionary = new InstanceInterface.OldLongDictionary( - oldLong.get("datetime").getAsString(), - oldLong.get("fees_paid_in_quote").getAsDouble(), - oldLong.get("quote_spent").getAsDouble(), - oldLong.get("tp_amount").getAsDouble(), - oldLong.get("tp_price").getAsDouble() - ); + if (!oldLong.entrySet().isEmpty()) { + oldLongDictionary = new InstanceInterface.OldLongDictionary( + oldLong.get("datetime").getAsString(), + oldLong.get("fees_paid_in_quote").getAsDouble(), + oldLong.get("quote_spent").getAsDouble(), + oldLong.get("tp_amount").getAsDouble(), + oldLong.get("tp_price").getAsDouble() + ); + } } valueToReturn = new InstanceInterface.WorkerStatsData(