Search in sources :

Example 1 with BitfinexDepth

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

the class BitfinexOrderbookTest method timestampShouldBeInSeconds.

@Test
public void timestampShouldBeInSeconds() {
    BitfinexDepth depth = new BitfinexOrderbook(new BitfinexOrderbookLevel[] { new BitfinexOrderbookLevel(ONE, ONE, ONE), new BitfinexOrderbookLevel(ONE, ONE, ONE) }).toBitfinexDepth();
    OrderBook orderBook = BitfinexAdapters.adaptOrderBook(depth, BTC_USD);
    // What is the time now... after order books created?
    assertThat("The timestamp should be a value less than now, but was: " + orderBook.getTimeStamp(), !orderBook.getTimeStamp().after(new Date()));
}
Also used : OrderBook(org.knowm.xchange.dto.marketdata.OrderBook) BitfinexDepth(org.knowm.xchange.bitfinex.v1.dto.marketdata.BitfinexDepth) Date(java.util.Date) Test(org.junit.Test)

Example 2 with BitfinexDepth

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

the class BitfinexMarketDataService method getOrderBook.

/**
 * @param args If two integers are provided, then those count as limit bid and limit ask count
 */
@Override
public OrderBook getOrderBook(CurrencyPair currencyPair, Object... args) throws IOException {
    try {
        // null will cause fetching of full order book, the default behavior in XChange
        Integer limitBids = null;
        Integer limitAsks = null;
        if (args != null && args.length == 2) {
            Object arg0 = args[0];
            if (!(arg0 instanceof Integer)) {
                throw new ExchangeException("Argument 0 must be an Integer!");
            } else {
                limitBids = (Integer) arg0;
            }
            Object arg1 = args[1];
            if (!(arg1 instanceof Integer)) {
                throw new ExchangeException("Argument 1 must be an Integer!");
            } else {
                limitAsks = (Integer) arg1;
            }
        }
        BitfinexDepth bitfinexDepth = getBitfinexOrderBook(BitfinexUtils.toPairStringV1(currencyPair), limitBids, limitAsks);
        OrderBook orderBook = BitfinexAdapters.adaptOrderBook(bitfinexDepth, currencyPair);
        return orderBook;
    } catch (BitfinexException e) {
        throw BitfinexErrorAdapter.adapt(e);
    }
}
Also used : OrderBook(org.knowm.xchange.dto.marketdata.OrderBook) LoanOrderBook(org.knowm.xchange.dto.marketdata.LoanOrderBook) BitfinexDepth(org.knowm.xchange.bitfinex.v1.dto.marketdata.BitfinexDepth) ExchangeException(org.knowm.xchange.exceptions.ExchangeException) BitfinexException(org.knowm.xchange.bitfinex.dto.BitfinexException)

Example 3 with BitfinexDepth

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

the class LendDepthDemo method raw.

private static void raw(BitfinexMarketDataServiceRaw marketDataService) throws IOException {
    // Get the latest order book data for USD swaps
    BitfinexLendDepth bitfinexDepth = marketDataService.getBitfinexLendBook("USD", 50, 50);
    System.out.println("Current Order Book size for USD: " + (bitfinexDepth.getAsks().length + bitfinexDepth.getBids().length));
    System.out.println("First Ask: " + bitfinexDepth.getAsks()[0].toString());
    System.out.println("First Bid: " + bitfinexDepth.getBids()[0].toString());
    System.out.println(bitfinexDepth.toString());
}
Also used : BitfinexLendDepth(org.knowm.xchange.bitfinex.v1.dto.marketdata.BitfinexLendDepth)

Example 4 with BitfinexDepth

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

the class BitfinexDepthDemo method raw.

private static void raw(BitfinexMarketDataServiceRaw marketDataService) throws IOException {
    // Get the latest order book data for BTC/CAD
    BitfinexDepth bitfinexDepth = marketDataService.getBitfinexOrderBook("btcusd", 50, 50);
    System.out.println("Current Order Book size for BTC / USD: " + (bitfinexDepth.getAsks().length + bitfinexDepth.getBids().length));
    System.out.println("First Ask: " + bitfinexDepth.getAsks()[0].toString());
    System.out.println("First Bid: " + bitfinexDepth.getBids()[0].toString());
    System.out.println(bitfinexDepth.toString());
}
Also used : BitfinexDepth(org.knowm.xchange.bitfinex.v1.dto.marketdata.BitfinexDepth)

Aggregations

BitfinexDepth (org.knowm.xchange.bitfinex.v1.dto.marketdata.BitfinexDepth)3 OrderBook (org.knowm.xchange.dto.marketdata.OrderBook)2 Date (java.util.Date)1 Test (org.junit.Test)1 BitfinexException (org.knowm.xchange.bitfinex.dto.BitfinexException)1 BitfinexLendDepth (org.knowm.xchange.bitfinex.v1.dto.marketdata.BitfinexLendDepth)1 LoanOrderBook (org.knowm.xchange.dto.marketdata.LoanOrderBook)1 ExchangeException (org.knowm.xchange.exceptions.ExchangeException)1