1 package org.oxerr.chbtc.service.polling; 2 3 import java.io.IOException; 4 import java.util.Collection; 5 import java.util.HashMap; 6 import java.util.Map; 7 8 import org.oxerr.chbtc.CHBTCMarketData; 9 import org.oxerr.chbtc.CHBTCMarketDataBTC; 10 import org.oxerr.chbtc.CHBTCMarketDataLTC; 11 import org.oxerr.chbtc.dto.Depth; 12 import org.oxerr.chbtc.dto.TickerResponse; 13 import org.oxerr.chbtc.dto.Trade; 14 15 import si.mazi.rescu.RestProxyFactory; 16 17 import com.xeiam.xchange.Exchange; 18 import com.xeiam.xchange.ExchangeSpecification; 19 import com.xeiam.xchange.currency.Currencies; 20 import com.xeiam.xchange.currency.CurrencyPair; 21 22 public class CHBTCMarketDataServiceRaw extends CHBTCBasePollingService { 23 24 private final Map<String, CHBTCMarketData> chbtcMarketDatas = new HashMap<>(2); 25 26 protected CHBTCMarketDataServiceRaw(Exchange exchange) { 27 super(exchange); 28 ExchangeSpecification spec = exchange.getExchangeSpecification(); 29 final String baseUrl = spec.getPlainTextUri(); 30 final Collection<CurrencyPair> exchangeSymbols; 31 try { 32 exchangeSymbols = getExchangeSymbols(); 33 } catch (IOException e) { 34 throw new RuntimeException(e); 35 } 36 if (exchangeSymbols.contains(CurrencyPair.BTC_CNY)) { 37 chbtcMarketDatas.put(Currencies.BTC, 38 RestProxyFactory.createProxy( 39 CHBTCMarketDataBTC.class, baseUrl)); 40 } 41 if (exchangeSymbols.contains(CurrencyPair.LTC_CNY)) { 42 chbtcMarketDatas.put(Currencies.LTC, 43 RestProxyFactory.createProxy( 44 CHBTCMarketDataLTC.class, baseUrl)); 45 } 46 } 47 48 public TickerResponse getTicker(CurrencyPair currencyPair) 49 throws IOException { 50 return getData(currencyPair).getTicker(); 51 } 52 53 public Depth getDepth(CurrencyPair currencyPair) throws IOException { 54 return getData(currencyPair).getDepth(); 55 } 56 57 public Trade[] getTrades(CurrencyPair currencyPair) throws IOException { 58 return getData(currencyPair).getTrades(); 59 } 60 61 public Trade[] getTrades(CurrencyPair currencyPair, long since) 62 throws IOException { 63 return getData(currencyPair).getTrades(since); 64 } 65 66 private CHBTCMarketData getData(CurrencyPair currencyPair) { 67 return chbtcMarketDatas.get(currencyPair.baseSymbol); 68 } 69 70 }