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);
}
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);
}
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);
}
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;
}
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();
}
Aggregations