Log list
This commit is contained in:
parent
a8f58d59ac
commit
ade62f87c6
|
|
@ -62,11 +62,12 @@ public class InstanceInterface {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public static List<String> getLastTradesFromExchange(String exchange) throws IOException {
|
public static List<DealData> getLastTradesFromExchange(String exchange) throws IOException {
|
||||||
Request dealsRequest = new Request.Builder()
|
Request dealsRequest = new Request.Builder()
|
||||||
.url(API_BASE_URL + "/" + exchange + "/get_deals_cache")
|
.url(API_BASE_URL + "/" + exchange + "/get_deals_cache")
|
||||||
.header("X-API-KEY", API_KEY)
|
.header("X-API-KEY", API_KEY)
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
try (Response statsResponse = httpClient.newCall(dealsRequest).execute()) {
|
try (Response statsResponse = httpClient.newCall(dealsRequest).execute()) {
|
||||||
if (!statsResponse.isSuccessful()) {
|
if (!statsResponse.isSuccessful()) {
|
||||||
throw new IOException("Unexpected code " + statsResponse);
|
throw new IOException("Unexpected code " + statsResponse);
|
||||||
|
|
@ -87,14 +88,56 @@ public class InstanceInterface {
|
||||||
//(timestamp,pair,amount,exchange_name,order_id,order_history)
|
//(timestamp,pair,amount,exchange_name,order_id,order_history)
|
||||||
//order history always is an empty string when querying the deals cache
|
//order history always is an empty string when querying the deals cache
|
||||||
//It can be safely ignored
|
//It can be safely ignored
|
||||||
|
JsonArray dealsArray = jsonObject.getAsJsonArray("Deals");
|
||||||
|
List<DealData> dealDataList = new ArrayList<>();
|
||||||
|
|
||||||
|
for (int i = 0; i < dealsArray.size(); i++) {
|
||||||
|
JsonObject dealObject = dealsArray.get(i).getAsJsonObject();
|
||||||
|
|
||||||
return null;
|
long timestamp = dealObject.get("timestamp").getAsLong();
|
||||||
|
String pair = dealObject.get("pair").getAsString();
|
||||||
|
double amount = dealObject.get("amount").getAsDouble();
|
||||||
|
String exchangeName = dealObject.get("exchange_name").getAsString();
|
||||||
|
String orderId = dealObject.get("order_id").getAsString();
|
||||||
|
|
||||||
|
DealData dealData = new DealData(timestamp, pair, amount, exchangeName, orderId, "");
|
||||||
|
dealDataList.add(dealData);
|
||||||
|
}
|
||||||
|
return dealDataList;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static List<String> getLastLogs(int amount) throws IOException {
|
public static List<String> getLastLogs() throws IOException {
|
||||||
return null;
|
Request logRequest = new Request.Builder()
|
||||||
|
.url(API_BASE_URL + "/get_log_lisd")
|
||||||
|
.header("X-API-KEY", API_KEY)
|
||||||
|
.build();
|
||||||
|
|
||||||
|
|
||||||
|
try (Response statsResponse = httpClient.newCall(logRequest).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("Logs")) {
|
||||||
|
System.err.println("The parsed JSON response does not contain the logs key.");
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
JsonArray logsArray = jsonObject.getAsJsonArray("Logs");
|
||||||
|
List<String> logList = new ArrayList<>();
|
||||||
|
for (int i = 0; i < logsArray.size(); i++) {
|
||||||
|
logList.add(logsArray.get(i).getAsString());
|
||||||
|
}
|
||||||
|
|
||||||
|
return logList;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -248,13 +291,15 @@ public class InstanceInterface {
|
||||||
public static class DealData {
|
public static class DealData {
|
||||||
private final double timestamp;
|
private final double timestamp;
|
||||||
private final String pair;
|
private final String pair;
|
||||||
|
private final double amount;
|
||||||
private final String exchangeName;
|
private final String exchangeName;
|
||||||
private final String orderId;
|
private final String orderId;
|
||||||
private final String orderHistory;
|
private final String orderHistory;
|
||||||
|
|
||||||
public DealData(double timestamp, String pair, String exchangeName, String orderId, String orderHistory) {
|
public DealData(double timestamp, String pair, double amount, String exchangeName, String orderId, String orderHistory) {
|
||||||
this.timestamp = timestamp;
|
this.timestamp = timestamp;
|
||||||
this.pair = pair;
|
this.pair = pair;
|
||||||
|
this.amount = amount;
|
||||||
this.exchangeName = exchangeName;
|
this.exchangeName = exchangeName;
|
||||||
this.orderId = orderId;
|
this.orderId = orderId;
|
||||||
this.orderHistory = orderHistory;
|
this.orderHistory = orderHistory;
|
||||||
|
|
@ -262,6 +307,7 @@ public class InstanceInterface {
|
||||||
|
|
||||||
public double getTimestamp() { return timestamp; }
|
public double getTimestamp() { return timestamp; }
|
||||||
public String getPair() { return pair; }
|
public String getPair() { return pair; }
|
||||||
|
public double getAmount() {return amount; }
|
||||||
public String getExchangeName() { return exchangeName; }
|
public String getExchangeName() { return exchangeName; }
|
||||||
public String getOrderId() { return orderId; }
|
public String getOrderId() { return orderId; }
|
||||||
public String getOrderHistory() { return orderHistory; }
|
public String getOrderHistory() { return orderHistory; }
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue