Search in sources :

Example 1 with PriceData

use of io.bitsquare.pricefeed.PriceData in project bitsquare by bitsquare.

the class PoloniexProvider method request.

public Map<String, PriceData> request() throws IOException, HttpException {
    Map<String, PriceData> marketPriceMap = new HashMap<>();
    String response = httpClient.requestWithGET("?command=returnTicker", "User-Agent", "");
    LinkedTreeMap<String, Object> treeMap = new Gson().fromJson(response, LinkedTreeMap.class);
    treeMap.entrySet().stream().forEach(e -> {
        Object value = e.getValue();
        String invertedCurrencyPair = e.getKey();
        String altcoinCurrency = null;
        if (invertedCurrencyPair.startsWith("BTC")) {
            String[] tokens = invertedCurrencyPair.split("_");
            if (tokens.length == 2) {
                altcoinCurrency = tokens[1];
                if (supportedAltcoins.contains(altcoinCurrency)) {
                    if (value instanceof LinkedTreeMap) {
                        LinkedTreeMap<String, Object> data = (LinkedTreeMap) value;
                        marketPriceMap.put(altcoinCurrency, new PriceData(altcoinCurrency, parseDouble((String) data.get("lowestAsk")), parseDouble((String) data.get("highestBid")), parseDouble((String) data.get("last"))));
                    }
                }
            } else {
                log.error("invertedCurrencyPair has invalid format: invertedCurrencyPair=" + invertedCurrencyPair);
            }
        }
    });
    return marketPriceMap;
}
Also used : LinkedTreeMap(com.google.gson.internal.LinkedTreeMap) HashMap(java.util.HashMap) PriceData(io.bitsquare.pricefeed.PriceData) Gson(com.google.gson.Gson)

Example 2 with PriceData

use of io.bitsquare.pricefeed.PriceData in project bitsquare by bitsquare.

the class CoinmarketcapProvider method request.

public Map<String, PriceData> request() throws IOException, HttpException {
    Map<String, PriceData> marketPriceMap = new HashMap<>();
    String response = httpClient.requestWithGET("v1/ticker/?limit=200", "User-Agent", "");
    List<LinkedTreeMap<String, Object>> list = new Gson().fromJson(response, ArrayList.class);
    list.stream().forEach(treeMap -> {
        String code = (String) treeMap.get("symbol");
        if (supportedAltcoins.contains(code)) {
            double price_btc = parseDouble((String) treeMap.get("price_btc"));
            marketPriceMap.put(code, new PriceData(code, price_btc, price_btc, price_btc));
        }
    });
    return marketPriceMap;
}
Also used : LinkedTreeMap(com.google.gson.internal.LinkedTreeMap) PriceData(io.bitsquare.pricefeed.PriceData) Gson(com.google.gson.Gson)

Example 3 with PriceData

use of io.bitsquare.pricefeed.PriceData in project bitsquare by bitsquare.

the class BtcAverageProvider method getMap.

private Map<String, PriceData> getMap(String json) {
    Map<String, PriceData> marketPriceMap = new HashMap<>();
    LinkedTreeMap<String, Object> treeMap = new Gson().<LinkedTreeMap<String, Object>>fromJson(json, LinkedTreeMap.class);
    treeMap.entrySet().stream().forEach(e -> {
        Object value = e.getValue();
        if (value instanceof LinkedTreeMap) {
            LinkedTreeMap<String, Object> data = (LinkedTreeMap) value;
            String currencyCode = e.getKey().substring(3);
            marketPriceMap.put(currencyCode, new PriceData(currencyCode, (double) data.get("ask"), (double) data.get("bid"), (double) data.get("last")));
        }
    });
    return marketPriceMap;
}
Also used : LinkedTreeMap(com.google.gson.internal.LinkedTreeMap) HashMap(java.util.HashMap) PriceData(io.bitsquare.pricefeed.PriceData) Gson(com.google.gson.Gson)

Aggregations

Gson (com.google.gson.Gson)3 LinkedTreeMap (com.google.gson.internal.LinkedTreeMap)3 PriceData (io.bitsquare.pricefeed.PriceData)3 HashMap (java.util.HashMap)2