Search in sources :

Example 1 with BitcoiniumTickerHistory

use of org.knowm.xchange.bitcoinium.dto.marketdata.BitcoiniumTickerHistory in project XChange by knowm.

the class BitcoiniumMarketDataServiceRaw method getBitcoiniumTickerHistory.

/**
 * @param tradableIdentifier
 * @param currency
 * @param timeWindow - The time period of the requested ticker data. Value can be from set: {
 *     "10m", "1h", "3h", "12h", "24h", "3d", "7d", "30d", "2M" }
 * @return
 * @throws IOException
 */
public BitcoiniumTickerHistory getBitcoiniumTickerHistory(String tradableIdentifier, String currency, String timeWindow) throws IOException {
    String pair = BitcoiniumUtils.createCurrencyPairString(tradableIdentifier, currency);
    verifyTimeWindow(timeWindow);
    // Request data
    BitcoiniumTickerHistory bitcoiniumTickerHistory = bitcoinium.getTickerHistory(pair, timeWindow, exchange.getExchangeSpecification().getApiKey());
    return bitcoiniumTickerHistory;
}
Also used : BitcoiniumTickerHistory(org.knowm.xchange.bitcoinium.dto.marketdata.BitcoiniumTickerHistory)

Example 2 with BitcoiniumTickerHistory

use of org.knowm.xchange.bitcoinium.dto.marketdata.BitcoiniumTickerHistory in project XChange by knowm.

the class BitcoiniumRealtimeTickerDemo method buildPanel.

public XChartPanel<XYChart> buildPanel() throws IOException {
    System.out.println("fetching data...");
    // Get the latest order book data for BTC/USD - BITSTAMP
    BitcoiniumTickerHistory bitcoiniumTickerHistory = bitcoiniumMarketDataService.getBitcoiniumTickerHistory("BTC", "BITSTAMP_USD", "THREE_HOURS");
    System.out.println(bitcoiniumTickerHistory.toString());
    // build ticker history chart series data
    xAxisData = new ArrayList<>();
    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
    chart = new XYChartBuilder().width(800).height(600).title("Real-time Bitstamp Price vs. Time").xAxisTitle("Time").yAxisTitle("Price").build();
    // Customize Chart
    chart.getStyler().setDefaultSeriesRenderStyle(XYSeriesRenderStyle.Area);
    chart.getStyler().setLegendPosition(LegendPosition.InsideNE);
    // add series
    XYSeries series = chart.addSeries(SERIES_NAME, xAxisData, yAxisData);
    series.setMarker(SeriesMarkers.NONE);
    return new XChartPanel(chart);
}
Also used : XYSeries(org.knowm.xchart.XYSeries) BitcoiniumTickerHistory(org.knowm.xchange.bitcoinium.dto.marketdata.BitcoiniumTickerHistory) BitcoiniumTicker(org.knowm.xchange.bitcoinium.dto.marketdata.BitcoiniumTicker) XChartPanel(org.knowm.xchart.XChartPanel) XYChartBuilder(org.knowm.xchart.XYChartBuilder) Date(java.util.Date)

Example 3 with BitcoiniumTickerHistory

use of org.knowm.xchange.bitcoinium.dto.marketdata.BitcoiniumTickerHistory 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)

Aggregations

BitcoiniumTickerHistory (org.knowm.xchange.bitcoinium.dto.marketdata.BitcoiniumTickerHistory)3 Date (java.util.Date)2 BitcoiniumTicker (org.knowm.xchange.bitcoinium.dto.marketdata.BitcoiniumTicker)2 XYChartBuilder (org.knowm.xchart.XYChartBuilder)2 XYSeries (org.knowm.xchart.XYSeries)2 ArrayList (java.util.ArrayList)1 Exchange (org.knowm.xchange.Exchange)1 ExchangeSpecification (org.knowm.xchange.ExchangeSpecification)1 BitcoiniumExchange (org.knowm.xchange.bitcoinium.BitcoiniumExchange)1 BitcoiniumMarketDataServiceRaw (org.knowm.xchange.bitcoinium.service.BitcoiniumMarketDataServiceRaw)1 SwingWrapper (org.knowm.xchart.SwingWrapper)1 XChartPanel (org.knowm.xchart.XChartPanel)1 XYChart (org.knowm.xchart.XYChart)1