From 02ec626c004813bc4472cf4ac6cc34e7e5c8e070 Mon Sep 17 00:00:00 2001 From: Dmitri Karpovich Date: Wed, 8 Jan 2025 14:24:43 +0100 Subject: [PATCH] [coinmarketcap] Delete deprecated code --- .../deprecated/v2/CoinMarketCap.java | 111 ------------ .../deprecated/v2/CoinMarketCapExchange.java | 97 ----------- .../marketdata/CoinMarketCapArrayData.java | 56 ------ .../dto/marketdata/CoinMarketCapCurrency.java | 15 -- .../CoinMarketCapHistoricalSpotPrice.java | 38 ----- .../v2/dto/marketdata/CoinMarketCapQuote.java | 97 ----------- .../dto/marketdata/CoinMarketCapTicker.java | 160 ------------------ .../CoinMarketCapMarketDataService.java | 120 ------------- .../CoinMarketCapMarketDataServiceRaw.java | 87 ---------- 9 files changed, 781 deletions(-) delete mode 100644 xchange-coinmarketcap/src/main/java/org/knowm/xchange/coinmarketcap/deprecated/v2/CoinMarketCap.java delete mode 100644 xchange-coinmarketcap/src/main/java/org/knowm/xchange/coinmarketcap/deprecated/v2/CoinMarketCapExchange.java delete mode 100644 xchange-coinmarketcap/src/main/java/org/knowm/xchange/coinmarketcap/deprecated/v2/dto/marketdata/CoinMarketCapArrayData.java delete mode 100644 xchange-coinmarketcap/src/main/java/org/knowm/xchange/coinmarketcap/deprecated/v2/dto/marketdata/CoinMarketCapCurrency.java delete mode 100644 xchange-coinmarketcap/src/main/java/org/knowm/xchange/coinmarketcap/deprecated/v2/dto/marketdata/CoinMarketCapHistoricalSpotPrice.java delete mode 100644 xchange-coinmarketcap/src/main/java/org/knowm/xchange/coinmarketcap/deprecated/v2/dto/marketdata/CoinMarketCapQuote.java delete mode 100644 xchange-coinmarketcap/src/main/java/org/knowm/xchange/coinmarketcap/deprecated/v2/dto/marketdata/CoinMarketCapTicker.java delete mode 100644 xchange-coinmarketcap/src/main/java/org/knowm/xchange/coinmarketcap/deprecated/v2/service/CoinMarketCapMarketDataService.java delete mode 100644 xchange-coinmarketcap/src/main/java/org/knowm/xchange/coinmarketcap/deprecated/v2/service/CoinMarketCapMarketDataServiceRaw.java diff --git a/xchange-coinmarketcap/src/main/java/org/knowm/xchange/coinmarketcap/deprecated/v2/CoinMarketCap.java b/xchange-coinmarketcap/src/main/java/org/knowm/xchange/coinmarketcap/deprecated/v2/CoinMarketCap.java deleted file mode 100644 index 1396b8d88ad..00000000000 --- a/xchange-coinmarketcap/src/main/java/org/knowm/xchange/coinmarketcap/deprecated/v2/CoinMarketCap.java +++ /dev/null @@ -1,111 +0,0 @@ -package org.knowm.xchange.coinmarketcap.deprecated.v2; - -import jakarta.ws.rs.GET; -import jakarta.ws.rs.Path; -import jakarta.ws.rs.Produces; -import jakarta.ws.rs.QueryParam; -import jakarta.ws.rs.core.MediaType; -import java.io.IOException; -import java.util.Objects; -import org.knowm.xchange.coinmarketcap.deprecated.v2.dto.marketdata.CoinMarketCapArrayData; -import org.knowm.xchange.coinmarketcap.deprecated.v2.dto.marketdata.CoinMarketCapTicker; -import org.knowm.xchange.currency.CurrencyPair; -import org.knowm.xchange.utils.jackson.CurrencyPairDeserializer; - -/** - * @author allenday https://api.coinmarketcap.com/v2/ticker/ - */ -@Path("/v2") -@Produces(MediaType.APPLICATION_JSON) -public interface CoinMarketCap { - - @GET - @Path("ticker") - CoinMarketCapArrayData getTickers(@QueryParam("structure") String structure) - throws IOException; - - /** - * @param start return results from rank [start] and above - * @param limit number of results. 0 = unlimited - * @see #getTickers(String structure) - */ - @GET - @Path("ticker") - CoinMarketCapArrayData getTickers( - @QueryParam("start") int start, - @QueryParam("limit") int limit, - @QueryParam("structure") String structure) - throws IOException; - - /** - * @param limit number of results. 0 = unlimited - * @param convert currency to get price converted to - * @see #getTickers(String structure) - */ - @GET - @Path("ticker") - CoinMarketCapArrayData getTickers( - @QueryParam("limit") int limit, - @QueryParam("convert") String convert, - @QueryParam("structure") String structure) - throws IOException; - - /** - * @param start return results from rank [start] and above - * @param limit number of results. 0 = unlimited - * @param convert currency to get price converted to - * @see #getTickers(String structure) - */ - @GET - @Path("ticker") - CoinMarketCapArrayData getTickers( - @QueryParam("start") int start, - @QueryParam("limit") int limit, - @QueryParam("convert") String convert, - @QueryParam("structure") String structure) - throws IOException; - - /** - * @param limit number of results. 0 = unlimited - * @see #getTickers(String structure) - */ - @GET - @Path("ticker") - CoinMarketCapArrayData getTickers( - @QueryParam("limit") int limit, @QueryParam("structure") String structure) throws IOException; - - CoinMarketCapTicker getTicker(CoinMarketCap.Pair pair); - - class Pair { - public final CurrencyPair pair; - - public Pair(CurrencyPair pair) { - this.pair = pair; - } - - public Pair(String pair) { - this(CurrencyPairDeserializer.getCurrencyPairFromString(pair)); - } - - @Override - public boolean equals(Object o) { - return this == o - || !(o == null || getClass() != o.getClass()) && Objects.equals(pair, ((Pair) o).pair); - } - - @Override - public int hashCode() { - return Objects.hash(pair); - } - - @Override - public String toString() { - return pair == null - ? "" - : String.format( - "%s%s", - pair.base.getCurrencyCode().toLowerCase(), - pair.counter.getCurrencyCode().toLowerCase()); - } - } -} diff --git a/xchange-coinmarketcap/src/main/java/org/knowm/xchange/coinmarketcap/deprecated/v2/CoinMarketCapExchange.java b/xchange-coinmarketcap/src/main/java/org/knowm/xchange/coinmarketcap/deprecated/v2/CoinMarketCapExchange.java deleted file mode 100644 index 90779ed2d72..00000000000 --- a/xchange-coinmarketcap/src/main/java/org/knowm/xchange/coinmarketcap/deprecated/v2/CoinMarketCapExchange.java +++ /dev/null @@ -1,97 +0,0 @@ -package org.knowm.xchange.coinmarketcap.deprecated.v2; - -import java.io.IOException; -import java.util.ArrayList; -import java.util.List; -import org.knowm.xchange.BaseExchange; -import org.knowm.xchange.Exchange; -import org.knowm.xchange.ExchangeSpecification; -import org.knowm.xchange.coinmarketcap.deprecated.v2.service.CoinMarketCapMarketDataService; -import org.knowm.xchange.currency.Currency; -import org.knowm.xchange.currency.CurrencyPair; -import org.knowm.xchange.dto.meta.ExchangeMetaData; -import org.knowm.xchange.exceptions.ExchangeException; -import org.knowm.xchange.instrument.Instrument; -import org.knowm.xchange.service.account.AccountService; -import org.knowm.xchange.service.marketdata.MarketDataService; -import org.knowm.xchange.service.trade.TradeService; - -/** - * @author allenday - */ -public class CoinMarketCapExchange extends BaseExchange implements Exchange { - - private CoinMarketCapMarketDataService marketDataService; - private ExchangeSpecification exchangeSpecification; - - public CoinMarketCapExchange() { - initServices(); - } - - @Override - public ExchangeSpecification getDefaultExchangeSpecification() { - final ExchangeSpecification defaultExchangeSpecification = - new ExchangeSpecification(this.getClass()); - defaultExchangeSpecification.setSslUri("https://api.coinmarketcap.com"); - defaultExchangeSpecification.setHost("coinmarketcap.com"); - defaultExchangeSpecification.setExchangeName("CoinMarketCap"); - defaultExchangeSpecification.setExchangeDescription( - "Cryptocurrency market cap rankings, charts, and more."); - return defaultExchangeSpecification; - } - - @Override - public ExchangeSpecification getExchangeSpecification() { - if (exchangeSpecification == null) exchangeSpecification = getDefaultExchangeSpecification(); - return exchangeSpecification; - } - - @Override - public void applySpecification(ExchangeSpecification exchangeSpecification) { - this.exchangeSpecification = exchangeSpecification; - } - - @Override - public ExchangeMetaData getExchangeMetaData() { - return null; - } - - @Override - public void remoteInit() throws IOException, ExchangeException { - initServices(); - } - - @Override - protected void initServices() { - if (this.marketDataService == null) { - this.marketDataService = new CoinMarketCapMarketDataService(this); - } - } - - @Override - public TradeService getTradeService() { - return null; - } - - @Override - public AccountService getAccountService() { - return null; - } - - @Override - public MarketDataService getMarketDataService() { - return marketDataService; - } - - @Override - public List getExchangeInstruments() { - List currencies = marketDataService.getCurrencies(); - - List pairs = new ArrayList<>(); - for (Currency currency : currencies) { - pairs.add(new CurrencyPair(currency, Currency.USD)); - pairs.add(new CurrencyPair(currency, Currency.BTC)); - } - return pairs; - } -} diff --git a/xchange-coinmarketcap/src/main/java/org/knowm/xchange/coinmarketcap/deprecated/v2/dto/marketdata/CoinMarketCapArrayData.java b/xchange-coinmarketcap/src/main/java/org/knowm/xchange/coinmarketcap/deprecated/v2/dto/marketdata/CoinMarketCapArrayData.java deleted file mode 100644 index 60d9768c27a..00000000000 --- a/xchange-coinmarketcap/src/main/java/org/knowm/xchange/coinmarketcap/deprecated/v2/dto/marketdata/CoinMarketCapArrayData.java +++ /dev/null @@ -1,56 +0,0 @@ -package org.knowm.xchange.coinmarketcap.deprecated.v2.dto.marketdata; - -import com.fasterxml.jackson.core.JsonParser; -import com.fasterxml.jackson.core.JsonProcessingException; -import com.fasterxml.jackson.core.ObjectCodec; -import com.fasterxml.jackson.databind.DeserializationContext; -import com.fasterxml.jackson.databind.JsonDeserializer; -import com.fasterxml.jackson.databind.JsonNode; -import com.fasterxml.jackson.databind.ObjectMapper; -import com.fasterxml.jackson.databind.annotation.JsonDeserialize; -import com.fasterxml.jackson.databind.module.SimpleModule; -import java.io.IOException; -import java.util.LinkedList; -import java.util.List; - -@JsonDeserialize(using = CoinMarketCapArrayData.CoinMarketCapTickersDeserializer.class) -public class CoinMarketCapArrayData { - - private List data; - - private CoinMarketCapArrayData(List data) { - - this.data = data; - } - - public List getData() { - return data; - } - - static class CoinMarketCapTickersDeserializer - extends JsonDeserializer> { - - @Override - public CoinMarketCapArrayData deserialize( - JsonParser jp, DeserializationContext ctxt) throws IOException, JsonProcessingException { - - ObjectCodec oc = jp.getCodec(); - JsonNode node = oc.readTree(jp); - - if (node.isObject()) { - List tickers = new LinkedList<>(); - ObjectMapper mapper = new ObjectMapper(); - SimpleModule module = new SimpleModule(); - module.addDeserializer( - CoinMarketCapTicker.class, new CoinMarketCapTicker.CoinMarketCapTickerDeserializer()); - mapper.registerModule(module); - for (JsonNode child : node.get("data")) { - tickers.add(mapper.treeToValue(child, CoinMarketCapTicker.class)); - } - - return new CoinMarketCapArrayData<>(tickers); - } - return null; - } - } -} diff --git a/xchange-coinmarketcap/src/main/java/org/knowm/xchange/coinmarketcap/deprecated/v2/dto/marketdata/CoinMarketCapCurrency.java b/xchange-coinmarketcap/src/main/java/org/knowm/xchange/coinmarketcap/deprecated/v2/dto/marketdata/CoinMarketCapCurrency.java deleted file mode 100644 index 49d74e66434..00000000000 --- a/xchange-coinmarketcap/src/main/java/org/knowm/xchange/coinmarketcap/deprecated/v2/dto/marketdata/CoinMarketCapCurrency.java +++ /dev/null @@ -1,15 +0,0 @@ -package org.knowm.xchange.coinmarketcap.deprecated.v2.dto.marketdata; - -import org.knowm.xchange.currency.Currency; - -public class CoinMarketCapCurrency { - Currency currency; - - public CoinMarketCapCurrency(String code) { - currency = Currency.getInstance(code); - } - - public Currency getCurrency() { - return currency; - } -} diff --git a/xchange-coinmarketcap/src/main/java/org/knowm/xchange/coinmarketcap/deprecated/v2/dto/marketdata/CoinMarketCapHistoricalSpotPrice.java b/xchange-coinmarketcap/src/main/java/org/knowm/xchange/coinmarketcap/deprecated/v2/dto/marketdata/CoinMarketCapHistoricalSpotPrice.java deleted file mode 100644 index ef2bad2a1d3..00000000000 --- a/xchange-coinmarketcap/src/main/java/org/knowm/xchange/coinmarketcap/deprecated/v2/dto/marketdata/CoinMarketCapHistoricalSpotPrice.java +++ /dev/null @@ -1,38 +0,0 @@ -package org.knowm.xchange.coinmarketcap.deprecated.v2.dto.marketdata; - -import java.math.BigDecimal; -import java.util.Date; - -/** - * @author allenday - */ -public class CoinMarketCapHistoricalSpotPrice - implements Comparable { - - private final Date timestamp; - private final BigDecimal spotRate; - - CoinMarketCapHistoricalSpotPrice(Date timestamp, final BigDecimal spotRate) { - this.timestamp = timestamp; - this.spotRate = spotRate; - } - - public Date getTimestamp() { - return timestamp; - } - - public BigDecimal getSpotRate() { - return spotRate; - } - - @Override - public String toString() { - return "CoinbaseHistoricalPrice [timestamp=" + timestamp + ", spotRate=" + spotRate + "]"; - } - - @Override - public int compareTo(CoinMarketCapHistoricalSpotPrice o) { - - return this.timestamp.compareTo(o.timestamp); - } -} diff --git a/xchange-coinmarketcap/src/main/java/org/knowm/xchange/coinmarketcap/deprecated/v2/dto/marketdata/CoinMarketCapQuote.java b/xchange-coinmarketcap/src/main/java/org/knowm/xchange/coinmarketcap/deprecated/v2/dto/marketdata/CoinMarketCapQuote.java deleted file mode 100644 index 4b6e6d44a78..00000000000 --- a/xchange-coinmarketcap/src/main/java/org/knowm/xchange/coinmarketcap/deprecated/v2/dto/marketdata/CoinMarketCapQuote.java +++ /dev/null @@ -1,97 +0,0 @@ -package org.knowm.xchange.coinmarketcap.deprecated.v2.dto.marketdata; - -import com.fasterxml.jackson.core.JsonParser; -import com.fasterxml.jackson.core.JsonProcessingException; -import com.fasterxml.jackson.core.ObjectCodec; -import com.fasterxml.jackson.databind.DeserializationContext; -import com.fasterxml.jackson.databind.JsonDeserializer; -import com.fasterxml.jackson.databind.JsonNode; -import java.io.IOException; -import java.math.BigDecimal; - -public class CoinMarketCapQuote { - private final BigDecimal price; - private final BigDecimal volume24h; - private final BigDecimal marketCap; - private final BigDecimal pctChange1h; - private final BigDecimal pctChange24h; - private final BigDecimal pctChange7d; - - private CoinMarketCapQuote( - final BigDecimal price, - final BigDecimal volume24h, - final BigDecimal marketCap, - final BigDecimal pctChange1h, - final BigDecimal pctChange24h, - final BigDecimal pctChange7d) { - - this.price = price; - this.volume24h = volume24h; - this.marketCap = marketCap; - this.pctChange1h = pctChange1h; - this.pctChange24h = pctChange24h; - this.pctChange7d = pctChange7d; - } - - public BigDecimal getPrice() { - return price; - } - - public BigDecimal getVolume24h() { - return volume24h; - } - - public BigDecimal getMarketCap() { - return marketCap; - } - - public BigDecimal getPctChange1h() { - return pctChange1h; - } - - public BigDecimal getPctChange24h() { - return pctChange24h; - } - - public BigDecimal getPctChange7d() { - return pctChange7d; - } - - @Override - public String toString() { - - return "CoinMarketCapQuote [price=" - + price - + ", volume24h=" - + volume24h - + ", marketCap=" - + marketCap - + "]"; - } - - static class CoinMarketCapQuoteDeserializer extends JsonDeserializer { - - @Override - public CoinMarketCapQuote deserialize(JsonParser jp, DeserializationContext ctxt) - throws IOException, JsonProcessingException { - - ObjectCodec oc = jp.getCodec(); - JsonNode node = oc.readTree(jp); - - if (node.isObject()) { - BigDecimal price = new BigDecimal(node.get("price").asDouble()); - BigDecimal volume24h = new BigDecimal(node.get("volume_24h").asDouble()); - BigDecimal marketCap = new BigDecimal(node.get("market_cap").asDouble()); - - // TODO use these to create CoinMarketCapHistoricalSpotPrice instances - BigDecimal pctChange1h = new BigDecimal(node.get("percent_change_1h").asDouble()); - BigDecimal pctChange24h = new BigDecimal(node.get("percent_change_24h").asDouble()); - BigDecimal pctChange7d = new BigDecimal(node.get("percent_change_7d").asDouble()); - - return new CoinMarketCapQuote( - price, volume24h, marketCap, pctChange1h, pctChange24h, pctChange7d); - } - return null; - } - } -} diff --git a/xchange-coinmarketcap/src/main/java/org/knowm/xchange/coinmarketcap/deprecated/v2/dto/marketdata/CoinMarketCapTicker.java b/xchange-coinmarketcap/src/main/java/org/knowm/xchange/coinmarketcap/deprecated/v2/dto/marketdata/CoinMarketCapTicker.java deleted file mode 100644 index de39f044bbc..00000000000 --- a/xchange-coinmarketcap/src/main/java/org/knowm/xchange/coinmarketcap/deprecated/v2/dto/marketdata/CoinMarketCapTicker.java +++ /dev/null @@ -1,160 +0,0 @@ -package org.knowm.xchange.coinmarketcap.deprecated.v2.dto.marketdata; - -import com.fasterxml.jackson.core.JsonParser; -import com.fasterxml.jackson.core.JsonProcessingException; -import com.fasterxml.jackson.core.ObjectCodec; -import com.fasterxml.jackson.databind.DeserializationContext; -import com.fasterxml.jackson.databind.JsonDeserializer; -import com.fasterxml.jackson.databind.JsonNode; -import com.fasterxml.jackson.databind.ObjectMapper; -import com.fasterxml.jackson.databind.annotation.JsonDeserialize; -import com.fasterxml.jackson.databind.module.SimpleModule; -import java.io.IOException; -import java.math.BigDecimal; -import java.util.Date; -import java.util.HashMap; -import java.util.Iterator; -import java.util.Map; - -/** - * @author allenday - */ -@JsonDeserialize(using = CoinMarketCapTicker.CoinMarketCapTickerDeserializer.class) -public final class CoinMarketCapTicker { - - private final String id; - private final String name; - private final String symbol; - private final String websiteSlug; - private final BigDecimal rank; - private final BigDecimal circulatingSupply; - private final BigDecimal totalSupply; - private final BigDecimal maxSupply; - private final Map quotes; - private final Date lastUpdated; - private final CoinMarketCapCurrency baseCurrency; - - private CoinMarketCapTicker( - final String id, - final String name, - final String isoCode, - final String websiteSlug, - final BigDecimal rank, - final BigDecimal circulatingSupply, - final BigDecimal totalSupply, - final BigDecimal maxSupply, - final Map quotes, - final Date lastUpdated) { - this.id = id; - this.name = name; - this.baseCurrency = new CoinMarketCapCurrency(isoCode); - this.symbol = isoCode; - this.websiteSlug = websiteSlug; - this.rank = rank; - this.circulatingSupply = circulatingSupply; - this.totalSupply = totalSupply; - this.maxSupply = maxSupply; - this.quotes = quotes; - this.lastUpdated = lastUpdated; - } - - public String getID() { - return id; - } - - public String getName() { - return name; - } - - public CoinMarketCapCurrency getBaseCurrency() { - return baseCurrency; - } - - public String getSymbol() { - return symbol; - } - - public String getWebsiteSlug() { - return websiteSlug; - } - - public BigDecimal getRank() { - return rank; - } - - public BigDecimal getCirculatingSupply() { - return circulatingSupply; - } - - public BigDecimal getTotalSupply() { - return totalSupply; - } - - public BigDecimal getMaxSupply() { - return maxSupply; - } - - public Map getQuotes() { - return quotes; - } - - public Date getLastUpdated() { - return lastUpdated; - } - - @Override - public String toString() { - - return "CoinMarketCapCurrency [name=" + name + ", symbol=" + symbol + "]"; - } - - static class CoinMarketCapTickerDeserializer extends JsonDeserializer { - - @Override - public CoinMarketCapTicker deserialize(JsonParser jp, DeserializationContext ctxt) - throws IOException, JsonProcessingException { - - ObjectCodec oc = jp.getCodec(); - JsonNode node = oc.readTree(jp); - - if (node.isObject()) { - String id = node.get("id").asText(); - String name = node.get("name").asText(); - String symbol = node.get("symbol").asText(); - String websiteSlug = node.get("website_slug").asText(); - Date lastUpdated = new Date(node.get("last_updated").asLong() * 1000); - BigDecimal rank = new BigDecimal(node.get("rank").asInt()); - BigDecimal circulatingSupply = new BigDecimal(node.get("circulating_supply").asDouble()); - BigDecimal totalSupply = new BigDecimal(node.get("total_supply").asDouble()); - BigDecimal maxSupply = new BigDecimal(node.get("max_supply").asDouble()); - - Map quotes = new HashMap<>(); - ObjectMapper mapper = new ObjectMapper(); - SimpleModule module = new SimpleModule(); - module.addDeserializer( - CoinMarketCapQuote.class, new CoinMarketCapQuote.CoinMarketCapQuoteDeserializer()); - mapper.registerModule(module); - Iterator> it = node.get("quotes").fields(); - while (it.hasNext()) { - Map.Entry pair = it.next(); - quotes.put(pair.getKey(), mapper.treeToValue(pair.getValue(), CoinMarketCapQuote.class)); - } - - CoinMarketCapTicker ticker = - new CoinMarketCapTicker( - id, - name, - symbol, - websiteSlug, - rank, - circulatingSupply, - totalSupply, - maxSupply, - quotes, - lastUpdated); - return ticker; - } - return null; - } - } -} diff --git a/xchange-coinmarketcap/src/main/java/org/knowm/xchange/coinmarketcap/deprecated/v2/service/CoinMarketCapMarketDataService.java b/xchange-coinmarketcap/src/main/java/org/knowm/xchange/coinmarketcap/deprecated/v2/service/CoinMarketCapMarketDataService.java deleted file mode 100644 index 08ddc2f5bb4..00000000000 --- a/xchange-coinmarketcap/src/main/java/org/knowm/xchange/coinmarketcap/deprecated/v2/service/CoinMarketCapMarketDataService.java +++ /dev/null @@ -1,120 +0,0 @@ -package org.knowm.xchange.coinmarketcap.deprecated.v2.service; - -import java.io.IOException; -import java.math.BigDecimal; -import java.util.ArrayList; -import java.util.Collection; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import org.knowm.xchange.Exchange; -import org.knowm.xchange.coinmarketcap.deprecated.v2.dto.marketdata.CoinMarketCapCurrency; -import org.knowm.xchange.coinmarketcap.deprecated.v2.dto.marketdata.CoinMarketCapTicker; -import org.knowm.xchange.currency.Currency; -import org.knowm.xchange.currency.CurrencyPair; -import org.knowm.xchange.dto.marketdata.OrderBook; -import org.knowm.xchange.dto.marketdata.Ticker; -import org.knowm.xchange.dto.marketdata.Trades; -import org.knowm.xchange.exceptions.NotAvailableFromExchangeException; -import org.knowm.xchange.service.marketdata.MarketDataService; - -/** - * @author allenday - */ -public class CoinMarketCapMarketDataService extends CoinMarketCapMarketDataServiceRaw - implements MarketDataService { - - private Map tickers; - - /** - * Constructor - * - * @param exchange - */ - public CoinMarketCapMarketDataService(Exchange exchange) { - super(exchange); - try { - tickers = getNewTickers(); - } catch (IOException e) { - e.printStackTrace(); - } - } - - @Override - public Ticker getTicker(CurrencyPair currencyPair, final Object... args) throws IOException { - Currency b = currencyPair.base; - Currency c = currencyPair.counter; - - if (!tickers.containsKey(b.getCurrencyCode()) && b.getCurrencyCode().compareTo("USD") != 0) - throw new IOException("unsupported ISO 4217 Currency: " + b.getCurrencyCode()); - if (!tickers.containsKey(c.getCurrencyCode()) && c.getCurrencyCode().compareTo("USD") != 0) - throw new IOException("unsupported ISO 4217 Currency: " + c.getCurrencyCode()); - if (b.getCurrencyCode().compareTo(c.getCurrencyCode()) == 0) - throw new IOException("base and counter currency must not be identical"); - - CoinMarketCapTicker cmcB = tickers.get(b.getCurrencyCode()); - BigDecimal price; - BigDecimal volume; - try { - price = cmcB.getQuotes().get(c.toString()).getPrice(); - volume = cmcB.getQuotes().get(c.toString()).getVolume24h(); - } catch (NullPointerException npe) { - throw new NotAvailableFromExchangeException(); - } - - return new Ticker.Builder() - .currencyPair(currencyPair) - .timestamp(cmcB.getLastUpdated()) - .last(price) - .bid(price) - .ask(price) - .high(price) - .low(price) - .vwap(price) - .volume(volume) - .build(); - } - - public Ticker getTickerFresh(CurrencyPair currencyPair) throws IOException { - tickers = getNewTickers(); - return getTicker(currencyPair); - } - - private Map getNewTickers() throws IOException { - Map freshTickers = new HashMap<>(); - List tt = getCoinMarketCapTickers(); - for (CoinMarketCapTicker t : tt) { - freshTickers.put(t.getSymbol(), t); - } - return freshTickers; - } - - @Override - public OrderBook getOrderBook(CurrencyPair currencyPair, Object... objects) { - throw new NotAvailableFromExchangeException(); - } - - @Override - public Trades getTrades(CurrencyPair currencyPair, Object... objects) { - throw new NotAvailableFromExchangeException(); - } - - public List getCurrencies() { - List currencies = new ArrayList<>(); - List cmcCurrencies = getCoinMarketCapCurrencies(); - - for (CoinMarketCapCurrency cmcCurrency : cmcCurrencies) { - currencies.add(cmcCurrency.getCurrency()); - } - - return currencies; - } - - @Override - public List getCoinMarketCapCurrencies() { - Collection tickers = this.tickers.values(); - List currencies = new ArrayList<>(); - for (CoinMarketCapTicker ticker : tickers) currencies.add(ticker.getBaseCurrency()); - return currencies; - } -} diff --git a/xchange-coinmarketcap/src/main/java/org/knowm/xchange/coinmarketcap/deprecated/v2/service/CoinMarketCapMarketDataServiceRaw.java b/xchange-coinmarketcap/src/main/java/org/knowm/xchange/coinmarketcap/deprecated/v2/service/CoinMarketCapMarketDataServiceRaw.java deleted file mode 100644 index f9875ce8e52..00000000000 --- a/xchange-coinmarketcap/src/main/java/org/knowm/xchange/coinmarketcap/deprecated/v2/service/CoinMarketCapMarketDataServiceRaw.java +++ /dev/null @@ -1,87 +0,0 @@ -package org.knowm.xchange.coinmarketcap.deprecated.v2.service; - -import java.io.IOException; -import java.util.ArrayList; -import java.util.List; -import org.knowm.xchange.Exchange; -import org.knowm.xchange.client.ExchangeRestProxyBuilder; -import org.knowm.xchange.coinmarketcap.deprecated.v2.CoinMarketCap; -import org.knowm.xchange.coinmarketcap.deprecated.v2.dto.marketdata.CoinMarketCapCurrency; -import org.knowm.xchange.coinmarketcap.deprecated.v2.dto.marketdata.CoinMarketCapTicker; -import org.knowm.xchange.currency.Currency; -import org.knowm.xchange.currency.CurrencyPair; -import org.knowm.xchange.service.BaseExchangeService; -import org.knowm.xchange.service.BaseService; - -/** - * @author allenday - */ -class CoinMarketCapMarketDataServiceRaw extends BaseExchangeService implements BaseService { - - private final CoinMarketCap coinmarketcap; - - public CoinMarketCapMarketDataServiceRaw(Exchange exchange) { - - super(exchange); - this.coinmarketcap = - ExchangeRestProxyBuilder.forInterface( - CoinMarketCap.class, exchange.getExchangeSpecification()) - .build(); - } - - public CoinMarketCapTicker getCoinMarketCapTicker(CurrencyPair pair) { - - return coinmarketcap.getTicker(new CoinMarketCap.Pair(pair)); - } - - /** - * Unauthenticated resource that returns currencies supported on CoinMarketCap. - * - * @return A list of currency names and their corresponding ISO code. - * @throws IOException - */ - public List getCoinMarketCapCurrencies() throws IOException { - - List tickers = getCoinMarketCapTickers(); - List currencies = new ArrayList<>(); - for (CoinMarketCapTicker ticker : tickers) currencies.add(ticker.getBaseCurrency()); - return currencies; - } - - /** Retrieves all tickers from CoinMarketCap */ - public List getCoinMarketCapTickers() throws IOException { - return getCoinMarketCapTickers(0); - } - - /** - * Retrieves limited amount of tickers from CoinMarketCap - * - * @param limit count of tickers to be retrieved - */ - public List getCoinMarketCapTickers(final int limit) throws IOException { - return coinmarketcap.getTickers(limit, "array").getData(); - } - - /** - * Retrieves limited amount of tickers from CoinMarketCap - * - * @param limit count of tickers to be retrieved - * @param convert currency to get price converted to - */ - public List getCoinMarketCapTickers(final int limit, Currency convert) - throws IOException { - return coinmarketcap.getTickers(limit, convert.toString(), "array").getData(); - } - - public List getCoinMarketCapTickers(int start, int limit) - throws IOException { - - return coinmarketcap.getTickers(start, limit, "array").getData(); - } - - public List getCoinMarketCapTickers(int start, int limit, Currency convert) - throws IOException { - - return coinmarketcap.getTickers(start, limit, convert.toString(), "array").getData(); - } -}