Search in sources :

Example 1 with SwingWrapper

use of org.knowm.xchart.SwingWrapper in project XChange by knowm.

the class DepthChartDemo method main.

public static void main(String[] args) throws IOException {
    // Use the factory to get the version 1 Bitstamp exchange API using default settings
    Exchange bitstampExchange = ExchangeFactory.INSTANCE.createExchange(BitstampExchange.class);
    // Interested in the public market data feed (no authentication)
    MarketDataService marketDataService = bitstampExchange.getMarketDataService();
    System.out.println("fetching data...");
    // Get the current orderbook
    OrderBook orderBook = marketDataService.getOrderBook(CurrencyPair.BTC_USD);
    System.out.println("orderBook = " + orderBook);
    System.out.println("received data.");
    System.out.println("plotting...");
    // Create Chart
    XYChart chart = new XYChartBuilder().width(800).height(600).title("Bitstamp Order Book").xAxisTitle("BTC").yAxisTitle("USD").build();
    // Customize Chart
    chart.getStyler().setDefaultSeriesRenderStyle(XYSeriesRenderStyle.Area);
    // BIDS
    List<Number> xData = new ArrayList<>();
    List<Number> yData = new ArrayList<>();
    BigDecimal accumulatedBidUnits = new BigDecimal("0");
    for (LimitOrder limitOrder : orderBook.getBids()) {
        if (limitOrder.getLimitPrice().doubleValue() > 5000) {
            xData.add(limitOrder.getLimitPrice());
            accumulatedBidUnits = accumulatedBidUnits.add(limitOrder.getOriginalAmount());
            yData.add(accumulatedBidUnits);
        }
    }
    Collections.reverse(xData);
    Collections.reverse(yData);
    // Bids Series
    XYSeries series = chart.addSeries("bids", xData, yData);
    series.setMarker(SeriesMarkers.NONE);
    // ASKS
    xData = new ArrayList<>();
    yData = new ArrayList<>();
    BigDecimal accumulatedAskUnits = new BigDecimal("0");
    for (LimitOrder limitOrder : orderBook.getAsks()) {
        if (limitOrder.getLimitPrice().doubleValue() < 20000) {
            xData.add(limitOrder.getLimitPrice());
            accumulatedAskUnits = accumulatedAskUnits.add(limitOrder.getOriginalAmount());
            yData.add(accumulatedAskUnits);
        }
    }
    // Asks Series
    series = chart.addSeries("asks", xData, yData);
    series.setMarker(SeriesMarkers.NONE);
    new SwingWrapper(chart).displayChart();
}
Also used : XYSeries(org.knowm.xchart.XYSeries) OrderBook(org.knowm.xchange.dto.marketdata.OrderBook) ArrayList(java.util.ArrayList) SwingWrapper(org.knowm.xchart.SwingWrapper) BigDecimal(java.math.BigDecimal) Exchange(org.knowm.xchange.Exchange) BitstampExchange(org.knowm.xchange.bitstamp.BitstampExchange) MarketDataService(org.knowm.xchange.service.marketdata.MarketDataService) XYChart(org.knowm.xchart.XYChart) XYChartBuilder(org.knowm.xchart.XYChartBuilder) LimitOrder(org.knowm.xchange.dto.trade.LimitOrder)

Example 2 with SwingWrapper

use of org.knowm.xchart.SwingWrapper in project XChange by knowm.

the class DepthChartDemo method main.

