This commit is contained in:
Nicolás Sánchez 2024-12-16 19:40:37 -03:00
parent a4767708dd
commit 54c2247b6f
2 changed files with 47 additions and 7 deletions

View File

@ -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<WorkerData> fetchWorkersDataForCards(String exchange) throws IOException {
// Implement this method to fetch actual data
// call List<WorkerStatsData> getAllWorkersStats from InstanceInterface and
// translate all the WorkerStatsData objects to WorkerData objects!
// Example implementation:
List<InstanceInterface.WorkerStatsData> workerStatsDataList = InstanceInterface.getAllWorkersStats(exchange, true);
List<WorkerData> 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; }
}

View File

@ -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<WorkerData> newData = null; // Implement this method to fetch actual data
workerDataList.setValue(newData);
List<WorkerData> newData = InstanceInterface.fetchWorkersDataForCards("binance");
workerDataList.postValue(newData);
} catch (InterruptedException e) {
e.printStackTrace();
} catch (IOException e) {
throw new RuntimeException(e);
}
}
}).start();
}
}
}