Search in sources :

Example 1 with BitcoiniumOrderbook

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

the class BitcoiniumMarketDataService method getOrderBook.

@Override
public OrderBook getOrderBook(CurrencyPair currencyPair, Object... args) throws IOException {
    String priceWindow = "";
    if (args != null && args.length == 1) {
        Object arg0 = args[0];
        if (!(arg0 instanceof String)) {
            throw new ExchangeException("priceWindow argument must be a String!");
        } else {
            priceWindow = (String) arg0;
        }
    } else {
        throw new ExchangeException("Exactly 1 String arguments is necessary: the priceWindow!");
    }
    // Request data
    BitcoiniumOrderbook bitcoiniumOrderbook = getBitcoiniumOrderbook(currencyPair.base.getCurrencyCode(), currencyPair.counter.getCurrencyCode(), priceWindow);
    // Adapt to XChange DTOs
    return BitcoiniumAdapters.adaptOrderbook(bitcoiniumOrderbook, currencyPair);
}
Also used : BitcoiniumOrderbook(org.knowm.xchange.bitcoinium.dto.marketdata.BitcoiniumOrderbook) NotAvailableFromExchangeException(org.knowm.xchange.exceptions.NotAvailableFromExchangeException) ExchangeException(org.knowm.xchange.exceptions.ExchangeException)

Example 2 with BitcoiniumOrderbook

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

the class BitcoiniumAdapterTest method testOrderAdapterWithDepth.

@Test
public void testOrderAdapterWithDepth() throws IOException {
    // Read in the JSON from the example resources
    InputStream is = BitcoiniumDepthJSONTest.class.getResourceAsStream("/org/knowm/xchange/bitcoinium/dto/marketdata/example-depth-data.json");
    // Use Jackson to parse it
    ObjectMapper mapper = new ObjectMapper();
    BitcoiniumOrderbook bitcoiniumDepth = mapper.readValue(is, BitcoiniumOrderbook.class);
    OrderBook orderBook = BitcoiniumAdapters.adaptOrderbook(bitcoiniumDepth, CurrencyPair.BTC_USD);
    // Verify all fields filled
    assertThat(orderBook.getAsks().get(0).getLimitPrice()).isEqualTo(new BigDecimal("522.9"));
    assertThat(orderBook.getAsks().get(0).getType()).isEqualTo(OrderType.ASK);
    assertThat(orderBook.getAsks().get(0).getOriginalAmount()).isEqualTo(new BigDecimal("1.07"));
    assertThat(orderBook.getAsks().get(0).getCurrencyPair()).isEqualTo(CurrencyPair.BTC_USD);
}
Also used : BitcoiniumOrderbook(org.knowm.xchange.bitcoinium.dto.marketdata.BitcoiniumOrderbook) OrderBook(org.knowm.xchange.dto.marketdata.OrderBook) InputStream(java.io.InputStream) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) BigDecimal(java.math.BigDecimal) Test(org.junit.Test) BitcoiniumTickerJSONTest(org.knowm.xchange.bitcoinium.dto.marketdata.BitcoiniumTickerJSONTest) BitcoiniumDepthJSONTest(org.knowm.xchange.bitcoinium.dto.marketdata.BitcoiniumDepthJSONTest)

Example 3 with BitcoiniumOrderbook

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

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

the class BitcoiniumMarketDataServiceRaw method getBitcoiniumOrderbook.

/**
 * @param tradableIdentifier
 * @param currency
 * @param orderbookwindow - The width of the Orderbook as a percentage plus and minus the current
 *     price. Value can be from set: { 2p, 5p, 10p, 20p, 50p, 100p }
 * @return
 */
public BitcoiniumOrderbook getBitcoiniumOrderbook(String tradableIdentifier, String currency, String orderbookwindow) throws IOException {
    String pair = BitcoiniumUtils.createCurrencyPairString(tradableIdentifier, currency);
    verifyPriceWindow(orderbookwindow);
    // Request data
    BitcoiniumOrderbook bitcoiniumDepth = bitcoinium.getDepth(pair, orderbookwindow, exchange.getExchangeSpecification().getApiKey());
    return bitcoiniumDepth;
}
Also used : BitcoiniumOrderbook(org.knowm.xchange.bitcoinium.dto.marketdata.BitcoiniumOrderbook)

Example 5 with BitcoiniumOrderbook

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

BitcoiniumOrderbook (org.knowm.xchange.bitcoinium.dto.marketdata.BitcoiniumOrderbook)6 BitcoiniumMarketDataServiceRaw (org.knowm.xchange.bitcoinium.service.BitcoiniumMarketDataServiceRaw)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 InputStream (java.io.InputStream)1 BigDecimal (java.math.BigDecimal)1 Test (org.junit.Test)1 Exchange (org.knowm.xchange.Exchange)1 ExchangeSpecification (org.knowm.xchange.ExchangeSpecification)1 BitcoiniumExchange (org.knowm.xchange.bitcoinium.BitcoiniumExchange)1 BitcoiniumDepthJSONTest (org.knowm.xchange.bitcoinium.dto.marketdata.BitcoiniumDepthJSONTest)1 BitcoiniumTicker (org.knowm.xchange.bitcoinium.dto.marketdata.BitcoiniumTicker)1 BitcoiniumTickerJSONTest (org.knowm.xchange.bitcoinium.dto.marketdata.BitcoiniumTickerJSONTest)1 OrderBook (org.knowm.xchange.dto.marketdata.OrderBook)1 ExchangeException (org.knowm.xchange.exceptions.ExchangeException)1 NotAvailableFromExchangeException (org.knowm.xchange.exceptions.NotAvailableFromExchangeException)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