Search in sources :

Example 1 with MercadoBitcoinTicker

use of org.knowm.xchange.mercadobitcoin.dto.marketdata.MercadoBitcoinTicker in project XChange by knowm.

the class TickerDemo method raw.

private static void raw(MercadoBitcoinMarketDataServiceRaw marketDataService) throws IOException {
    MercadoBitcoinTicker mercadoBitcoinTicker = marketDataService.getMercadoBitcoinTicker(CurrencyPair.BTC_BRL);
    System.out.println(mercadoBitcoinTicker.toString());
}
Also used : MercadoBitcoinTicker(org.knowm.xchange.mercadobitcoin.dto.marketdata.MercadoBitcoinTicker)

Example 2 with MercadoBitcoinTicker

use of org.knowm.xchange.mercadobitcoin.dto.marketdata.MercadoBitcoinTicker in project XChange by knowm.

the class MercadoBitcoinAdapters method adaptTicker.

/**
 * Adapts a MercadoBitcoinTicker to a Ticker Object
 *
 * @param mercadoBitcoinTicker The exchange specific ticker
 * @param currencyPair (e.g. BTC/USD)
 * @return The ticker
 */
public static Ticker adaptTicker(MercadoBitcoinTicker mercadoBitcoinTicker, CurrencyPair currencyPair) {
    BigDecimal last = mercadoBitcoinTicker.getTicker().getLast();
    BigDecimal bid = mercadoBitcoinTicker.getTicker().getBuy();
    BigDecimal ask = mercadoBitcoinTicker.getTicker().getSell();
    BigDecimal high = mercadoBitcoinTicker.getTicker().getHigh();
    BigDecimal low = mercadoBitcoinTicker.getTicker().getLow();
    BigDecimal volume = mercadoBitcoinTicker.getTicker().getVol();
    Date timestamp = new Date(mercadoBitcoinTicker.getTicker().getDate() * 1000L);
    return new Ticker.Builder().currencyPair(currencyPair).last(last).bid(bid).ask(ask).high(high).low(low).volume(volume).timestamp(timestamp).build();
}
Also used : MercadoBitcoinTicker(org.knowm.xchange.mercadobitcoin.dto.marketdata.MercadoBitcoinTicker) Ticker(org.knowm.xchange.dto.marketdata.Ticker) BigDecimal(java.math.BigDecimal) Date(java.util.Date)

Example 3 with MercadoBitcoinTicker

use of org.knowm.xchange.mercadobitcoin.dto.marketdata.MercadoBitcoinTicker in project XChange by knowm.

the class MercadoBitcoinAdapterTest method testTickerAdapter.

@Test
public void testTickerAdapter() throws IOException {
    // Read in the JSON from the example resources
    InputStream is = MercadoBitcoinAdapterTest.class.getResourceAsStream("/org/knowm/xchange/mercadobitcoin/dto/marketdata/example-ticker-data.json");
    // Use Jackson to parse it
    ObjectMapper mapper = new ObjectMapper();
    MercadoBitcoinTicker mercadoBitcoinTicker = mapper.readValue(is, MercadoBitcoinTicker.class);
    Ticker ticker = MercadoBitcoinAdapters.adaptTicker(mercadoBitcoinTicker, CurrencyPair.BTC_BRL);
    assertThat(ticker.getLast().toString()).isEqualTo("1019.99999");
    assertThat(ticker.getBid().toString()).isEqualTo("1019.99999");
    assertThat(ticker.getAsk().toString()).isEqualTo("1020");
    assertThat(ticker.getVolume()).isEqualTo(new BigDecimal("6.90157391"));
    assertThat(ticker.getTimestamp()).isEqualTo(new Date(1417226432L * 1000L));
}
Also used : MercadoBitcoinTicker(org.knowm.xchange.mercadobitcoin.dto.marketdata.MercadoBitcoinTicker) InputStream(java.io.InputStream) MercadoBitcoinTicker(org.knowm.xchange.mercadobitcoin.dto.marketdata.MercadoBitcoinTicker) Ticker(org.knowm.xchange.dto.marketdata.Ticker) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) BigDecimal(java.math.BigDecimal) Date(java.util.Date) Test(org.junit.Test)

Example 4 with MercadoBitcoinTicker

use of org.knowm.xchange.mercadobitcoin.dto.marketdata.MercadoBitcoinTicker in project XChange by knowm.

the class TickerDemo method raw.

private static void raw(MercadoBitcoinMarketDataServiceRaw marketDataService) throws IOException {
    MercadoBitcoinTicker mercadoBitcoinTicker = marketDataService.getMercadoBitcoinTicker(new CurrencyPair(Currency.LTC, Currency.BRL));
    System.out.println(mercadoBitcoinTicker.toString());
}
Also used : MercadoBitcoinTicker(org.knowm.xchange.mercadobitcoin.dto.marketdata.MercadoBitcoinTicker) CurrencyPair(org.knowm.xchange.currency.CurrencyPair)

Aggregations

MercadoBitcoinTicker (org.knowm.xchange.mercadobitcoin.dto.marketdata.MercadoBitcoinTicker)4 BigDecimal (java.math.BigDecimal)2 Date (java.util.Date)2 Ticker (org.knowm.xchange.dto.marketdata.Ticker)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 InputStream (java.io.InputStream)1 Test (org.junit.Test)1 CurrencyPair (org.knowm.xchange.currency.CurrencyPair)1