diff --git a/app/src/main/java/com/example/dcav2gui/InstanceInterface.java b/app/src/main/java/com/example/dcav2gui/InstanceInterface.java index 60dbe47..0294590 100644 --- a/app/src/main/java/com/example/dcav2gui/InstanceInterface.java +++ b/app/src/main/java/com/example/dcav2gui/InstanceInterface.java @@ -46,7 +46,6 @@ public class InstanceInterface { } public static double getTraderTime(String exchange) throws IOException { - //Uptime request Request uptimeRequest = new Request.Builder() .url(API_BASE_URL + "/" + exchange + "/trader_time") .header("X-API-KEY", API_KEY) @@ -63,19 +62,44 @@ public class InstanceInterface { } + public static List getLastTradesFromExchange(String exchange) throws IOException { + Request dealsRequest = new Request.Builder() + .url(API_BASE_URL + "/" + exchange + "/get_deals_cache") + .header("X-API-KEY", API_KEY) + .build(); + try (Response statsResponse = httpClient.newCall(dealsRequest).execute()) { + if (!statsResponse.isSuccessful()) { + throw new IOException("Unexpected code " + statsResponse); + } + String dealsResponseBody = statsResponse.body().string(); + JsonElement jsonElement = JsonParser.parseString(dealsResponseBody); + if (!jsonElement.isJsonObject()) { + System.err.println("The parsed JSON response is not a JsonObject."); + return null; + } + JsonObject jsonObject = jsonElement.getAsJsonObject(); + if (!jsonObject.has("Deals")) { + System.err.println("The parsed JSON response does not contain the deals key."); + return null; + } + + //Return a list of items of the format: + //(timestamp,pair,amount,exchange_name,order_id,order_history) + //order history always is an empty string when querying the deals cache + //It can be safely ignored + return null; + } + } - - - + public static List getLastLogs(int amount) throws IOException { + return null; + } public static ExchangeStatsData getExchangeStatsData(String exchange) throws IOException { //This needs to do A LOT of work - - - //All workers stats request Request allWorkersStatsRequest = new Request.Builder() .url(API_BASE_URL + "/" + exchange + "/get_all_worker_status") @@ -88,10 +112,10 @@ public class InstanceInterface { .header("X-API-KEY", API_KEY) .build(); - return null; } + private static double getTodaysProfit(String jsonResponse) { try { JsonElement jsonElement = JsonParser.parseString(jsonResponse); @@ -220,6 +244,30 @@ public class InstanceInterface { } } + + public static class DealData { + private final double timestamp; + private final String pair; + private final String exchangeName; + private final String orderId; + private final String orderHistory; + + public DealData(double timestamp, String pair, String exchangeName, String orderId, String orderHistory) { + this.timestamp = timestamp; + this.pair = pair; + this.exchangeName = exchangeName; + this.orderId = orderId; + this.orderHistory = orderHistory; + } + + public double getTimestamp() { return timestamp; } + public String getPair() { return pair; } + public String getExchangeName() { return exchangeName; } + public String getOrderId() { return orderId; } + public String getOrderHistory() { return orderHistory; } + + } + public static class InstanceGlobalStatsData { private final String instanceName; private final double instanceUptime;