Search in sources :

Example 1 with BitfinexTicker

use of org.knowm.xchange.bitfinex.v1.dto.marketdata.BitfinexTicker in project XChange by knowm.

the class TickerDemo method raw.

private static void raw(BitfinexMarketDataServiceRaw marketDataService) throws IOException {
    // Get the latest ticker data showing BTC to USD
    BitfinexTicker ticker = marketDataService.getBitfinexTicker("btcusd");
    System.out.println(ticker.toString());
}
Also used : BitfinexTicker(org.knowm.xchange.bitfinex.v1.dto.marketdata.BitfinexTicker)

Example 2 with BitfinexTicker

use of org.knowm.xchange.bitfinex.v1.dto.marketdata.BitfinexTicker in project XChange by knowm.

the class BitfinexAdapters method adaptTicker.

public static Ticker adaptTicker(org.knowm.xchange.bitfinex.v2.dto.marketdata.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();
    BigDecimal percentageChange = bitfinexTicker.getDailyChangePerc().multiply(new BigDecimal("100"), new MathContext(8));
    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).percentageChange(percentageChange).build();
}
Also used : BitfinexTicker(org.knowm.xchange.bitfinex.v1.dto.marketdata.BitfinexTicker) Ticker(org.knowm.xchange.dto.marketdata.Ticker) BigDecimal(java.math.BigDecimal) MathContext(java.math.MathContext) CurrencyPair(org.knowm.xchange.currency.CurrencyPair)

Example 3 with BitfinexTicker

use of org.knowm.xchange.bitfinex.v1.dto.marketdata.BitfinexTicker in project XChange by knowm.

the class BitfinexAdapters method adaptTicker.

public static Ticker adaptTicker(BitfinexTicker bitfinexTicker, CurrencyPair currencyPair) {
    BigDecimal last = bitfinexTicker.getLast_price();
    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();
    Date timestamp = DateUtils.fromMillisUtc((long) (bitfinexTicker.getTimestamp() * 1000L));
    return new Ticker.Builder().currencyPair(currencyPair).last(last).bid(bid).bidSize(bidSize).ask(ask).askSize(askSize).high(high).low(low).volume(volume).timestamp(timestamp).build();
}
Also used : BitfinexTicker(org.knowm.xchange.bitfinex.v1.dto.marketdata.BitfinexTicker) Ticker(org.knowm.xchange.dto.marketdata.Ticker) BigDecimal(java.math.BigDecimal) Date(java.util.Date)

Example 4 with BitfinexTicker

use of org.knowm.xchange.bitfinex.v1.dto.marketdata.BitfinexTicker in project XChange by knowm.

the class BitfinexWebSocketTickerTransaction method toBitfinexTicker.

public BitfinexTicker toBitfinexTicker() {
    BigDecimal bid = new BigDecimal(tickerArr[0]);
    BigDecimal bidSize = new BigDecimal(tickerArr[1]);
    BigDecimal ask = new BigDecimal(tickerArr[2]);
    BigDecimal askSize = new BigDecimal(tickerArr[3]);
    BigDecimal mid = ask.subtract(bid);
    BigDecimal low = new BigDecimal(tickerArr[9]);
    BigDecimal high = new BigDecimal(tickerArr[8]);
    BigDecimal last = new BigDecimal(tickerArr[6]);
    // Xchange-bitfinex adapter expects the timestamp to be seconds since Epoch.
    double timestamp = System.currentTimeMillis() / 1000;
    BigDecimal volume = new BigDecimal(tickerArr[7]);
    return new BitfinexTicker(mid, bid, bidSize, ask, askSize, low, high, last, timestamp, volume);
}
Also used : BitfinexTicker(org.knowm.xchange.bitfinex.v1.dto.marketdata.BitfinexTicker) BigDecimal(java.math.BigDecimal)

Aggregations

BitfinexTicker (org.knowm.xchange.bitfinex.v1.dto.marketdata.BitfinexTicker)4 BigDecimal (java.math.BigDecimal)3 Ticker (org.knowm.xchange.dto.marketdata.Ticker)2 MathContext (java.math.MathContext)1 Date (java.util.Date)1 CurrencyPair (org.knowm.xchange.currency.CurrencyPair)1