org.knowm.xchange.dto.marketdata.Ticker Java Examples
The following examples show how to use
org.knowm.xchange.dto.marketdata.Ticker.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: XChangeMarketIntegrationTest.java From wildfly-camel with Apache License 2.0 | 6 votes |
@Test public void testTickerBTCUSDT() throws Exception { try (CamelContext camelctx = new DefaultCamelContext()) { Assume.assumeTrue(checkAPIConnection()); camelctx.addRoutes(createRouteBuilder()); camelctx.start(); ProducerTemplate template = camelctx.createProducerTemplate(); Ticker ticker = template.requestBody("direct:tickerBTCUSDT", null, Ticker.class); Assert.assertNotNull("Ticker not null", ticker); System.out.println(ticker); } }
Example #2
Source File: TickerServiceTest.java From arbitrader with MIT License | 6 votes |
@Test public void testGetParallelTickers() throws IOException { Exchange exchange = new ExchangeBuilder("CrazyCoinz", CurrencyPair.BTC_USD) .withTickerStrategy(parallelTickerStrategy) .withTickers( false, Collections.singletonList(CurrencyPair.BTC_USD)) .build(); List<Ticker> tickers = tickerService.getTickers(exchange, currencyPairs); assertFalse(tickers.isEmpty()); assertTrue(errorCollectorService.isEmpty()); verify(exchange.getMarketDataService(), never()).getTickers(any()); verify(exchange.getMarketDataService(), atLeastOnce()).getTicker(any()); }
Example #3
Source File: TickerServiceTest.java From arbitrader with MIT License | 6 votes |
@Test public void testGetTickers() throws IOException { Exchange exchange = new ExchangeBuilder("CrazyCoinz", CurrencyPair.BTC_USD) .withTickerStrategy(singleCallTickerStrategy) .withTickers( true, Collections.singletonList(CurrencyPair.BTC_USD)) .build(); List<Ticker> tickers = tickerService.getTickers(exchange, currencyPairs); assertFalse(tickers.isEmpty()); assertTrue(errorCollectorService.isEmpty()); verify(exchange.getMarketDataService()).getTickers(any()); verify(exchange.getMarketDataService(), never()).getTicker(any()); }
Example #4
Source File: BinanceTicker24h.java From zheshiyigeniubidexiangmu with MIT License | 6 votes |
public synchronized Ticker toTicker() { CurrencyPair currencyPair = pair; if (currencyPair == null) { currencyPair = BinanceAdapters.adaptSymbol(symbol); } if (ticker == null) { ticker = new Ticker.Builder() .currencyPair(currencyPair) .open(openPrice) .ask(askPrice) .bid(bidPrice) .last(lastPrice) .high(highPrice) .low(lowPrice) .volume(volume) .vwap(weightedAvgPrice) .askSize(askQty) .bidSize(bidQty) .quoteVolume(quoteVolume) .build(); } return ticker; }
Example #5
Source File: SingleCallTickerStrategyTest.java From arbitrader with MIT License | 6 votes |
@Test public void testGetTickers() throws IOException { Exchange exchange = new ExchangeBuilder("CrazyCoinz", CurrencyPair.BTC_USD) .withTickerStrategy(tickerStrategy) .withTickers( true, Collections.singletonList(CurrencyPair.BTC_USD)) .build(); List<Ticker> tickers = tickerStrategy.getTickers(exchange, currencyPairs); assertEquals(1, tickers.size()); assertTrue(errorCollectorService.isEmpty()); Ticker ticker = tickers.get(0); assertEquals(CurrencyPair.BTC_USD, ticker.getCurrencyPair()); }
Example #6
Source File: ParallelTickerStrategyTest.java From arbitrader with MIT License | 6 votes |
@Test public void testGetTickers() throws IOException { Exchange exchange = new ExchangeBuilder("CrazyCoinz", CurrencyPair.BTC_USD) .withTickerStrategy(tickerStrategy) .withTickers( true, Collections.singletonList(CurrencyPair.BTC_USD)) .build(); List<Ticker> tickers = tickerStrategy.getTickers(exchange, currencyPairs); assertEquals(1, tickers.size()); assertTrue(errorCollectorService.isEmpty()); Ticker ticker = tickers.get(0); assertEquals(CurrencyPair.BTC_USD, ticker.getCurrencyPair()); }
Example #7
Source File: CoinbaseMarketDataService.java From zheshiyigeniubidexiangmu with MIT License | 6 votes |
/** * @param args Optional Boolean. If true an additional call to retrieve the spot price history * will be made and used to populate the 24 hour high and low values for the Ticker. * @return A Ticker with Coinbase's current buy price as the best ask, sell price as the best bid, * spot price as the last value, and can optionally use the spot price history to find the 24 * hour high and low. */ @Override public Ticker getTicker(CurrencyPair currencyPair, final Object... args) throws IOException { final String currency = currencyPair.counter.getCurrencyCode(); final CoinbasePrice buyPrice = super.getCoinbaseBuyPrice(BigDecimal.ONE, currency); final CoinbasePrice sellPrice = super.getCoinbaseSellPrice(BigDecimal.ONE, currency); final CoinbaseMoney spotRate = super.getCoinbaseSpotRate(currency); final CoinbaseSpotPriceHistory coinbaseSpotPriceHistory = (args != null && args.length > 0 && args[0] != null && args[0] instanceof Boolean && (Boolean) args[0]) ? super.getCoinbaseHistoricalSpotRates() : null; return CoinbaseAdapters.adaptTicker( currencyPair, buyPrice, sellPrice, spotRate, coinbaseSpotPriceHistory); }
Example #8
Source File: ExchangeBuilder.java From arbitrader with MIT License | 6 votes |
public ExchangeBuilder withTickers(boolean isGetTickersImplemented, List<CurrencyPair> currencyPairs) { this.isGetTickersImplemented = isGetTickersImplemented; this.tradingPairs.addAll(currencyPairs); currencyPairs.forEach(currencyPair -> tickers.add(new Ticker.Builder() .currencyPair(currencyPair) .open(new BigDecimal("1000.000")) .last(new BigDecimal("1001.000")) .bid(new BigDecimal("1001.000")) .ask(new BigDecimal("1002.000")) .high(new BigDecimal("1005.00")) .low(new BigDecimal("1000.00")) .vwap(new BigDecimal("1000.50")) .volume(new BigDecimal("500000.00")) .quoteVolume(new BigDecimal("600000.00")) .bidSize(new BigDecimal("400.00")) .askSize(new BigDecimal("600.00")) .build()) ); return this; }
Example #9
Source File: BitfinexAdapters.java From zheshiyigeniubidexiangmu with MIT License | 6 votes |
public static Ticker adaptTicker(BitfinexTicker bitfinexTicker, CurrencyPair currencyPair) { BigDecimal last = bitfinexTicker.getLast_price(); BigDecimal bid = bitfinexTicker.getBid(); BigDecimal ask = bitfinexTicker.getAsk(); BigDecimal high = bitfinexTicker.getHigh(); BigDecimal low = bitfinexTicker.getLow(); BigDecimal volume = bitfinexTicker.getVolume(); Date timestamp = DateUtils.fromMillisUtc((long) (bitfinexTicker.getTimestamp() * 1000L)); return new Ticker.Builder() .currencyPair(currencyPair) .last(last) .bid(bid) .ask(ask) .high(high) .low(low) .volume(volume) .timestamp(timestamp) .build(); }
Example #10
Source File: Spread.java From arbitrader with MIT License | 6 votes |
public Spread( CurrencyPair currencyPair, Exchange longExchange, Exchange shortExchange, Ticker longTicker, Ticker shortTicker, BigDecimal in, BigDecimal out) { this.currencyPair = currencyPair; this.longExchange = longExchange; this.shortExchange = shortExchange; this.longTicker = longTicker; this.shortTicker = shortTicker; this.in = in; this.out = out; }
Example #11
Source File: BitfinexAdapters.java From zheshiyigeniubidexiangmu with MIT License | 6 votes |
public static Ticker adaptTicker(BitfinexTicker bitfinexTicker) { BigDecimal last = bitfinexTicker.getLastPrice(); BigDecimal bid = bitfinexTicker.getBid(); BigDecimal bidSize = bitfinexTicker.getBidSize(); BigDecimal ask = bitfinexTicker.getAsk(); BigDecimal askSize = bitfinexTicker.getAskSize(); BigDecimal high = bitfinexTicker.getHigh(); BigDecimal low = bitfinexTicker.getLow(); BigDecimal volume = bitfinexTicker.getVolume(); CurrencyPair currencyPair = CurrencyPairDeserializer.getCurrencyPairFromString(bitfinexTicker.getSymbol().substring(1)); return new Ticker.Builder() .currencyPair(currencyPair) .last(last) .bid(bid) .ask(ask) .high(high) .low(low) .volume(volume) .bidSize(bidSize) .askSize(askSize) .build(); }
Example #12
Source File: XChangeMarketIntegrationTest.java From wildfly-camel with Apache License 2.0 | 6 votes |
@Test public void testTicker() throws Exception { try (CamelContext camelctx = new DefaultCamelContext()) { Assume.assumeTrue(checkAPIConnection()); camelctx.addRoutes(createRouteBuilder()); camelctx.start(); ProducerTemplate template = camelctx.createProducerTemplate(); Ticker ticker = template.requestBody("direct:ticker", CurrencyPair.EOS_ETH, Ticker.class); Assert.assertNotNull("Ticker not null", ticker); System.out.println(ticker); ticker = template.requestBodyAndHeader("direct:ticker", null, HEADER_CURRENCY_PAIR, CurrencyPair.EOS_ETH, Ticker.class); Assert.assertNotNull("Ticker not null", ticker); System.out.println(ticker); } }
Example #13
Source File: BitZAdapters.java From zheshiyigeniubidexiangmu with MIT License | 6 votes |
public static Ticker adaptTicker(BitZTicker bitzTicker, CurrencyPair currencyPair) { BigDecimal last = bitzTicker.getLast(); BigDecimal bid = bitzTicker.getSell(); BigDecimal ask = bitzTicker.getBuy(); BigDecimal high = bitzTicker.getHigh(); BigDecimal low = bitzTicker.getLow(); BigDecimal volume = bitzTicker.getVolume(); Date timestamp = DateUtils.fromMillisUtc(bitzTicker.getTimestamp()); Ticker ticker = new Ticker.Builder() .currencyPair(currencyPair) .last(last) .bid(bid) .ask(ask) .high(high) .low(low) .volume(volume) .timestamp(timestamp) .build(); return ticker; }
Example #14
Source File: TickerService.java From arbitrader with MIT License | 6 votes |
List<Ticker> getTickers(Exchange exchange, List<CurrencyPair> currencyPairs) { TickerStrategy tickerStrategy = (TickerStrategy)exchange.getExchangeSpecification().getExchangeSpecificParametersItem(TICKER_STRATEGY_KEY); try { List<Ticker> tickers = tickerStrategy.getTickers(exchange, currencyPairs); tickers.forEach(ticker -> LOGGER.debug("Ticker: {} {} {}/{}", exchange.getExchangeSpecification().getExchangeName(), ticker.getCurrencyPair(), ticker.getBid(), ticker.getAsk())); return tickers; } catch (RuntimeException re) { LOGGER.debug("Unexpected runtime exception: " + re.getMessage(), re); errorCollectorService.collect(exchange, re); } return Collections.emptyList(); }
Example #15
Source File: StreamingTickerStrategyTest.java From arbitrader with MIT License | 5 votes |
@Test public void testInvalidExchange() throws Exception { Exchange nonStreamingExchange = new ExchangeBuilder("CrazyCoinz",CurrencyPair.BTC_USD).build(); List<Ticker> result = streamingTickerStrategy.getTickers(nonStreamingExchange, List.of(CurrencyPair.BTC_USD)); assertTrue(result.isEmpty()); }
Example #16
Source File: KnowmExchangeRateProvider.java From consensusj with Apache License 2.0 | 5 votes |
public ExchangeRateUpdate getUpdate(CurrencyUnitPair pair) { MonitoredCurrency pairMonitor = monitoredCurrencies.get(pair); Ticker ticker; try { ticker = marketDataService.getTicker(pairMonitor.exchangePair); } catch (IOException e) { e.printStackTrace(); ticker = null; } return tickerToUpdate(pair, ticker); }
Example #17
Source File: BitZAdapters.java From zheshiyigeniubidexiangmu with MIT License | 5 votes |
public static List<Ticker> adaptTickers(BitZTickerAllResult bitZTickerAllResult) { List<Ticker> tickers = new ArrayList<Ticker>(); for (Entry<String, BitZTicker> ticker : bitZTickerAllResult.getData().getAllTickers().entrySet()) { CurrencyPair pair = BitZUtils.toCurrencyPair(ticker.getKey()); if (pair != null) { tickers.add(adaptTicker(ticker.getValue(), pair)); } } return tickers; }
Example #18
Source File: ParallelTickerStrategyTest.java From arbitrader with MIT License | 5 votes |
@Test public void testGetTickersExchangeException() throws IOException { Exchange exchange = new ExchangeBuilder("CrazyCoinz", CurrencyPair.BTC_USD) .withTickerStrategy(tickerStrategy) .withTickers(new ExchangeException("Boom!")) .build(); List<Ticker> tickers = tickerStrategy.getTickers(exchange, currencyPairs); assertTrue(tickers.isEmpty()); assertFalse(errorCollectorService.isEmpty()); }
Example #19
Source File: StreamingTickerStrategy.java From arbitrader with MIT License | 5 votes |
@Override public List<Ticker> getTickers(Exchange stdExchange, List<CurrencyPair> currencyPairs) { if (!(stdExchange instanceof StreamingExchange)) { LOGGER.warn("{} is not a streaming exchange", stdExchange.getExchangeSpecification().getExchangeName()); return Collections.emptyList(); } StreamingExchange exchange = (StreamingExchange)stdExchange; if (!tickers.containsKey(exchange)) { ProductSubscription.ProductSubscriptionBuilder builder = ProductSubscription.create(); currencyPairs.forEach(builder::addTicker); exchange.connect(builder.build()).blockingAwait(); subscriptions.addAll(subscribeAll(exchange, currencyPairs)); } if (tickers.containsKey(exchange)) { return tickers.get(exchange).entrySet() .stream() .filter(entry -> currencyPairs.contains(entry.getKey())) .map(Map.Entry::getValue) .collect(Collectors.toList()); } return Collections.emptyList(); }
Example #20
Source File: TickerServiceTest.java From arbitrader with MIT License | 5 votes |
@Test public void testIsInvalidTicker() { Ticker ticker = new Ticker.Builder() .bid(new BigDecimal("120.00")) .ask(new BigDecimal("123.00")) .build(); assertFalse(tickerService.isInvalidTicker(ticker)); }
Example #21
Source File: KnowmExchangeRateProvider.java From consensusj with Apache License 2.0 | 5 votes |
private ExchangeRate buildExchangeRate(CurrencyUnitPair pair, Ticker ticker) { return new ExchangeRateBuilder(name, RateType.DEFERRED) .setBase(pair.getBase()) .setTerm(pair.getTarget()) .setFactor(DefaultNumberValue.of(ticker.getLast())) .build(); }
Example #22
Source File: TickerServiceTest.java From arbitrader with MIT License | 5 votes |
@Test public void testGetTickersException() throws IOException { Exchange exchange = new ExchangeBuilder("CrazyCoinz", CurrencyPair.BTC_USD) .withTickerStrategy(singleCallTickerStrategy) .withTickers(new ExchangeException("Boom!")) .build(); List<Ticker> tickers = tickerService.getTickers(exchange, currencyPairs); assertTrue(tickers.isEmpty()); assertFalse(errorCollectorService.isEmpty()); verify(exchange.getMarketDataService()).getTickers(any()); verify(exchange.getMarketDataService(), never()).getTicker(any()); }
Example #23
Source File: BitmexAdapters.java From zheshiyigeniubidexiangmu with MIT License | 5 votes |
public static Ticker adaptTicker(BitmexTicker bitmexTicker, CurrencyPair currencyPair) { Ticker.Builder builder = new Ticker.Builder(); builder.open(bitmexTicker.getPrevClosePrice()); builder.ask(bitmexTicker.getAskPrice()); builder.bid(bitmexTicker.getBidPrice()); builder.last(bitmexTicker.getLastPrice()); builder.high(bitmexTicker.getHighPrice()); builder.low(bitmexTicker.getLowPrice()); builder.vwap(new BigDecimal(bitmexTicker.getVwap().longValue())); builder.volume(bitmexTicker.getVolume24h()); builder.currencyPair(currencyPair); return builder.build(); }
Example #24
Source File: BitmexMarketDataService.java From zheshiyigeniubidexiangmu with MIT License | 5 votes |
@Override public Ticker getTicker(CurrencyPair currencyPair, Object... args) throws IOException { List<BitmexTicker> bitmexTickers = getTicker(currencyPair.base.toString() + currencyPair.counter.toString()); if (bitmexTickers.isEmpty()) { return null; } BitmexTicker bitmexTicker = bitmexTickers.get(0); DateFormat format = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'"); Ticker ticker = null; try { ticker = new Ticker.Builder() .currencyPair(currencyPair) .open(bitmexTicker.getOpenValue()) .last(bitmexTicker.getLastPrice()) .bid(bitmexTicker.getBidPrice()) .ask(bitmexTicker.getAskPrice()) .high(bitmexTicker.getHighPrice()) .low(bitmexTicker.getLowPrice()) .vwap(new BigDecimal(bitmexTicker.getVwap())) .volume(bitmexTicker.getVolume24h()) .quoteVolume(null) .timestamp(format.parse(bitmexTicker.getTimestamp())) .build(); } catch (ParseException e) { return null; } return ticker; }
Example #25
Source File: ReactiveKnowmExchangeProvider.java From consensusj with Apache License 2.0 | 5 votes |
public ExchangeRateUpdate tickerMapper(Ticker ticker) { Date timestamp = ticker.getTimestamp(); long time = (timestamp != null) ? timestamp.getTime() : 0; return new ExchangeRateUpdate(pair, DefaultNumberValue.of(ticker.getBid()), time); }
Example #26
Source File: ReactiveKnowmExchangeProvider.java From consensusj with Apache License 2.0 | 5 votes |
public Ticker pollForTicker() { try { return marketDataService.getTicker(exchangePair); } catch (IOException e) { throw new RuntimeException(e); } }
Example #27
Source File: BiboxAdapters.java From zheshiyigeniubidexiangmu with MIT License | 5 votes |
public static Ticker adaptTicker(BiboxTicker ticker, CurrencyPair currencyPair) { return new Ticker.Builder() .currencyPair(currencyPair) .ask(ticker.getSell()) .bid(ticker.getBuy()) .high(ticker.getHigh()) .low(ticker.getLow()) .last(ticker.getLast()) .volume(ticker.getVol()) .timestamp(new Date(ticker.getTimestamp())) .build(); }
Example #28
Source File: HuobiAdapters.java From zheshiyigeniubidexiangmu with MIT License | 5 votes |
public static Ticker adaptTicker(HuobiTicker huobiTicker, CurrencyPair currencyPair) { Ticker.Builder builder = new Ticker.Builder(); builder.open(huobiTicker.getOpen()); builder.ask(huobiTicker.getAsk().getPrice()); builder.bid(huobiTicker.getBid().getPrice()); builder.last(huobiTicker.getClose()); builder.high(huobiTicker.getHigh()); builder.low(huobiTicker.getLow()); builder.volume(huobiTicker.getVol()); builder.timestamp(huobiTicker.getTs()); builder.currencyPair(currencyPair); return builder.build(); }
Example #29
Source File: OkCoinAdapters.java From zheshiyigeniubidexiangmu with MIT License | 5 votes |
public static Ticker adaptTicker(OkCoinTickerResponse tickerResponse, CurrencyPair currencyPair) { final Date date = adaptDate(tickerResponse.getDate()); return new Ticker.Builder() .currencyPair(currencyPair) .high(tickerResponse.getTicker().getHigh()) .low(tickerResponse.getTicker().getLow()) .bid(tickerResponse.getTicker().getBuy()) .ask(tickerResponse.getTicker().getSell()) .last(tickerResponse.getTicker().getLast()) .volume(tickerResponse.getTicker().getVol()) .timestamp(date) .build(); }
Example #30
Source File: OkCoinFuturesMarketDataService.java From zheshiyigeniubidexiangmu with MIT License | 5 votes |
@Override public Ticker getTicker(CurrencyPair currencyPair, Object... args) throws IOException { if (args != null && args.length > 0) { return OkCoinAdapters.adaptTicker( getFuturesTicker(currencyPair, (FuturesContract) args[0]), currencyPair); } else { return OkCoinAdapters.adaptTicker( getFuturesTicker(currencyPair, futuresContract), currencyPair); } }