Search in sources :

Example 1 with CoinMarketCapTicker

use of org.knowm.xchange.coinmarketcap.deprecated.v2.dto.marketdata.CoinMarketCapTicker in project XChange by knowm.

the class CoinMarketCapMarketDataService method getNewTickers.

private Map<String, CoinMarketCapTicker> getNewTickers() throws IOException {
    Map<String, CoinMarketCapTicker> freshTickers = new HashMap<>();
    List<CoinMarketCapTicker> tt = getCoinMarketCapTickers();
    for (CoinMarketCapTicker t : tt) {
        freshTickers.put(t.getSymbol(), t);
    }
    return freshTickers;
}
Also used : HashMap(java.util.HashMap) CoinMarketCapTicker(org.knowm.xchange.coinmarketcap.deprecated.v2.dto.marketdata.CoinMarketCapTicker)

Example 2 with CoinMarketCapTicker

use of org.knowm.xchange.coinmarketcap.deprecated.v2.dto.marketdata.CoinMarketCapTicker in project XChange by knowm.

the class CoinMarketCapMarketDataService method getTicker.

@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();
}
Also used : NotAvailableFromExchangeException(org.knowm.xchange.exceptions.NotAvailableFromExchangeException) CoinMarketCapCurrency(org.knowm.xchange.coinmarketcap.deprecated.v2.dto.marketdata.CoinMarketCapCurrency) Currency(org.knowm.xchange.currency.Currency) CoinMarketCapTicker(org.knowm.xchange.coinmarketcap.deprecated.v2.dto.marketdata.CoinMarketCapTicker) IOException(java.io.IOException) BigDecimal(java.math.BigDecimal)

Example 3 with CoinMarketCapTicker

use of org.knowm.xchange.coinmarketcap.deprecated.v2.dto.marketdata.CoinMarketCapTicker in project XChange by knowm.

the class CoinMarketCapMarketDataService method getCoinMarketCapCurrencies.

@Override
public List<CoinMarketCapCurrency> getCoinMarketCapCurrencies() {
    Collection<CoinMarketCapTicker> tickers = this.tickers.values();
    List<CoinMarketCapCurrency> currencies = new ArrayList<>();
    for (CoinMarketCapTicker ticker : tickers) currencies.add(ticker.getBaseCurrency());
    return currencies;
}
Also used : CoinMarketCapCurrency(org.knowm.xchange.coinmarketcap.deprecated.v2.dto.marketdata.CoinMarketCapCurrency) CoinMarketCapTicker(org.knowm.xchange.coinmarketcap.deprecated.v2.dto.marketdata.CoinMarketCapTicker) ArrayList(java.util.ArrayList)

Example 4 with CoinMarketCapTicker

use of org.knowm.xchange.coinmarketcap.deprecated.v2.dto.marketdata.CoinMarketCapTicker in project XChange by knowm.

the class CoinMarketCapMarketDataServiceRaw method getCoinMarketCapCurrencies.

/**
 * Unauthenticated resource that returns currencies supported on CoinMarketCap.
 *
 * @return A list of currency names and their corresponding ISO code.
 * @throws IOException
 */
public List<CoinMarketCapCurrency> getCoinMarketCapCurrencies() throws IOException {
    List<CoinMarketCapTicker> tickers = getCoinMarketCapTickers();
    List<CoinMarketCapCurrency> currencies = new ArrayList<>();
    for (CoinMarketCapTicker ticker : tickers) currencies.add(ticker.getBaseCurrency());
    return currencies;
}
Also used : CoinMarketCapCurrency(org.knowm.xchange.coinmarketcap.deprecated.v2.dto.marketdata.CoinMarketCapCurrency) CoinMarketCapTicker(org.knowm.xchange.coinmarketcap.deprecated.v2.dto.marketdata.CoinMarketCapTicker) ArrayList(java.util.ArrayList)

Aggregations

CoinMarketCapTicker (org.knowm.xchange.coinmarketcap.deprecated.v2.dto.marketdata.CoinMarketCapTicker)4 CoinMarketCapCurrency (org.knowm.xchange.coinmarketcap.deprecated.v2.dto.marketdata.CoinMarketCapCurrency)3 ArrayList (java.util.ArrayList)2 IOException (java.io.IOException)1 BigDecimal (java.math.BigDecimal)1 HashMap (java.util.HashMap)1 Currency (org.knowm.xchange.currency.Currency)1 NotAvailableFromExchangeException (org.knowm.xchange.exceptions.NotAvailableFromExchangeException)1