Search in sources :

Example 21 with OrderBook

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);
    }
}
Also used : GateioPublicTrade(org.knowm.xchange.gateio.dto.marketdata.GateioTradeHistory.GateioPublicTrade) Trade(org.knowm.xchange.dto.marketdata.Trade) Trades(org.knowm.xchange.dto.marketdata.Trades) OrderBook(org.knowm.xchange.dto.marketdata.OrderBook) Ticker(org.knowm.xchange.dto.marketdata.Ticker) GateioTicker(org.knowm.xchange.gateio.dto.marketdata.GateioTicker)

Example 22 with OrderBook

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());
}
Also used : OrderBook(org.knowm.xchange.dto.marketdata.OrderBook) CurrencyPair(org.knowm.xchange.currency.CurrencyPair)

Example 23 with OrderBook

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());
}
Also used : Trades(org.knowm.xchange.dto.marketdata.Trades) CoinbeneOrderBook(org.knowm.xchange.coinbene.dto.marketdata.CoinbeneOrderBook) OrderBook(org.knowm.xchange.dto.marketdata.OrderBook) Ticker(org.knowm.xchange.dto.marketdata.Ticker) CoinbeneTicker(org.knowm.xchange.coinbene.dto.marketdata.CoinbeneTicker)

Example 24 with OrderBook

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());
}
Also used : Exchange(org.knowm.xchange.Exchange) OrderBook(org.knowm.xchange.dto.marketdata.OrderBook) MarketDataService(org.knowm.xchange.service.marketdata.MarketDataService) LimitOrder(org.knowm.xchange.dto.trade.LimitOrder)

Example 25 with OrderBook

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()));
}
Also used : OkCoinDepth(org.knowm.xchange.okcoin.dto.marketdata.OkCoinDepth) OrderBook(org.knowm.xchange.dto.marketdata.OrderBook) LimitOrder(org.knowm.xchange.dto.trade.LimitOrder) BigDecimal(java.math.BigDecimal) Date(java.util.Date) Test(org.junit.Test)

Aggregations

OrderBook (org.knowm.xchange.dto.marketdata.OrderBook)193 Test (org.junit.Test)88 LimitOrder (org.knowm.xchange.dto.trade.LimitOrder)87 BigDecimal (java.math.BigDecimal)53 MarketDataService (org.knowm.xchange.service.marketdata.MarketDataService)44 Date (java.util.Date)43 CurrencyPair (org.knowm.xchange.currency.CurrencyPair)42 ArrayList (java.util.ArrayList)36 Exchange (org.knowm.xchange.Exchange)34 Ticker (org.knowm.xchange.dto.marketdata.Ticker)32 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)25 InputStream (java.io.InputStream)19 Trades (org.knowm.xchange.dto.marketdata.Trades)18 Trade (org.knowm.xchange.dto.marketdata.Trade)15 List (java.util.List)13 JsonNode (com.fasterxml.jackson.databind.JsonNode)11 Collectors (java.util.stream.Collectors)10 ExchangeSpecification (org.knowm.xchange.ExchangeSpecification)10 IOException (java.io.IOException)9 Order (org.knowm.xchange.dto.Order)9