From 73ce744bf7b63a89dd8a70eb5228dcb174d87afd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicol=C3=A1s=20S=C3=A1nchez?= Date: Sat, 14 Dec 2024 18:55:15 -0300 Subject: [PATCH] Exchange global stats done --- .../example/dcav2gui/InstanceInterface.java | 39 +++++++++++++++++-- .../dcav2gui/ui/home/HomeFragment.java | 8 ++++ 2 files changed, 43 insertions(+), 4 deletions(-) diff --git a/app/src/main/java/com/example/dcav2gui/InstanceInterface.java b/app/src/main/java/com/example/dcav2gui/InstanceInterface.java index 5231d47..f7cbea7 100644 --- a/app/src/main/java/com/example/dcav2gui/InstanceInterface.java +++ b/app/src/main/java/com/example/dcav2gui/InstanceInterface.java @@ -276,6 +276,14 @@ public class InstanceInterface { } + private static double gibSoSize(double orderSize, int n, double safetyOrderScale) { + double targetOrderSize = orderSize; + for (int i = 0; i < n; i++) { + targetOrderSize = targetOrderSize*safetyOrderScale*100; + } + return targetOrderSize; + + } public static ExchangeStatsData getExchangeStatsData(String exchange) throws IOException { double lastSeen; @@ -298,6 +306,16 @@ public class InstanceInterface { //Funds needed fundsNeeded = 0; + if (workers != null) { + for (WorkerStatsData worker : workers) { + if (!worker.isShort) { + for (int i = worker.getSoAmount(); i <= worker.getNumberOfSafetyOrders(); i++) { + fundsNeeded += gibSoSize(worker.getOrderSize(),i,0.0105); // I know I know + } + + } + } + } //Online workers if (workers != null) { @@ -308,9 +326,17 @@ public class InstanceInterface { //Long workers longWorkers = 0; - - //Short workers shortWorkers = 0; + if (workers != null) { + for (WorkerStatsData worker : workers) { + if (!worker.isShort) { + longWorkers++; + } + else { + shortWorkers++; + } + } + } return new ExchangeStatsData(lastSeen,fundsAvailable,fundsNeeded,onlineWorkers,longWorkers,shortWorkers); } @@ -382,6 +408,7 @@ public class InstanceInterface { double quoteSpent = value.has("quote_spent") && value.get("quote_spent").isJsonPrimitive() ? value.get("quote_spent").getAsDouble() : 0.0; double baseBought = value.has("base_bought") && value.get("base_bought").isJsonPrimitive() ? value.get("base_bought").getAsDouble() : 0.0; int soAmount = value.has("so_amount") && value.get("so_amount").isJsonPrimitive() ? value.get("so_amount").getAsInt() : 0; + int numberOfSafetyOrders = value.has("no_of_safety_orders") && value.get("no_of_safety_orders").isJsonPrimitive() ? value.get("no_of_safety_orders").getAsInt() : 0; int tpMode = value.has("tp_mode") && value.get("tp_mode").isJsonPrimitive() ? value.get("tp_mode").getAsInt() : 0; String profitTable = value.has("profit_table") && value.get("profit_table").isJsonPrimitive() ? value.get("profit_table").getAsString() : null; double startTime = value.has("start_time") && value.get("start_time").isJsonPrimitive() ? value.get("start_time").getAsDouble() : 0.0; @@ -417,6 +444,7 @@ public class InstanceInterface { quoteSpent, baseBought, soAmount, + numberOfSafetyOrders, tpMode, profitTable, startTime, @@ -682,6 +710,7 @@ public class InstanceInterface { private final double quoteSpent; private final double baseBought; private final int soAmount; + private final int numberOfSafetyOrders; private final int tpMode; private final String profitTable; private final double startTime; @@ -706,13 +735,14 @@ public class InstanceInterface { private final JsonObject oldLongDictionary; //Change type private final String statusString; - public WorkerStatsData(boolean isShort, boolean stopWhenProfit, double orderSize, double quoteSpent, double baseBought, int soAmount, 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, JsonObject oldLong, String statusString) { + public WorkerStatsData(boolean isShort, 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, JsonObject oldLong, String statusString) { this.isShort = isShort; this.stopWhenProfit = stopWhenProfit; this.orderSize = orderSize; this.quoteSpent = quoteSpent; this.baseBought = baseBought; this.soAmount = soAmount; + this.numberOfSafetyOrders = numberOfSafetyOrders; this.tpMode = tpMode; this.profitTable = profitTable; this.startTime = startTime; @@ -742,7 +772,8 @@ public class InstanceInterface { public double getOrderSize() { return orderSize; } public double getQuoteSpent() { return quoteSpent; } public double getBaseBought() { return baseBought; } - public double getSoAmount() { return soAmount; } + public int getSoAmount() { return soAmount; } + public int getNumberOfSafetyOrders() {return numberOfSafetyOrders; } public int getTpMode() { return tpMode; } public String getProfitTable() { return profitTable; } public double getStartTime() { return startTime; } diff --git a/app/src/main/java/com/example/dcav2gui/ui/home/HomeFragment.java b/app/src/main/java/com/example/dcav2gui/ui/home/HomeFragment.java index e10f6bc..f90b5ec 100644 --- a/app/src/main/java/com/example/dcav2gui/ui/home/HomeFragment.java +++ b/app/src/main/java/com/example/dcav2gui/ui/home/HomeFragment.java @@ -693,15 +693,23 @@ public class HomeFragment extends Fragment { if (binanceGlobalStats != null) { exchange1WorkersOnline.setText(String.valueOf(binanceGlobalStats.getOnlineWorkers())); + String longShortWorkers = String.valueOf(binanceGlobalStats.getLongWorkers()) + "/" + String.valueOf(binanceGlobalStats.getShortWorkers()); + exchange1WorkersLongShort.setText(longShortWorkers); } if (gateioGlobalStats != null) { exchange2WorkersOnline.setText(String.valueOf(gateioGlobalStats.getOnlineWorkers())); + String longShortWorkers = String.valueOf(gateioGlobalStats.getLongWorkers()) + "/" + String.valueOf(gateioGlobalStats.getShortWorkers()); + exchange2WorkersLongShort.setText(longShortWorkers); } if (kucoinGlobalStats != null) { exchange3WorkersOnline.setText(String.valueOf(kucoinGlobalStats.getOnlineWorkers())); + String longShortWorkers = String.valueOf(kucoinGlobalStats.getLongWorkers()) + "/" + String.valueOf(kucoinGlobalStats.getShortWorkers()); + exchange3WorkersLongShort.setText(longShortWorkers); } if (okexGlobalStats != null) { exchange4WorkersOnline.setText(String.valueOf(okexGlobalStats.getOnlineWorkers())); + String longShortWorkers = String.valueOf(okexGlobalStats.getLongWorkers()) + "/" + String.valueOf(okexGlobalStats.getShortWorkers()); + exchange4WorkersLongShort.setText(longShortWorkers); } });