diff --git a/dataModule/src/main/java/com/mobnetic/coinguardian/model/market/CoinsTH.java b/dataModule/src/main/java/com/mobnetic/coinguardian/model/market/CoinsTH.java new file mode 100644 index 00000000..8bbdc79f --- /dev/null +++ b/dataModule/src/main/java/com/mobnetic/coinguardian/model/market/CoinsTH.java @@ -0,0 +1,40 @@ +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 CoinsTH extends Market { + + private final static String NAME = "Coins.TH"; + private final static String TTS_NAME = NAME; + private final static String URL = "https://coins.co.th/api/v1/quote"; + private final static HashMap CURRENCY_PAIRS = new LinkedHashMap(); + static { + CURRENCY_PAIRS.put(VirtualCurrency.BTC, new String[]{ + Currency.THB + }); + } + + 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.getJsonObject("quote").getDouble("bid"); + ticker.ask = jsonObject.getJsonObject("quote").getDouble("ask"); + ticker.last = jsonObject.getJsonObject("quote").getDouble("ask"); + } +}