use of org.knowm.xchange.dto.marketdata.OrderBook in project XChange by knowm.
the class GateioMarketDataDemo method generic.
private static void generic(MarketDataService marketDataService) throws IOException {
Ticker ticker = marketDataService.getTicker(CurrencyPair.BTC_USDT);
System.out.println(ticker);
OrderBook oderBook = marketDataService.getOrderBook(CurrencyPair.BTC_USDT);
System.out.println(oderBook);
Trades tradeHistory = marketDataService.getTrades(CurrencyPair.BTC_USDT);
System.out.println(tradeHistory);
List<Trade> trades = tradeHistory.getTrades();
if (trades.size() > 1) {
Trade trade = trades.get(trades.size() - 2);
tradeHistory = marketDataService.getTrades(CurrencyPair.BTC_USDT, Long.valueOf(trade.getId()));
System.out.println(tradeHistory);
}
}
use of org.knowm.xchange.dto.marketdata.OrderBook in project XChange by knowm.
the class ItBitOrderBookDemo method generic.
private static void generic(MarketDataService marketDataService) throws IOException {
OrderBook orderBook = marketDataService.getOrderBook(CurrencyPair.BTC_USD);
System.out.println(orderBook.toString());
OrderBook orderBookAsXBT = marketDataService.getOrderBook(new CurrencyPair(Currency.XBT, Currency.USD));
System.out.println(orderBookAsXBT.toString());
}
use of org.knowm.xchange.dto.marketdata.OrderBook in project XChange by knowm.
the class CoinbeneMarketDataDemo method generic.
private static void generic(MarketDataService marketDataService) throws IOException {
Ticker ticker = marketDataService.getTicker(CurrencyPair.BTC_USDT);
System.out.println("BTC / USDT Ticker: " + ticker.toString());
// Get the latest order book data for BTC/USD
OrderBook orderBook = marketDataService.getOrderBook(CurrencyPair.BTC_USDT);
System.out.println("Current Order Book size for BTC/USD: " + (orderBook.getAsks().size() + orderBook.getBids().size()));
System.out.println("First Ask: " + orderBook.getAsks().get(0).toString());
System.out.println("First Bid: " + orderBook.getBids().get(0).toString());
System.out.println(orderBook.toString());
// Get the latest trade data for BTC/USD
Trades trades = marketDataService.getTrades(CurrencyPair.BTC_USDT);
System.out.println("Trades, default. Size=" + trades.getTrades().size());
}
use of org.knowm.xchange.dto.marketdata.OrderBook in project XChange by knowm.
the class CoingiPublicOrderBookDemo method main.
public static void main(String[] args) throws IOException {
Exchange coingi = CoingiDemoUtils.createExchange();
MarketDataService marketDataService = coingi.getMarketDataService();
OrderBook orderBook = marketDataService.getOrderBook(CurrencyPair.BTC_EUR);
// The following example limits max asks to 10, max bids to 10, and market depth to 32
// OrderBook orderBook = marketDataService.getOrderBook(CurrencyPair.BTC_EUR, 10, 10, 32);
List<LimitOrder> asks = orderBook.getAsks();
List<LimitOrder> bids = orderBook.getBids();
asks.forEach(System.out::println);
bids.forEach(System.out::println);
System.out.printf("Received an order book with the latest %d asks and %d bids.\n", asks.size(), bids.size());
}
use of org.knowm.xchange.dto.marketdata.OrderBook in project XChange by knowm.
the class OkCoinAdaptersTest method testAdaptOrderBook.
@Test
public void testAdaptOrderBook() {
BigDecimal ask1Price = new BigDecimal("8");
BigDecimal ask1Amount = new BigDecimal("28");
BigDecimal ask2Price = new BigDecimal("5");
BigDecimal ask2Amount = new BigDecimal("20");
BigDecimal ask3Price = new BigDecimal("7");
BigDecimal ask3Amount = new BigDecimal("24");
BigDecimal bid1Price = new BigDecimal("4");
BigDecimal bid1Amount = new BigDecimal("35");
BigDecimal bid2Price = new BigDecimal("2");
BigDecimal bid2Amount = new BigDecimal("45");
BigDecimal[][] asks = { { ask1Price, ask1Amount }, { ask2Price, ask2Amount }, { ask3Price, ask3Amount } };
BigDecimal[][] bids = { { bid1Price, bid1Amount }, { bid2Price, bid2Amount } };
Date date = new Date();
OkCoinDepth depth = new OkCoinDepth(asks, bids, date);
OrderBook orderBook = OkCoinAdapters.adaptOrderBook(depth, CurrencyPair.ETH_BTC);
Assert.assertEquals(orderBook.getAsks().size(), asks.length);
Assert.assertTrue(orderBook.getAsks().contains(new LimitOrder(Order.OrderType.ASK, ask1Amount, CurrencyPair.ETH_BTC, null, date, ask1Price)));
Assert.assertTrue(orderBook.getAsks().contains(new LimitOrder(Order.OrderType.ASK, ask2Amount, CurrencyPair.ETH_BTC, null, date, ask2Price)));
Assert.assertTrue(orderBook.getAsks().contains(new LimitOrder(Order.OrderType.ASK, ask3Amount, CurrencyPair.ETH_BTC, null, date, ask3Price)));
Assert.assertTrue(orderBook.getAsks().stream().sorted().collect(Collectors.toList()).equals(orderBook.getAsks()));
Assert.assertEquals(orderBook.getBids().size(), bids.length);
Assert.assertTrue(orderBook.getBids().contains(new LimitOrder(Order.OrderType.BID, bid1Amount, CurrencyPair.ETH_BTC, null, date, bid1Price)));
Assert.assertTrue(orderBook.getBids().contains(new LimitOrder(Order.OrderType.BID, bid2Amount, CurrencyPair.ETH_BTC, null, date, bid2Price)));
Assert.assertTrue(orderBook.getBids().stream().sorted().collect(Collectors.toList()).equals(orderBook.getBids()));
}
Aggregations