public static void main(String[] args) throws IOException {
    // Use the factory to get the version 1 Bitstamp exchange API using default settings
    Exchange ccexExchange = ExchangeFactory.INSTANCE.createExchange(CCEXExchange.class);
    // Interested in the public market data feed (no authentication)
    MarketDataService marketDataService = ccexExchange.getMarketDataService();
    System.out.println("fetching data...");
    // Get the current orderbook
    OrderBook orderBook = marketDataService.getOrderBook(CurrencyPair.XAUR_BTC);
    System.out.println("received data.");
    for (LimitOrder limitOrder : orderBook.getBids()) {
        System.out.println(limitOrder.getType() + " " + limitOrder.getCurrencyPair() + " Limit price: " + limitOrder.getLimitPrice() + " Amount: " + limitOrder.getOriginalAmount());
    }
    for (LimitOrder limitOrder : orderBook.getAsks()) {
        System.out.println(limitOrder.getType() + " " + limitOrder.getCurrencyPair() + " Limit price: " + limitOrder.getLimitPrice() + " Amount: " + limitOrder.getOriginalAmount());
    }
    System.out.println("plotting...");
    // Create Chart
    XYChart chart = new XYChartBuilder().width(800).height(600).title("C-CEX Order Book - Xaurum").xAxisTitle("BTC").yAxisTitle("Amount").build();
    // Customize Chart
    chart.getStyler().setDefaultSeriesRenderStyle(XYSeriesRenderStyle.Area);
    // BIDS
    List<Number> xData = new ArrayList<>();
    List<Number> yData = new ArrayList<>();
    BigDecimal accumulatedBidUnits = new BigDecimal("0");
    for (LimitOrder limitOrder : orderBook.getBids()) {
        xData.add(limitOrder.getLimitPrice());
        accumulatedBidUnits = accumulatedBidUnits.add(limitOrder.getOriginalAmount());
        yData.add(accumulatedBidUnits);
    }
    Collections.reverse(xData);
    Collections.reverse(yData);
    // Bids Series
    XYSeries series = chart.addSeries("bids", xData, yData);
    series.setMarker(SeriesMarkers.NONE);
    // ASKS
    xData = new ArrayList<>();
    yData = new ArrayList<>();
    BigDecimal accumulatedAskUnits = new BigDecimal("0");
    for (LimitOrder limitOrder : orderBook.getAsks()) {
        xData.add(limitOrder.getLimitPrice());
        accumulatedAskUnits = accumulatedAskUnits.add(limitOrder.getOriginalAmount());
        yData.add(accumulatedAskUnits);
    }
    // Asks Series
    series = chart.addSeries("asks", xData, yData);
    series.setMarker(SeriesMarkers.NONE);
    new SwingWrapper(chart).displayChart();
}
Also used : XYSeries(org.knowm.xchart.XYSeries) OrderBook(org.knowm.xchange.dto.marketdata.OrderBook) ArrayList(java.util.ArrayList) SwingWrapper(org.knowm.xchart.SwingWrapper) BigDecimal(java.math.BigDecimal) CCEXExchange(org.knowm.xchange.ccex.CCEXExchange) Exchange(org.knowm.xchange.Exchange) MarketDataService(org.knowm.xchange.service.marketdata.MarketDataService) XYChart(org.knowm.xchart.XYChart) LimitOrder(org.knowm.xchange.dto.trade.LimitOrder) XYChartBuilder(org.knowm.xchart.XYChartBuilder)

Example 3 with SwingWrapper

use of org.knowm.xchart.SwingWrapper in project XChange by knowm.

the class BitcoiniumTickerHistoryDemo method main.

