Search in sources :

Example 1 with CmcTicker

use of org.knowm.xchange.coinmarketcap.pro.v1.dto.marketdata.CmcTicker in project XChange by knowm.

the class CmcAdapter method adaptTickerList.

public static List<Ticker> adaptTickerList(List<CmcTicker> cmcTickerList) {
    List<Ticker> tickerList = new ArrayList<>();
    cmcTickerList.forEach(cmcTicker -> {
        cmcTicker.getQuote().forEach((currencySymbol, quote) -> {
            CurrencyPair pair = new CurrencyPair(cmcTicker.getSymbol(), currencySymbol);
            tickerList.add(adaptTicker(cmcTicker, pair));
        });
    });
    return tickerList;
}
Also used : CmcTicker(org.knowm.xchange.coinmarketcap.pro.v1.dto.marketdata.CmcTicker) Ticker(org.knowm.xchange.dto.marketdata.Ticker) ArrayList(java.util.ArrayList) CurrencyPair(org.knowm.xchange.currency.CurrencyPair)

Example 2 with CmcTicker

use of org.knowm.xchange.coinmarketcap.pro.v1.dto.marketdata.CmcTicker in project XChange by knowm.

the class CmcMarketDataService method getTickers.

@Override
public List<Ticker> getTickers(Params params) throws IOException {
    if (!(params instanceof CurrencyPairsParam)) {
        throw new IllegalArgumentException("Params must be instance of CurrencyPairsParam");
    }
    Collection<CurrencyPair> pairs = ((CurrencyPairsParam) params).getCurrencyPairs();
    Set<Currency> baseSymbols = new HashSet<>();
    Set<Currency> convertSymbols = new HashSet<>();
    for (CurrencyPair pair : pairs) {
        baseSymbols.add(pair.base);
        convertSymbols.add(pair.counter);
    }
    Map<String, CmcTicker> cmcTickerMap = super.getCmcLatestQuotes(baseSymbols, convertSymbols);
    return CmcAdapter.adaptTickerMap(cmcTickerMap);
}
Also used : Currency(org.knowm.xchange.currency.Currency) CurrencyPairsParam(org.knowm.xchange.service.marketdata.params.CurrencyPairsParam) CmcTicker(org.knowm.xchange.coinmarketcap.pro.v1.dto.marketdata.CmcTicker) CurrencyPair(org.knowm.xchange.currency.CurrencyPair) HashSet(java.util.HashSet)

Example 3 with CmcTicker

use of org.knowm.xchange.coinmarketcap.pro.v1.dto.marketdata.CmcTicker in project XChange by knowm.

the class CmcAdapter method adaptTickerMap.

public static List<Ticker> adaptTickerMap(Map<String, CmcTicker> cmcTickerMap) {
    List<Ticker> tickerList = new ArrayList<>();
    cmcTickerMap.forEach((baseSymbol, cmcTicker) -> {
        cmcTicker.getQuote().forEach((currencySymbol, quote) -> {
            CurrencyPair pair = new CurrencyPair(cmcTicker.getSymbol(), currencySymbol);
            tickerList.add(adaptTicker(cmcTicker, pair));
        });
    });
    return tickerList;
}
Also used : CmcTicker(org.knowm.xchange.coinmarketcap.pro.v1.dto.marketdata.CmcTicker) Ticker(org.knowm.xchange.dto.marketdata.Ticker) ArrayList(java.util.ArrayList) CurrencyPair(org.knowm.xchange.currency.CurrencyPair)

Example 4 with CmcTicker

use of org.knowm.xchange.coinmarketcap.pro.v1.dto.marketdata.CmcTicker in project XChange by knowm.

the class CmcAdapter method adaptTicker.

public static Ticker adaptTicker(CmcTicker ticker, CurrencyPair currencyPair) {
    Date timestamp = ticker.getLastUpdated();
    CmcQuote cmcQuote = ticker.getQuote().get(currencyPair.counter.getCurrencyCode());
    BigDecimal price = cmcQuote.getPrice();
    BigDecimal volume24h = cmcQuote.getVolume24h();
    return new Ticker.Builder().currencyPair(currencyPair).timestamp(timestamp).open(price).last(price).bid(price).ask(price).high(price).low(price).vwap(price).volume(volume24h).build();
}
Also used : CmcQuote(org.knowm.xchange.coinmarketcap.pro.v1.dto.marketdata.CmcQuote) CmcTicker(org.knowm.xchange.coinmarketcap.pro.v1.dto.marketdata.CmcTicker) Ticker(org.knowm.xchange.dto.marketdata.Ticker) Date(java.util.Date) BigDecimal(java.math.BigDecimal)

Example 5 with CmcTicker

use of org.knowm.xchange.coinmarketcap.pro.v1.dto.marketdata.CmcTicker in project XChange by knowm.

the class CmcMarketDataServiceRaw method getCmcLatestQuotes.

public Map<String, CmcTicker> getCmcLatestQuotes(Set<Currency> baseCurrencySet, Set<Currency> convertCurrencySet) throws IOException {
    List<String> baseSymbols = baseCurrencySet.stream().map(c -> c.getCurrencyCode()).collect(Collectors.toList());
    String commaSeparatedBaseSymbols = StringUtils.join(baseSymbols, ",");
    List<String> convertSymbols = convertCurrencySet.stream().map(c -> c.getCurrencyCode()).collect(Collectors.toList());
    String commaSeparatedConvertCurrencies = StringUtils.join(convertSymbols, ",");
    CmcTickerResponse response = null;
    try {
        response = cmcAuthenticated.getLatestQuotes(apiKey, commaSeparatedBaseSymbols, commaSeparatedConvertCurrencies);
    } catch (HttpStatusIOException ex) {
        CmcErrorAdapter.adapt(ex);
    }
    return response.getData();
}
Also used : CmcCurrencyInfoResponse(org.knowm.xchange.coinmarketcap.pro.v1.dto.marketdata.response.CmcCurrencyInfoResponse) CmcTickerResponse(org.knowm.xchange.coinmarketcap.pro.v1.dto.marketdata.response.CmcTickerResponse) Set(java.util.Set) IOException(java.io.IOException) CmcErrorAdapter(org.knowm.xchange.coinmarketcap.pro.v1.CmcErrorAdapter) CmcCurrencyMapResponse(org.knowm.xchange.coinmarketcap.pro.v1.dto.marketdata.response.CmcCurrencyMapResponse) Exchange(org.knowm.xchange.Exchange) Collectors(java.util.stream.Collectors) StringUtils(org.apache.commons.lang3.StringUtils) CmcCurrency(org.knowm.xchange.coinmarketcap.pro.v1.dto.marketdata.CmcCurrency) CmcCurrencyInfo(org.knowm.xchange.coinmarketcap.pro.v1.dto.marketdata.CmcCurrencyInfo) List(java.util.List) Currency(org.knowm.xchange.currency.Currency) CmcTicker(org.knowm.xchange.coinmarketcap.pro.v1.dto.marketdata.CmcTicker) CmcTickerListResponse(org.knowm.xchange.coinmarketcap.pro.v1.dto.marketdata.response.CmcTickerListResponse) Map(java.util.Map) CurrencyPair(org.knowm.xchange.currency.CurrencyPair) HttpStatusIOException(si.mazi.rescu.HttpStatusIOException) CmcTickerResponse(org.knowm.xchange.coinmarketcap.pro.v1.dto.marketdata.response.CmcTickerResponse) HttpStatusIOException(si.mazi.rescu.HttpStatusIOException)

Aggregations

CmcTicker (org.knowm.xchange.coinmarketcap.pro.v1.dto.marketdata.CmcTicker)5 CurrencyPair (org.knowm.xchange.currency.CurrencyPair)4 Ticker (org.knowm.xchange.dto.marketdata.Ticker)3 ArrayList (java.util.ArrayList)2 Currency (org.knowm.xchange.currency.Currency)2 IOException (java.io.IOException)1 BigDecimal (java.math.BigDecimal)1 Date (java.util.Date)1 HashSet (java.util.HashSet)1 List (java.util.List)1 Map (java.util.Map)1 Set (java.util.Set)1 Collectors (java.util.stream.Collectors)1 StringUtils (org.apache.commons.lang3.StringUtils)1 Exchange (org.knowm.xchange.Exchange)1 CmcErrorAdapter (org.knowm.xchange.coinmarketcap.pro.v1.CmcErrorAdapter)1 CmcCurrency (org.knowm.xchange.coinmarketcap.pro.v1.dto.marketdata.CmcCurrency)1 CmcCurrencyInfo (org.knowm.xchange.coinmarketcap.pro.v1.dto.marketdata.CmcCurrencyInfo)1 CmcQuote (org.knowm.xchange.coinmarketcap.pro.v1.dto.marketdata.CmcQuote)1 CmcCurrencyInfoResponse (org.knowm.xchange.coinmarketcap.pro.v1.dto.marketdata.response.CmcCurrencyInfoResponse)1