com.xeiam.xchange.examples.kraken.marketdata.KrakenDepthDemo Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of xchange-examples Show documentation
Show all versions of xchange-examples Show documentation
Provides a set of examples that demonstrate how to use XChange in client applications
The newest version!
package com.xeiam.xchange.examples.kraken.marketdata;
import java.io.IOException;
import com.xeiam.xchange.Exchange;
import com.xeiam.xchange.ExchangeFactory;
import com.xeiam.xchange.currency.CurrencyPair;
import com.xeiam.xchange.dto.marketdata.OrderBook;
import com.xeiam.xchange.kraken.KrakenExchange;
import com.xeiam.xchange.kraken.dto.marketdata.KrakenDepth;
import com.xeiam.xchange.kraken.service.polling.KrakenMarketDataServiceRaw;
import com.xeiam.xchange.service.polling.marketdata.PollingMarketDataService;
public class KrakenDepthDemo {
public static void main(String[] args) throws IOException {
// Use the factory to get Kraken exchange API using default settings
Exchange krakenExchange = ExchangeFactory.INSTANCE.createExchange(KrakenExchange.class.getName());
generic(krakenExchange);
raw(krakenExchange);
}
private static void generic(Exchange krakenExchange) throws IOException {
// Interested in the public polling market data feed (no authentication)
PollingMarketDataService krakenMarketDataService = krakenExchange.getPollingMarketDataService();
// Get the latest full order book data for NMC/XRP
OrderBook orderBook = krakenMarketDataService.getOrderBook(CurrencyPair.BTC_EUR);
System.out.println(orderBook.toString());
System.out.println("full orderbook size: " + (orderBook.getAsks().size() + orderBook.getBids().size()));
// Get the latest partial size order book data for NMC/XRP
orderBook = krakenMarketDataService.getOrderBook(CurrencyPair.BTC_EUR, 3L);
System.out.println(orderBook.toString());
System.out.println("partial orderbook size: " + (orderBook.getAsks().size() + orderBook.getBids().size()));
}
private static void raw(Exchange krakenExchange) throws IOException {
// Interested in the public polling market data feed (no authentication)
KrakenMarketDataServiceRaw krakenMarketDataService = (KrakenMarketDataServiceRaw) krakenExchange.getPollingMarketDataService();
// Get the latest full order book data
KrakenDepth depth = krakenMarketDataService.getKrakenDepth(CurrencyPair.BTC_EUR, Long.MAX_VALUE);
System.out.println(depth.toString());
System.out.println("size: " + (depth.getAsks().size() + depth.getBids().size()));
// Get the latest partial size order book data
depth = krakenMarketDataService.getKrakenDepth(CurrencyPair.BTC_EUR, 3L);
System.out.println(depth.toString());
System.out.println("size: " + (depth.getAsks().size() + depth.getBids().size()));
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy