fixed safety order id - compatibility with concurrent safety orders

This commit is contained in:
Nicolás Sánchez 2025-09-05 16:00:25 -03:00
parent 614ca2f525
commit 94137f57e6
5 changed files with 36 additions and 16 deletions

View File

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="AndroidProjectSystem">
<option name="providerId" value="com.android.tools.idea.GradleProjectSystem" />
</component>
</project>

View File

@ -4,10 +4,10 @@
<selectionStates> <selectionStates>
<SelectionState runConfigName="app"> <SelectionState runConfigName="app">
<option name="selectionMode" value="DROPDOWN" /> <option name="selectionMode" value="DROPDOWN" />
<DropdownSelection timestamp="2025-01-09T00:51:44.224576189Z"> <DropdownSelection timestamp="2025-06-16T13:28:36.173409509Z">
<Target type="DEFAULT_BOOT"> <Target type="DEFAULT_BOOT">
<handle> <handle>
<DeviceId pluginId="PhysicalDevice" identifier="serial=ZY22FN7MHQ" /> <DeviceId pluginId="LocalEmulator" identifier="path=/home/nicolas/.android/avd/Pixel_6_Pro_API_34.avd" />
</handle> </handle>
</Target> </Target>
</DropdownSelection> </DropdownSelection>

View File

