PollingMarketDataService marketDataService = bitstampExchange.getPollingMarketDataService();
System.out.println("fetching data...");
// Get the current orderbook
OrderBook orderBook = marketDataService.getOrderBook(CurrencyPair.BTC_USD);
System.out.println("received data.");
System.out.println("plotting...");
// Create Chart
Chart chart = new Chart(800, 500);
// Customize Chart
chart.setChartTitle("Bitstamp Order Book");
chart.setYAxisTitle("BTC");
chart.setXAxisTitle("USD");
chart.getStyleManager().setChartType(ChartType.Area);
// BIDS
List<Number> xData = new ArrayList<Number>();
List<Number> yData = new ArrayList<Number>();
BigDecimal accumulatedBidUnits = new BigDecimal("0");
for (LimitOrder limitOrder : orderBook.getBids()) {
if (limitOrder.getLimitPrice().doubleValue() > 10) {
xData.add(limitOrder.getLimitPrice());
accumulatedBidUnits = accumulatedBidUnits.add(limitOrder.getTradableAmount());
yData.add(accumulatedBidUnits);
}
}
Collections.reverse(xData);
Collections.reverse(yData);
// Bids Series
Series series = chart.addSeries("bids", xData, yData);
series.setMarker(SeriesMarker.NONE);
// ASKS
xData = new ArrayList<Number>();
yData = new ArrayList<Number>();
BigDecimal accumulatedAskUnits = new BigDecimal("0");
for (LimitOrder limitOrder : orderBook.getAsks()) {
if (limitOrder.getLimitPrice().doubleValue() < 1000) {
xData.add(limitOrder.getLimitPrice());
accumulatedAskUnits = accumulatedAskUnits.add(limitOrder.getTradableAmount());
yData.add(accumulatedAskUnits);
}