Search in sources :

Example 1 with BitcoiniumTicker

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

the class BitcoiniumMarketDataServiceRaw method getBitcoiniumTicker.

/**
 * @param tradableIdentifier
 * @param currency
 * @return a Bitcoinium Ticker object
 * @throws IOException
 */
public BitcoiniumTicker getBitcoiniumTicker(String tradableIdentifier, String currency) throws IOException {
    String pair = BitcoiniumUtils.createCurrencyPairString(tradableIdentifier, currency);
    // Request data
    BitcoiniumTicker bitcoiniumTicker = bitcoinium.getTicker(pair, exchange.getExchangeSpecification().getApiKey());
    // Adapt to XChange DTOs
    return bitcoiniumTicker;
}
Also used : BitcoiniumTicker(org.knowm.xchange.bitcoinium.dto.marketdata.BitcoiniumTicker)

Example 2 with BitcoiniumTicker

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

the class BitcoiniumMarketDataDemo method raw.

private static void raw(Exchange exchange) throws IOException {
    // Interested in the public market data feed (no authentication)
    BitcoiniumMarketDataServiceRaw bitcoiniumSpecificMarketDataService = (BitcoiniumMarketDataServiceRaw) exchange.getMarketDataService();
    // Get the latest ticker data showing BTC to USD
    BitcoiniumTicker bitcoiniumTicker = bitcoiniumSpecificMarketDataService.getBitcoiniumTicker("BTC", "BITSTAMP_USD");
    System.out.println("Last: " + bitcoiniumTicker.getLast());
    System.out.println("Bid: " + bitcoiniumTicker.getBid());
    System.out.println("Ask: " + bitcoiniumTicker.getAsk());
    System.out.println("Volume: " + bitcoiniumTicker.getVolume());
    // Get the latest order book data for BTC/USD - MtGox
    BitcoiniumOrderbook bitcoiniumOrderbook = bitcoiniumSpecificMarketDataService.getBitcoiniumOrderbook("BTC", "BITSTAMP_USD", "TEN_PERCENT");
    System.out.println("Order book: " + bitcoiniumOrderbook);
}
Also used : BitcoiniumOrderbook(org.knowm.xchange.bitcoinium.dto.marketdata.BitcoiniumOrderbook) BitcoiniumMarketDataServiceRaw(org.knowm.xchange.bitcoinium.service.BitcoiniumMarketDataServiceRaw) BitcoiniumTicker(org.knowm.xchange.bitcoinium.dto.marketdata.BitcoiniumTicker)

Example 3 with BitcoiniumTicker

use of org.knowm.xchange.bitcoinium.dto.marketdata.BitcoiniumTicker 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 4 with BitcoiniumTicker

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

the class BitcoiniumRealtimeTickerDemo method go.

private void go() throws IOException {
    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)
    bitcoiniumMarketDataService = (BitcoiniumMarketDataServiceRaw) bitcoiniumExchange.getMarketDataService();
    // Setup the panel
    final XChartPanel<XYChart> chartPanel = buildPanel();
    // Schedule a job for the event-dispatching thread:
    // creating and showing this application's GUI.
    javax.swing.SwingUtilities.invokeLater(new Runnable() {

        @Override
        public void run() {
            // Create and set up the window.
            JFrame frame = new JFrame("XChart");
            frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            frame.add(chartPanel);
            // Display the window.
            frame.pack();
            frame.setVisible(true);
        }
    });
    // Simulate a data feed
    TimerTask chartUpdaterTask = new TimerTask() {

        @Override
        public void run() {
            try {
                BitcoiniumTicker bitcoiniumTicker = bitcoiniumMarketDataService.getBitcoiniumTicker("BTC", "BITSTAMP_USD");
                System.out.println(bitcoiniumTicker.toString());
                Date timestamp = new Date(bitcoiniumTicker.getTimestamp());
                float price = bitcoiniumTicker.getLast().floatValue();
                if (xAxisData.get(xAxisData.size() - 1).getTime() != timestamp.getTime()) {
                    xAxisData.add(timestamp);
                    yAxisData.add(price);
                    XYSeries series = chart.updateXYSeries(SERIES_NAME, xAxisData, yAxisData, null);
                    chartPanel.revalidate();
                    chartPanel.repaint();
                    System.out.println(series.getXData());
                    System.out.println(series.getYData());
                } else {
                    System.out.println("No new data.");
                }
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    };
    Timer timer = new Timer();
    // every ten
    timer.scheduleAtFixedRate(chartUpdaterTask, 0, 10000);
// seconds
}
Also used : XYSeries(org.knowm.xchart.XYSeries) IOException(java.io.IOException) Date(java.util.Date) BitcoiniumExchange(org.knowm.xchange.bitcoinium.BitcoiniumExchange) Exchange(org.knowm.xchange.Exchange) TimerTask(java.util.TimerTask) Timer(java.util.Timer) JFrame(javax.swing.JFrame) XYChart(org.knowm.xchart.XYChart) ExchangeSpecification(org.knowm.xchange.ExchangeSpecification) BitcoiniumTicker(org.knowm.xchange.bitcoinium.dto.marketdata.BitcoiniumTicker)

Example 5 with BitcoiniumTicker

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

BitcoiniumTicker (org.knowm.xchange.bitcoinium.dto.marketdata.BitcoiniumTicker)6 Date (java.util.Date)3 XYSeries (org.knowm.xchart.XYSeries)3 Exchange (org.knowm.xchange.Exchange)2 ExchangeSpecification (org.knowm.xchange.ExchangeSpecification)2 BitcoiniumExchange (org.knowm.xchange.bitcoinium.BitcoiniumExchange)2 BitcoiniumTickerHistory (org.knowm.xchange.bitcoinium.dto.marketdata.BitcoiniumTickerHistory)2 BitcoiniumMarketDataServiceRaw (org.knowm.xchange.bitcoinium.service.BitcoiniumMarketDataServiceRaw)2 XYChart (org.knowm.xchart.XYChart)2 XYChartBuilder (org.knowm.xchart.XYChartBuilder)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 BigDecimal (java.math.BigDecimal)1 ArrayList (java.util.ArrayList)1 Timer (java.util.Timer)1 TimerTask (java.util.TimerTask)1 JFrame (javax.swing.JFrame)1 Test (org.junit.Test)1 BitcoiniumDepthJSONTest (org.knowm.xchange.bitcoinium.dto.marketdata.BitcoiniumDepthJSONTest)1