@ -2,6 +2,8 @@ package com.example.dcav2gui;
import static com.example.dcav2gui.MainActivity.globalSettings; import static com.example.dcav2gui.MainActivity.globalSettings;
import android.util.Log;
import androidx.annotation.NonNull; import androidx.annotation.NonNull;
import com.example.dcav2gui.ui.exchanges.WorkerData; import com.example.dcav2gui.ui.exchanges.WorkerData;
@ -652,17 +654,20 @@ public class InstanceInterface {
double nextSoPrice = value.has("next_so_price") && value.get("next_so_price").isJsonPrimitive() ? value.get("next_so_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;
JsonObject takeProfitOrder = null; JsonObject takeProfitOrder = null;
String tpOrderId = ""; String tpOrderId = "";
JsonObject safetyOrder = null; JsonArray safetyOrders = null;
String safetyOrderId = ""; String safetyOrderId = "";
JsonElement takeProfitOrderElement = value.get("take_profit_order"); JsonElement takeProfitOrderElement = value.get("take_profit_order");
if (takeProfitOrderElement!=null && !takeProfitOrderElement.isJsonNull() && takeProfitOrderElement.isJsonObject()) { if (takeProfitOrderElement!=null && !takeProfitOrderElement.isJsonNull() && takeProfitOrderElement.isJsonObject()) {
takeProfitOrder = takeProfitOrderElement.getAsJsonObject(); takeProfitOrder = takeProfitOrderElement.getAsJsonObject();
tpOrderId = takeProfitOrder.has("id") && takeProfitOrder.get("id").isJsonPrimitive() ? takeProfitOrder.get("id").getAsString() : ""; tpOrderId = takeProfitOrder.has("id") && takeProfitOrder.get("id").isJsonPrimitive() ? takeProfitOrder.get("id").getAsString() : "";
} }
JsonElement safetyOrderElement = value.get("safety_order"); JsonElement safetyOrderElements = value.get("safety_orders");
if (safetyOrderElement!=null && !safetyOrderElement.isJsonNull() && safetyOrderElement.isJsonObject()) { if (safetyOrderElements!=null && !safetyOrderElements.isJsonNull() && safetyOrderElements.isJsonArray()) {
safetyOrder = safetyOrderElement.getAsJsonObject(); safetyOrders = safetyOrderElements.getAsJsonArray();
safetyOrderId = safetyOrder.has("id") && safetyOrder.get("id").isJsonPrimitive() ? safetyOrder.get("id").getAsString() : ""; if (!safetyOrders.isEmpty()) {
JsonObject firstSafetyOrder = safetyOrders.get(0).getAsJsonObject();
safetyOrderId = firstSafetyOrder.has("id") && firstSafetyOrder.get("id").isJsonPrimitive() ? firstSafetyOrder.get("id").getAsString() : "";
}
} }
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 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; double feesPaidInQuote = value.has("fees_paid_in_quote") && value.get("fees_paid_in_quote").isJsonPrimitive() ? value.get("fees_paid_in_quote").getAsDouble() : 0.0;
@ -711,7 +716,7 @@ public class InstanceInterface {
tpOrderId, tpOrderId,
takeProfitOrder, takeProfitOrder,
safetyOrderId, safetyOrderId,
safetyOrder, safetyOrders,
feesPaidInBase, feesPaidInBase,
feesPaidInQuote, feesPaidInQuote,
partialProfit, partialProfit,
@ -1060,7 +1065,7 @@ public class InstanceInterface {
private final String tpOrderId; private final String tpOrderId;
private final JsonObject takeProfitOrder; private final JsonObject takeProfitOrder;
private final String soOrderId; private final String soOrderId;
private final JsonObject safetyOrder; private final JsonArray safetyOrders;
private final double feesPaidInBase; private final double feesPaidInBase;
private final double feesPaidInQuote; private final double feesPaidInQuote;
private final double partialProfit; private final double partialProfit;
@ -1070,7 +1075,7 @@ public class InstanceInterface {
private final OldLongDictionary oldLongDictionary; //Change type private final OldLongDictionary oldLongDictionary; //Change type
private final String statusString; private final String statusString;
public WorkerStatsData(String pair, boolean isShort, boolean isBoosted, boolean isPaused, boolean autoSwitchEnabled, boolean stopWhenProfit, double orderSize, double quoteSpent, double baseBought, int soAmount, int numberOfSafetyOrders, int tpMode, String profitTable, double startTime, double startPrice, double dealStartTime, double dealUptime, double totalUptime, double price, double takeProfitPrice, double nextSoPrice, String tpOrderId, JsonObject takeProfitOrder, String soOrderId, JsonObject safetyOrder, double feesPaidInBase, double feesPaidInQuote, double partialProfit, String safetyPriceTable, String dealOrderHistory, String pauseReason, OldLongDictionary oldLong, String statusString) { public WorkerStatsData(String pair, boolean isShort, boolean isBoosted, boolean isPaused, boolean autoSwitchEnabled, boolean stopWhenProfit, double orderSize, double quoteSpent, double baseBought, int soAmount, int numberOfSafetyOrders, int tpMode, String profitTable, double startTime, double startPrice, double dealStartTime, double dealUptime, double totalUptime, double price, double takeProfitPrice, double nextSoPrice, String tpOrderId, JsonObject takeProfitOrder, String soOrderId, JsonArray safetyOrders, double feesPaidInBase, double feesPaidInQuote, double partialProfit, String safetyPriceTable, String dealOrderHistory, String pauseReason, OldLongDictionary oldLong, String statusString) {
this.pair = pair; this.pair = pair;
this.isShort = isShort; this.isShort = isShort;
this.isBoosted = isBoosted; this.isBoosted = isBoosted;
@ -1095,7 +1100,7 @@ public class InstanceInterface {
this.tpOrderId = tpOrderId; this.tpOrderId = tpOrderId;
this.takeProfitOrder = takeProfitOrder; this.takeProfitOrder = takeProfitOrder;
this.soOrderId = soOrderId; this.soOrderId = soOrderId;
this.safetyOrder = safetyOrder; this.safetyOrders = safetyOrders;
this.feesPaidInBase = feesPaidInBase; this.feesPaidInBase = feesPaidInBase;
this.feesPaidInQuote = feesPaidInQuote; this.feesPaidInQuote = feesPaidInQuote;
this.partialProfit = partialProfit; this.partialProfit = partialProfit;
@ -1129,7 +1134,7 @@ public class InstanceInterface {
public String getTpOrderId() { return tpOrderId; } public String getTpOrderId() { return tpOrderId; }
public JsonObject getTakeProfitOrder() { return takeProfitOrder; } public JsonObject getTakeProfitOrder() { return takeProfitOrder; }
public String getSoOrderId() { return soOrderId; } public String getSoOrderId() { return soOrderId; }
public JsonObject getSafetyOrder() { return safetyOrder; } public JsonArray getSafetyOrders() { return safetyOrders; }
public double getFeesPaidInBase() { return feesPaidInBase; } public double getFeesPaidInBase() { return feesPaidInBase; }
public double getFeesPaidInQuote() { return feesPaidInQuote; } public double getFeesPaidInQuote() { return feesPaidInQuote; }
public double getPartialProfit() { return partialProfit; } public double getPartialProfit() { return partialProfit; }

View File

@ -23,6 +23,7 @@ import com.example.dcav2gui.ui.exchanges.adapters.WorkerCardAdapter;
import com.example.dcav2gui.ui.home.HomeFragment; import com.example.dcav2gui.ui.home.HomeFragment;
import com.google.android.material.materialswitch.MaterialSwitch; import com.google.android.material.materialswitch.MaterialSwitch;
import com.google.gson.Gson; import com.google.gson.Gson;
import com.google.gson.JsonArray;
import com.google.gson.JsonElement; import com.google.gson.JsonElement;
import com.google.gson.JsonObject; import com.google.gson.JsonObject;
import com.google.gson.JsonParser; import com.google.gson.JsonParser;
@ -94,9 +95,17 @@ public class WorkerInterface {
double takeProfitPrice = value.has("take_profit_price") && value.get("take_profit_price").isJsonPrimitive() ? value.get("take_profit_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; double nextSoPrice = value.has("next_so_price") && value.get("next_so_price").isJsonPrimitive() ? value.get("next_so_price").getAsDouble() : 0.0;
JsonObject takeProfitOrder = value.get("take_profit_order").getAsJsonObject(); JsonObject takeProfitOrder = value.get("take_profit_order").getAsJsonObject();
JsonObject safetyOrder = value.get("safety_order").getAsJsonObject(); JsonArray safetyOrders = null;
String safetyOrderId = "";
JsonElement safetyOrderElements = value.get("safety_orders");
if (safetyOrderElements!=null && !safetyOrderElements.isJsonNull() && safetyOrderElements.isJsonArray()) {
safetyOrders = safetyOrderElements.getAsJsonArray();
if (!safetyOrders.isEmpty()) {
JsonObject firstSafetyOrder = safetyOrders.get(0).getAsJsonObject();
safetyOrderId = firstSafetyOrder.has("id") && firstSafetyOrder.get("id").isJsonPrimitive() ? firstSafetyOrder.get("id").getAsString() : "";
}
}
String tpOrderId = takeProfitOrder.has("id") && takeProfitOrder.get("id").isJsonPrimitive() ? takeProfitOrder.get("id").getAsString() : null; String tpOrderId = takeProfitOrder.has("id") && takeProfitOrder.get("id").isJsonPrimitive() ? takeProfitOrder.get("id").getAsString() : null;
String safetyOrderId = safetyOrder.has("id") && safetyOrder.get("id").isJsonPrimitive() ? safetyOrder.get("id").getAsString() : null;
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 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; double feesPaidInQuote = value.has("fees_paid_in_quote") && value.get("fees_paid_in_quote").isJsonPrimitive() ? value.get("fees_paid_in_quote").getAsDouble() : 0.0;
double partialProfit = value.has("partial_profit") && value.get("partial_profit").isJsonPrimitive() ? value.get("partial_profit").getAsDouble() : 0.0; double partialProfit = value.has("partial_profit") && value.get("partial_profit").isJsonPrimitive() ? value.get("partial_profit").getAsDouble() : 0.0;
@ -144,7 +153,7 @@ public class WorkerInterface {
tpOrderId, tpOrderId,
takeProfitOrder, takeProfitOrder,
safetyOrderId, safetyOrderId,
safetyOrder, safetyOrders,
feesPaidInBase, feesPaidInBase,
feesPaidInQuote, feesPaidInQuote,
partialProfit, partialProfit,

View File

@ -1,7 +1,7 @@
<resources> <resources>
<string name="app_name" translatable="false">DCAv2GUI</string> <string name="app_name" translatable="false">DCAv2GUI</string>
<string name="nav_header_title" translatable="false">DCAv2</string> <string name="nav_header_title" translatable="false">DCAv2</string>
<string name="nav_header_subtitle">Version 2025.05.16</string> <string name="nav_header_subtitle">Version 2025.09.05</string>
<string name="navigation_drawer_open">Open navigation drawer</string> <string name="navigation_drawer_open">Open navigation drawer</string>
<string name="navigation_drawer_close">Close navigation drawer</string> <string name="navigation_drawer_close">Close navigation drawer</string>
<string name="nav_header_desc">Navigation header</string> <string name="nav_header_desc">Navigation header</string>