com.xeiam.xchange.examples.bitstamp.marketdata.DepthDemo 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.bitstamp.marketdata;
import java.io.IOException;
import com.xeiam.xchange.Exchange;
import com.xeiam.xchange.ExchangeFactory;
import com.xeiam.xchange.bitstamp.BitstampExchange;
import com.xeiam.xchange.bitstamp.dto.marketdata.BitstampOrderBook;
import com.xeiam.xchange.bitstamp.service.polling.BitstampMarketDataServiceRaw;
import com.xeiam.xchange.currency.CurrencyPair;
import com.xeiam.xchange.dto.marketdata.OrderBook;
import com.xeiam.xchange.service.polling.marketdata.PollingMarketDataService;
/**
* Demonstrate requesting Depth at Bitstamp
*/
public class DepthDemo {
public static void main(String[] args) throws IOException {
// Use the factory to get Bitstamp exchange API using default settings
Exchange bitstamp = ExchangeFactory.INSTANCE.createExchange(BitstampExchange.class.getName());
// Interested in the public polling market data feed (no authentication)
PollingMarketDataService marketDataService = bitstamp.getPollingMarketDataService();
generic(marketDataService);
raw((BitstampMarketDataServiceRaw) marketDataService);
}
private static void generic(PollingMarketDataService marketDataService) throws IOException {
// Get the latest order book data for BTC/CAD
OrderBook orderBook = marketDataService.getOrderBook(CurrencyPair.BTC_USD);
System.out.println("Current Order Book size for BTC / USD: " + (orderBook.getAsks().size() + orderBook.getBids().size()));
System.out.println("First Ask: " + orderBook.getAsks().get(0).toString());
System.out.println("Last Ask: " + orderBook.getAsks().get(orderBook.getAsks().size() - 1).toString());
System.out.println("First Bid: " + orderBook.getBids().get(0).toString());
System.out.println("Last Bid: " + orderBook.getBids().get(orderBook.getBids().size() - 1).toString());
System.out.println(orderBook.toString());
}
private static void raw(BitstampMarketDataServiceRaw marketDataService) throws IOException {
// Get the latest order book data for BTC/CAD
BitstampOrderBook orderBook = marketDataService.getBitstampOrderBook();
System.out.println("Current Order Book size for BTC / USD: " + (orderBook.getAsks().size() + orderBook.getBids().size()));
System.out.println("First Ask: " + orderBook.getAsks().get(0).toString());
System.out.println("First Bid: " + orderBook.getBids().get(0).toString());
System.out.println(orderBook.toString());
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy