
org.knowm.xchange.kraken.service.KrakenMarketDataService Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of xchange-kraken Show documentation
Show all versions of xchange-kraken Show documentation
Development fork. Not for general use.
The newest version!
package org.knowm.xchange.kraken.service;
import java.io.IOException;
import java.util.Collection;
import java.util.List;
import org.knowm.xchange.Exchange;
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.ExchangeException;
import org.knowm.xchange.kraken.KrakenAdapters;
import org.knowm.xchange.kraken.dto.marketdata.KrakenDepth;
import org.knowm.xchange.kraken.dto.marketdata.KrakenPublicTrades;
import org.knowm.xchange.service.marketdata.MarketDataService;
import org.knowm.xchange.service.marketdata.params.CurrencyPairsParam;
import org.knowm.xchange.service.marketdata.params.Params;
public class KrakenMarketDataService extends KrakenMarketDataServiceRaw
implements MarketDataService {
/**
* Constructor
*
* @param exchange
*/
public KrakenMarketDataService(Exchange exchange) {
super(exchange);
}
@Override
public Ticker getTicker(CurrencyPair currencyPair, Object... args) throws IOException {
return KrakenAdapters.adaptTicker(getKrakenTicker(currencyPair), currencyPair);
}
@Override
public List getTickers(Params params) throws IOException {
if (!(params instanceof CurrencyPairsParam)) {
throw new IllegalArgumentException("Params must be instance of CurrencyPairsParam");
}
Collection pairs = ((CurrencyPairsParam) params).getCurrencyPairs();
CurrencyPair[] pair = pairs.toArray(new CurrencyPair[pairs.size()]);
return KrakenAdapters.adaptTickers(getKrakenTickers(pair));
}
@Override
public OrderBook getOrderBook(CurrencyPair currencyPair, Object... args) throws IOException {
long count = Long.MAX_VALUE;
if (args != null && args.length > 0) {
Object arg0 = args[0];
if (arg0 instanceof Long) {
count = (Long) arg0;
} else if (arg0 instanceof Integer) {
count = (Integer) arg0;
} else {
throw new ExchangeException("args[0] must be of type Long or Integer");
}
}
KrakenDepth krakenDepth = getKrakenDepth(currencyPair, count);
return KrakenAdapters.adaptOrderBook(krakenDepth, currencyPair);
}
@Override
public Trades getTrades(CurrencyPair currencyPair, Object... args) throws IOException {
Long since = null;
if (args != null && args.length > 0) {
Object arg0 = args[0];
if (arg0 instanceof Long) {
since = (Long) arg0;
} else {
throw new ExchangeException("args[0] must be of type Long!");
}
}
KrakenPublicTrades krakenTrades = getKrakenTrades(currencyPair, since);
return KrakenAdapters.adaptTrades(
krakenTrades.getTrades(), currencyPair, krakenTrades.getLast());
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy