com.xeiam.xchange.examples.btcchina.marketdata.BTCChinaTradesDemo 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.btcchina.marketdata;
import java.io.IOException;
import com.xeiam.xchange.Exchange;
import com.xeiam.xchange.ExchangeFactory;
import com.xeiam.xchange.btcchina.BTCChinaExchange;
import com.xeiam.xchange.btcchina.dto.marketdata.BTCChinaTrade;
import com.xeiam.xchange.btcchina.service.polling.BTCChinaMarketDataServiceRaw;
import com.xeiam.xchange.currency.CurrencyPair;
import com.xeiam.xchange.dto.marketdata.Trades;
import com.xeiam.xchange.service.polling.marketdata.PollingMarketDataService;
/**
* @author ObsessiveOrange Demonstrate requesting Trades at BTC China
*/
public class BTCChinaTradesDemo {
// Use the factory to get the VirtEx exchange API using default settings
static Exchange btcchina = ExchangeFactory.INSTANCE.createExchange(BTCChinaExchange.class.getName());
// Interested in the public polling market data feed (no authentication)
static PollingMarketDataService marketDataService = btcchina.getPollingMarketDataService();
public static void main(String[] args) throws IOException {
generic();
raw();
}
public static void generic() throws IOException {
// Get the latest trade data for BTC/CNY
Trades trades = marketDataService.getTrades(CurrencyPair.BTC_CNY);
System.out.println(trades);
System.out.println("NumTrades=" + trades.getTrades().size());
// Get the latest trade data for BTC/CNY, limit 10
trades = marketDataService.getTrades(CurrencyPair.BTC_CNY, null, 10);
System.out.println(trades);
System.out.println("NumTrades=" + trades.getTrades().size());
// Get the offset trade data for BTC/CNY
trades = marketDataService.getTrades(CurrencyPair.BTC_CNY, 6097616);
System.out.println(trades);
System.out.println("NumTrades=" + trades.getTrades().size());
System.out.println("LastId=" + trades.getlastID());
// Get the offset trade data for BTC/CNY, limit 10
trades = marketDataService.getTrades(CurrencyPair.BTC_CNY, 6097616, 10);
System.out.println(trades);
System.out.println("NumTrades=" + trades.getTrades().size());
System.out.println("LastId=" + trades.getlastID());
}
public static void raw() throws IOException {
// Get the latest trade data for BTC/CNY
BTCChinaTrade[] trades = ((BTCChinaMarketDataServiceRaw) marketDataService).getBTCChinaHistoryData(BTCChinaExchange.DEFAULT_MARKET);
for (BTCChinaTrade trade : trades) {
System.out.println(trade.toString());
}
System.out.println("NumTrades=" + trades.length);
// Get the offset trade data for BTC/CNY
trades = ((BTCChinaMarketDataServiceRaw) marketDataService).getBTCChinaHistoryData(BTCChinaExchange.DEFAULT_MARKET, 122235L);
for (BTCChinaTrade trade : trades) {
System.out.println(trade.toString());
}
System.out.println("NumTrades=" + trades.length);
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy