Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Simplify offers query. Requires risq v0.3.0 #3

Merged
merged 1 commit into from
Oct 31, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 12 additions & 31 deletions src/main/java/bisq/markets/api/GraphQLQuery.java
Original file line number Diff line number Diff line change
Expand Up @@ -108,13 +108,16 @@ public int compareTo(OpenOffer o) {
}
}
}
private static final String offerFields = "{ " +
"market: marketPair offer_id: id offer_date: offerDate " +
"direction min_amount: formattedMinAmount " +
"amount: formattedAmount price: formattedPrice " +
"volume: formattedVolume payment_method: paymentMethodId " +
"offer_fee_txid: offerFeeTxId } ";
private static final String offersQuery = "query Offers($market: MarketPair, $direction: Direction)" +
"{ offers(market: $market, direction: $direction) { " +
"market: marketPair offer_id: id offer_date: offerDate " +
"direction min_amount: formattedMinAmount " +
"amount: formattedAmount price: formattedPrice " +
"volume: formattedVolume payment_method: paymentMethodId " +
"offer_fee_txid: offerFeeTxId } }";
"buys " + offerFields +
"sells " + offerFields + " } }";
private final String query = offersQuery;
private final Map<String,String> variables;

Expand All @@ -124,31 +127,8 @@ public int compareTo(OpenOffer o) {

@Override
public Object translateResponse(String response) {
GraphQLResponse<List<OpenOffer>> offers = gson.fromJson(response,new TypeToken<GraphQLResponse<List<OpenOffer>>>(){}.getType());

Iterator<OpenOffer> iter = offers.getData().iterator();
Map<String,Map<String,List<OpenOffer>>> ret = new HashMap<>();
while(iter.hasNext()) {
OpenOffer offer = iter.next();
if (!ret.containsKey(offer.market)) {
Map<String,List<OpenOffer>> directions = new HashMap<>();
directions.put("buys",new ArrayList<>());
directions.put("sells",new ArrayList<>());
ret.put(offer.market, directions);
}
Map<String,List<OpenOffer>> directions = ret.get(offer.market);
if (offer.direction.equals("BUY")) {
List<OpenOffer> buys = directions.get("buys");
buys.add(offer);
Collections.sort(buys);
Collections.reverse(buys);
} else {
List<OpenOffer> sells = directions.get("sells");
sells.add(offer);
Collections.sort(sells);
}
}
return ret;
GraphQLResponse<Map<String,List<OpenOffer>>> offers = gson.fromJson(response,new TypeToken<GraphQLResponse<Map<String,List<OpenOffer>>>>(){}.getType());
return offers.getData();
}
}

Expand All @@ -158,7 +138,8 @@ private static class Depth {
List<String> sells;
}
private static final String depthQuery = "query Depth($market: MarketPair!)" +
"{ depth(market: $market) { buys: formattedBuys sells: formattedSells } }";
"{ offers(market: $market) { " +
"buys: formattedBuyPrices sells: formattedSellPrices } }";
private final String query = depthQuery;
private final Map<String,String> variables;

Expand Down