diff --git a/app/src/main/java/com/example/dcav2gui/InstanceInterface.java b/app/src/main/java/com/example/dcav2gui/InstanceInterface.java index 552a0f8..007e215 100644 --- a/app/src/main/java/com/example/dcav2gui/InstanceInterface.java +++ b/app/src/main/java/com/example/dcav2gui/InstanceInterface.java @@ -2,6 +2,7 @@ package com.example.dcav2gui; import static com.example.dcav2gui.MainActivity.globalSettings; +import com.example.dcav2gui.ui.exchanges.WorkerData; import com.google.gson.JsonArray; import com.google.gson.JsonElement; import com.google.gson.JsonObject; @@ -449,6 +450,7 @@ public class InstanceInterface { JsonObject oldLong = null; if (value.has("old_long")) { oldLong = value.get("old_long").getAsJsonObject(); + //translate from json to OldLongDictionary } valueToReturn.add(new WorkerStatsData( @@ -601,6 +603,34 @@ public class InstanceInterface { } } + public static List fetchWorkersDataForCards(String exchange) throws IOException { + // Implement this method to fetch actual data + // call List getAllWorkersStats from InstanceInterface and + // translate all the WorkerStatsData objects to WorkerData objects! + // Example implementation: + List workerStatsDataList = InstanceInterface.getAllWorkersStats(exchange, true); + List workerDataList = new ArrayList<>(); + if (workerStatsDataList != null) { + for (InstanceInterface.WorkerStatsData workerStatsData : workerStatsDataList) { + WorkerData workerData = new WorkerData( + workerStatsData.getPair(), + workerStatsData.getSoAmount(), + workerStatsData.getNumberOfSafetyOrders(), + workerStatsData.getDealUptime(), + workerStatsData.getNextSoPrice(), + workerStatsData.getPrice(), + workerStatsData.getTakeProfitPrice(), + workerStatsData.getIsShort(), + false, + false, + false, + workerStatsData.getOldLongDictionary()); + workerDataList.add(workerData); + } + } + return workerDataList; + } + public static class DealData { private final double timestamp; @@ -774,10 +804,10 @@ public class InstanceInterface { private final String safetyPriceTable; private final String dealOrderHistory; private final String pauseReason; - private final JsonObject oldLongDictionary; //Change type + private final OldLongDictionary oldLongDictionary; //Change type private final String statusString; - public WorkerStatsData(String pair, 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) { + public WorkerStatsData(String pair, 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, OldLongDictionary oldLong, String statusString) { this.pair = pair; this.isShort = isShort; this.stopWhenProfit = stopWhenProfit; @@ -838,7 +868,7 @@ public class InstanceInterface { public String getSafetyPriceTable() { return safetyPriceTable; } public String getDealOrderHistory() { return dealOrderHistory; } public String getPauseReason() { return pauseReason; } - public JsonObject getOldLongDictionary() { return oldLongDictionary; } + public OldLongDictionary getOldLongDictionary() { return oldLongDictionary; } public String getStatusString() { return statusString; } } diff --git a/app/src/main/java/com/example/dcav2gui/ui/exchanges/BinanceViewModel.java b/app/src/main/java/com/example/dcav2gui/ui/exchanges/BinanceViewModel.java index 7009a4a..feb05ca 100644 --- a/app/src/main/java/com/example/dcav2gui/ui/exchanges/BinanceViewModel.java +++ b/app/src/main/java/com/example/dcav2gui/ui/exchanges/BinanceViewModel.java @@ -4,6 +4,12 @@ import androidx.annotation.NonNull; import androidx.lifecycle.AndroidViewModel; import androidx.lifecycle.LiveData; import androidx.lifecycle.MutableLiveData; + + +import com.example.dcav2gui.InstanceInterface; +import com.google.gson.JsonObject; + +import java.io.IOException; import java.util.ArrayList; import java.util.List; @@ -33,13 +39,17 @@ public class BinanceViewModel extends AndroidViewModel { try { Thread.sleep(5000); // Fetch and update the data - List newData = null; // Implement this method to fetch actual data - workerDataList.setValue(newData); + List newData = InstanceInterface.fetchWorkersDataForCards("binance"); + workerDataList.postValue(newData); } catch (InterruptedException e) { e.printStackTrace(); + } catch (IOException e) { + throw new RuntimeException(e); } } }).start(); - } -} + + + +} \ No newline at end of file