package com.mobnetic.coinguardian.model.market.example; import java.util.HashMap; import java.util.LinkedHashMap; import org.json.JSONObject; import com.mobnetic.coinguardian.model.CheckerInfo; import com.mobnetic.coinguardian.model.Market; import com.mobnetic.coinguardian.model.Ticker; import com.mobnetic.coinguardian.model.currency.Currency; import com.mobnetic.coinguardian.model.currency.VirtualCurrency; public class MarketExample extends Market { private final static String NAME = "Market Example"; private final static String TTS_NAME = NAME; private final static String URL = "https://www.marketexample.com/api/%1$s_%2$s/ticker/"; private final static HashMap CURRENCY_PAIRS = new LinkedHashMap(); static { CURRENCY_PAIRS.put(VirtualCurrency.BTC, new String[]{ Currency.CNY, Currency.USD }); CURRENCY_PAIRS.put(VirtualCurrency.DOGE, new String[]{ VirtualCurrency.BTC, Currency.USD }); } public MarketExample() { super(NAME, TTS_NAME, CURRENCY_PAIRS); } @Override public String getUrl(int requestId, CheckerInfo checkerInfo) { return String.format(URL, checkerInfo.getCurrencyBase(), checkerInfo.getCurrencyCounter()); } @Override protected void parseTickerFromJsonObject(int requestId, JSONObject jsonObject, Ticker ticker, CheckerInfo checkerInfo) throws Exception { ticker.bid = jsonObject.getDouble("bid"); ticker.ask = jsonObject.getDouble("ask"); ticker.vol = jsonObject.getDouble("volume"); ticker.high = jsonObject.getDouble("high"); ticker.low = jsonObject.getDouble("low"); ticker.last = jsonObject.getDouble("last"); ticker.timestamp = jsonObject.getLong("timestamp"); } }