Search in sources :

Example 1 with CCEXExchange

use of org.knowm.xchange.ccex.CCEXExchange 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 2 with CCEXExchange

use of org.knowm.xchange.ccex.CCEXExchange in project XChange by knowm.

the class OrderBookDemo method main.

public static void main(String[] args) throws IOException {
    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());
    }
}
Also used : CCEXExchange(org.knowm.xchange.ccex.CCEXExchange) Exchange(org.knowm.xchange.Exchange) OrderBook(org.knowm.xchange.dto.marketdata.OrderBook) MarketDataService(org.knowm.xchange.service.marketdata.MarketDataService) LimitOrder(org.knowm.xchange.dto.trade.LimitOrder)

Example 3 with CCEXExchange

use of org.knowm.xchange.ccex.CCEXExchange in project XChange by knowm.

the class TickerDemo method main.

public static void main(String[] args) throws IOException {
    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
    Ticker ticker = marketDataService.getTicker(CurrencyPair.XAUR_BTC);
    System.out.println("received data.");
    System.out.println(ticker);
}
Also used : CCEXExchange(org.knowm.xchange.ccex.CCEXExchange) Exchange(org.knowm.xchange.Exchange) MarketDataService(org.knowm.xchange.service.marketdata.MarketDataService) Ticker(org.knowm.xchange.dto.marketdata.Ticker)

Aggregations

Exchange (org.knowm.xchange.Exchange)3 CCEXExchange (org.knowm.xchange.ccex.CCEXExchange)3 MarketDataService (org.knowm.xchange.service.marketdata.MarketDataService)3 OrderBook (org.knowm.xchange.dto.marketdata.OrderBook)2 LimitOrder (org.knowm.xchange.dto.trade.LimitOrder)2 BigDecimal (java.math.BigDecimal)1 ArrayList (java.util.ArrayList)1 Ticker (org.knowm.xchange.dto.marketdata.Ticker)1 SwingWrapper (org.knowm.xchart.SwingWrapper)1 XYChart (org.knowm.xchart.XYChart)1 XYChartBuilder (org.knowm.xchart.XYChartBuilder)1 XYSeries (org.knowm.xchart.XYSeries)1