public static void main(String[] args) throws Exception {
    ExchangeSpecification exchangeSpecification = new ExchangeSpecification(BitcoiniumExchange.class);
    // exchangeSpecification.setPlainTextUri("http://openexchangerates.org");
    exchangeSpecification.setApiKey("42djci5kmbtyzrvglfdw3e2dgmh5mr37");
    System.out.println(exchangeSpecification.toString());
    Exchange bitcoiniumExchange = ExchangeFactory.INSTANCE.createExchange(exchangeSpecification);
    // Interested in the public market data feed (no authentication)
    BitcoiniumMarketDataServiceRaw bitcoiniumMarketDataService = (BitcoiniumMarketDataServiceRaw) bitcoiniumExchange.getMarketDataService();
    System.out.println("fetching data...");
    // Get the latest order book data for BTC/USD - BITSTAMP
    BitcoiniumTickerHistory bitcoiniumTickerHistory = bitcoiniumMarketDataService.getBitcoiniumTickerHistory("BTC", "BITSTAMP_USD", "THIRTY_DAYS");
    System.out.println(bitcoiniumTickerHistory.toString());
    List<Date> xAxisData = new ArrayList<>();
    List<Float> 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);
    }
    // Create Chart
    XYChart chart = new XYChartBuilder().width(800).height(600).title("Bitstamp Price vs. Date").xAxisTitle("Date").yAxisTitle("Price").build();
    // Customize Chart
    chart.getStyler().setLegendPosition(LegendPosition.InsideNE);
    chart.getStyler().setDefaultSeriesRenderStyle(XYSeriesRenderStyle.Area);
    XYSeries series = chart.addSeries("Bitcoinium USD/BTC", xAxisData, yAxisData);
    series.setMarker(SeriesMarkers.NONE);
    new SwingWrapper(chart).displayChart();
}
Also used : XYSeries(org.knowm.xchart.XYSeries) BitcoiniumTickerHistory(org.knowm.xchange.bitcoinium.dto.marketdata.BitcoiniumTickerHistory) ArrayList(java.util.ArrayList) SwingWrapper(org.knowm.xchart.SwingWrapper) Date(java.util.Date) BitcoiniumExchange(org.knowm.xchange.bitcoinium.BitcoiniumExchange) Exchange(org.knowm.xchange.Exchange) BitcoiniumMarketDataServiceRaw(org.knowm.xchange.bitcoinium.service.BitcoiniumMarketDataServiceRaw) XYChart(org.knowm.xchart.XYChart) ExchangeSpecification(org.knowm.xchange.ExchangeSpecification) BitcoiniumTicker(org.knowm.xchange.bitcoinium.dto.marketdata.BitcoiniumTicker) XYChartBuilder(org.knowm.xchart.XYChartBuilder)

Example 4 with SwingWrapper

use of org.knowm.xchart.SwingWrapper in project skeleton-sp18 by Berkeley-CS61B.

the class GeneratorDrawer method draw.

public void draw(int numSamples) {
    double[] xValues = new double[numSamples];
    double[] samples = new double[numSamples];
    for (int ii = 0; ii < numSamples; ii += 1) {
        xValues[ii] = ii;
        samples[ii] = generator.next();
    }
    // Create Chart
    XYChart chart = QuickChart.getChart("Generator Output", "X", "Y", "y(x)", xValues, samples);
    // Show it
    new SwingWrapper(chart).displayChart();
}
Also used : XYChart(org.knowm.xchart.XYChart) SwingWrapper(org.knowm.xchart.SwingWrapper)

Example 5 with SwingWrapper

use of org.knowm.xchart.SwingWrapper in project XChange by knowm.

the class BitcoiniumOrderBookChartDemo method main.

