com.xeiam.xchange.examples.bitcoinium.BitcoiniumTickerHistoryDemo 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.bitcoinium;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import com.xeiam.xchange.Exchange;
import com.xeiam.xchange.ExchangeFactory;
import com.xeiam.xchange.ExchangeSpecification;
import com.xeiam.xchange.bitcoinium.BitcoiniumExchange;
import com.xeiam.xchange.bitcoinium.dto.marketdata.BitcoiniumTicker;
import com.xeiam.xchange.bitcoinium.dto.marketdata.BitcoiniumTickerHistory;
import com.xeiam.xchange.bitcoinium.service.polling.BitcoiniumMarketDataServiceRaw;
import com.xeiam.xchange.currency.Currencies;
import com.xeiam.xchart.Chart;
import com.xeiam.xchart.ChartBuilder;
import com.xeiam.xchart.Series;
import com.xeiam.xchart.SeriesMarker;
import com.xeiam.xchart.StyleManager.ChartType;
import com.xeiam.xchart.StyleManager.LegendPosition;
import com.xeiam.xchart.SwingWrapper;
/**
* Demonstrates plotting an OrderBook with XChart
*
* @author timmolter
*/
public class BitcoiniumTickerHistoryDemo {
public static void main(String[] args) throws Exception {
ExchangeSpecification exchangeSpecification = new ExchangeSpecification(BitcoiniumExchange.class.getName());
// exchangeSpecification.setPlainTextUri("http://openexchangerates.org");
exchangeSpecification.setApiKey("42djci5kmbtyzrvglfdw3e2dgmh5mr37");
System.out.println(exchangeSpecification.toString());
Exchange bitcoiniumExchange = ExchangeFactory.INSTANCE.createExchange(exchangeSpecification);
// Interested in the public polling market data feed (no authentication)
BitcoiniumMarketDataServiceRaw bitcoiniumMarketDataService = (BitcoiniumMarketDataServiceRaw) bitcoiniumExchange.getPollingMarketDataService();
System.out.println("fetching data...");
// Get the latest order book data for BTC/USD - BITSTAMP
BitcoiniumTickerHistory bitcoiniumTickerHistory = bitcoiniumMarketDataService.getBitcoiniumTickerHistory(Currencies.BTC, "BITSTAMP_USD",
"THIRTY_DAYS");
System.out.println(bitcoiniumTickerHistory.toString());
List xAxisData = new ArrayList();
List yAxisData = new ArrayList();
for (int i = 0; i < bitcoiniumTickerHistory.getCondensedTickers().length; i++) {
BitcoiniumTicker bitcoiniumTicker = bitcoiniumTickerHistory.getCondensedTickers()[i];
Date timestamp = new Date(bitcoiniumTicker.getTimestamp());
float price = bitcoiniumTicker.getLast().floatValue();
System.out.println(timestamp + ": " + price);
xAxisData.add(timestamp);
yAxisData.add(price);
}
Chart chart = new ChartBuilder().chartType(ChartType.Area).width(800).height(600).title("Bitstamp Price vs. Date").xAxisTitle("Date")
.yAxisTitle("Price").build();
chart.getStyleManager().setLegendPosition(LegendPosition.InsideNE);
Series series = chart.addSeries("Bitcoinium USD/BTC", xAxisData, yAxisData);
series.setMarker(SeriesMarker.NONE);
new SwingWrapper(chart).displayChart();
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy