Search in sources :

Example 26 with Ticker

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

the class MarketDataTest method testTickerAdapter.

@Test
public void testTickerAdapter() throws Exception {
    InputStream is = MarketDataTest.class.getResourceAsStream("/org/knowm/xchange/btcc/ticker.json");
    ObjectMapper mapper = new ObjectMapper();
    TypeFactory t = TypeFactory.defaultInstance();
    Map<String, BTCCTicker> response = mapper.readValue(is, t.constructMapType(Map.class, String.class, BTCCTicker.class));
    BTCCTicker btccTicker = response.get("ticker");
    Ticker ticker = BTCCAdapters.adaptTicker(btccTicker, CurrencyPair.BTC_USD);
    assertThat(ticker.getHigh()).isEqualTo(new BigDecimal("1730"));
    assertThat(ticker.getLow()).isEqualTo(new BigDecimal("1688"));
    assertThat(ticker.getLast()).isEqualTo(new BigDecimal("1725"));
    assertThat(ticker.getVolume()).isEqualTo(new BigDecimal("113.3411"));
    assertThat(ticker.getAsk()).isEqualTo(new BigDecimal("1729"));
    assertThat(ticker.getBid()).isEqualTo(new BigDecimal("1725"));
}
Also used : InputStream(java.io.InputStream) Ticker(org.knowm.xchange.dto.marketdata.Ticker) BTCCTicker(org.knowm.xchange.btcc.dto.marketdata.BTCCTicker) TypeFactory(com.fasterxml.jackson.databind.type.TypeFactory) BTCCTicker(org.knowm.xchange.btcc.dto.marketdata.BTCCTicker) Map(java.util.Map) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) BigDecimal(java.math.BigDecimal) Test(org.junit.Test)

Example 27 with Ticker

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

the class BTCMarketsAdaptersTest method shouldAdaptTicker.

@Test
public void shouldAdaptTicker() throws IOException {
    final BTCMarketsTicker response = parse(BTCMarketsTicker.class);
    final Ticker ticker = BTCMarketsAdapters.adaptTicker(CurrencyPair.BTC_AUD, response);
    assertThat(ticker.getBid()).isEqualTo("137.00");
    assertThat(ticker.getAsk()).isEqualTo("140.00");
    assertThat(ticker.getLast()).isEqualTo("140.00");
    assertThat(ticker.getCurrencyPair()).isEqualTo(CurrencyPair.BTC_AUD);
    assertThat(ticker.getTimestamp().getTime()).isEqualTo(1378878117000L);
}
Also used : Ticker(org.knowm.xchange.dto.marketdata.Ticker) BTCMarketsTicker(org.knowm.xchange.btcmarkets.dto.marketdata.BTCMarketsTicker) BTCMarketsTicker(org.knowm.xchange.btcmarkets.dto.marketdata.BTCMarketsTicker) Test(org.junit.Test)

Example 28 with Ticker

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

the class BTCTradeAdaptersTest method testAdaptTicker.

@Test
public void testAdaptTicker() throws IOException {
    BTCTradeTicker btcTradeTicker = mapper.readValue(getClass().getResource("dto/marketdata/ticker.json"), BTCTradeTicker.class);
    Ticker ticker = BTCTradeAdapters.adaptTicker(btcTradeTicker, CurrencyPair.BTC_CNY);
    assertEquals(new BigDecimal("3760"), ticker.getHigh());
    assertEquals(new BigDecimal("3658"), ticker.getLow());
    assertEquals(new BigDecimal("3752"), ticker.getBid());
    assertEquals(new BigDecimal("3758"), ticker.getAsk());
    assertEquals(new BigDecimal("3757"), ticker.getLast());
    assertEquals(new BigDecimal("11009.76"), ticker.getVolume());
}
Also used : BTCTradeTicker(org.knowm.xchange.btctrade.dto.marketdata.BTCTradeTicker) BTCTradeTicker(org.knowm.xchange.btctrade.dto.marketdata.BTCTradeTicker) Ticker(org.knowm.xchange.dto.marketdata.Ticker) BigDecimal(java.math.BigDecimal) Test(org.junit.Test)

Example 29 with Ticker

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

the class TickerDemo method generic.

private static void generic(MarketDataService marketDataService) throws IOException {
    Ticker ticker = marketDataService.getTicker(CurrencyPair.BTC_USD);
    System.out.println(ticker.toString());
}
Also used : Ticker(org.knowm.xchange.dto.marketdata.Ticker)

Example 30 with Ticker

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

the class ParibuTickerDemo method generic.

private static void generic(MarketDataService marketDataService) throws IOException {
    Ticker ticker = marketDataService.getTicker(CurrencyPair.BTC_TRY);
    System.out.println(ticker.toString());
}
Also used : Ticker(org.knowm.xchange.dto.marketdata.Ticker) ParibuTicker(org.knowm.xchange.paribu.dto.marketdata.ParibuTicker)

Aggregations

Ticker (org.knowm.xchange.dto.marketdata.Ticker)201 Test (org.junit.Test)101 MarketDataService (org.knowm.xchange.service.marketdata.MarketDataService)69 CurrencyPair (org.knowm.xchange.currency.CurrencyPair)68 BigDecimal (java.math.BigDecimal)66 Exchange (org.knowm.xchange.Exchange)48 Date (java.util.Date)34 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)23 InputStream (java.io.InputStream)23 OrderBook (org.knowm.xchange.dto.marketdata.OrderBook)22 Trades (org.knowm.xchange.dto.marketdata.Trades)15 IOException (java.io.IOException)10 Map (java.util.Map)9 ArrayList (java.util.ArrayList)8 ExchangeSpecification (org.knowm.xchange.ExchangeSpecification)8 Arrays (java.util.Arrays)6 Collectors (java.util.stream.Collectors)6 Balance (org.knowm.xchange.dto.account.Balance)6 JsonNode (com.fasterxml.jackson.databind.JsonNode)5 List (java.util.List)5