public static void main(String[] args) throws Exception {
    ExchangeSpecification exchangeSpecification = new ExchangeSpecification(BitcoiniumExchange.class);
    // exchangeSpecification.setPlainTextUri("http://openexchangerates.org");
    exchangeSpecification.setApiKey("42djci5kmbtyzrvglfdw3e2dgmh5mr37");
    System.out.println(exchangeSpecification.toString());
    Exchange bitcoiniumExchange = ExchangeFactory.INSTANCE.createExchange(exchangeSpecification);
    // Interested in the public market data feed (no authentication)
    BitcoiniumMarketDataServiceRaw bitcoiniumMarketDataService = (BitcoiniumMarketDataServiceRaw) bitcoiniumExchange.getMarketDataService();
    System.out.println("fetching data...");
    // Get the latest order book data for BTC/USD - BITSTAMP
    BitcoiniumOrderbook bitcoiniumOrderbook = bitcoiniumMarketDataService.getBitcoiniumOrderbook("BTC", "BITSTAMP_USD", "TEN_PERCENT");
    System.out.println("Order book: " + bitcoiniumOrderbook);
    System.out.println("received data.");
    System.out.println("plotting...");
    // Create Chart
    XYChart chart = new XYChartBuilder().width(800).height(600).title("Bitcoinium Order Book - BITSTAMP_BTC_USD").xAxisTitle("BTC").yAxisTitle("USD").build();
    // Customize Chart
    chart.getStyler().setDefaultSeriesRenderStyle(XYSeriesRenderStyle.Area);
    // BIDS
    // Collections.reverse(bitcoiniumOrderbook.getBidPriceList());
    // Collections.reverse(bitcoiniumOrderbook.getBidVolumeList());
    // Bids Series
    List<Float> bidsPriceData = getPriceData(bitcoiniumOrderbook.getBids());
    Collections.reverse(bidsPriceData);
    List<Float> bidsVolumeData = getVolumeData(bitcoiniumOrderbook.getBids());
    Collections.reverse(bidsVolumeData);
    XYSeries series = chart.addSeries("bids", bidsPriceData, bidsVolumeData);
    series.setMarker(SeriesMarkers.NONE);
    // ASKS
    // Asks Series
    series = chart.addSeries("asks", getPriceData(bitcoiniumOrderbook.getAsks()), getVolumeData(bitcoiniumOrderbook.getAsks()));
    series.setMarker(SeriesMarkers.NONE);
    new SwingWrapper(chart).displayChart();
}
Also used : BitcoiniumExchange(org.knowm.xchange.bitcoinium.BitcoiniumExchange) Exchange(org.knowm.xchange.Exchange) XYSeries(org.knowm.xchart.XYSeries) BitcoiniumOrderbook(org.knowm.xchange.bitcoinium.dto.marketdata.BitcoiniumOrderbook) BitcoiniumMarketDataServiceRaw(org.knowm.xchange.bitcoinium.service.BitcoiniumMarketDataServiceRaw) XYChart(org.knowm.xchart.XYChart) ExchangeSpecification(org.knowm.xchange.ExchangeSpecification) SwingWrapper(org.knowm.xchart.SwingWrapper) XYChartBuilder(org.knowm.xchart.XYChartBuilder)

Aggregations

SwingWrapper (org.knowm.xchart.SwingWrapper)8 XYChart (org.knowm.xchart.XYChart)8 Exchange (org.knowm.xchange.Exchange)7 XYChartBuilder (org.knowm.xchart.XYChartBuilder)7 XYSeries (org.knowm.xchart.XYSeries)7 ArrayList (java.util.ArrayList)6 BigDecimal (java.math.BigDecimal)5 OrderBook (org.knowm.xchange.dto.marketdata.OrderBook)5 LimitOrder (org.knowm.xchange.dto.trade.LimitOrder)5 MarketDataService (org.knowm.xchange.service.marketdata.MarketDataService)5 ExchangeSpecification (org.knowm.xchange.ExchangeSpecification)2 BitcoiniumExchange (org.knowm.xchange.bitcoinium.BitcoiniumExchange)2 BitcoiniumMarketDataServiceRaw (org.knowm.xchange.bitcoinium.service.BitcoiniumMarketDataServiceRaw)2 MercadoBitcoinExchange (org.knowm.xchange.mercadobitcoin.MercadoBitcoinExchange)2 Date (java.util.Date)1 BitcoiniumOrderbook (org.knowm.xchange.bitcoinium.dto.marketdata.BitcoiniumOrderbook)1 BitcoiniumTicker (org.knowm.xchange.bitcoinium.dto.marketdata.BitcoiniumTicker)1 BitcoiniumTickerHistory (org.knowm.xchange.bitcoinium.dto.marketdata.BitcoiniumTickerHistory)1 BitstampExchange (org.knowm.xchange.bitstamp.BitstampExchange)1 CCEXExchange (org.knowm.xchange.ccex.CCEXExchange)1