Search in sources :

Example 1 with OrderBook

use of org.knowm.xchange.dto.marketdata.OrderBook in project XChange by knowm.

the class BitmexBulkOrderTest method testOrderReplace.

@Test
@Ignore
public void testOrderReplace() throws Exception {
    CertHelper.trustAllCerts();
    BitmexExchange exchange = (BitmexExchange) ExchangeFactory.INSTANCE.createExchange(BitmexExchange.class);
    ExchangeSpecification defaultExchangeSpecification = exchange.getDefaultExchangeSpecification();
    defaultExchangeSpecification.setExchangeSpecificParametersItem("Use_Sandbox", true);
    defaultExchangeSpecification.setApiKey("QW8Ao_gx38e-8KFvDkFn-Ym4");
    defaultExchangeSpecification.setSecretKey("tn7rpzvOXSKThZD0f-xXehtydt4OTHZVf42gCCyxPixiiVOb");
    defaultExchangeSpecification.setShouldLoadRemoteMetaData(true);
    defaultExchangeSpecification.setProxyHost("localhost");
    defaultExchangeSpecification.setProxyPort(9999);
    exchange.applySpecification(defaultExchangeSpecification);
    BitmexMarketDataService marketDataService = (BitmexMarketDataService) exchange.getMarketDataService();
    OrderBook orderBook = marketDataService.getOrderBook(XBT_USD, PERPETUAL);
    // OrderBook orderBook = marketDataService.getOrderBook(new CurrencyPair(Currency.ADA,
    // Currency.BTC), BitmexPrompt.QUARTERLY);
    // OrderBook orderBook = marketDataService.getOrderBook(new CurrencyPair(Currency.BTC,
    // Currency.USD), BitmexPrompt.BIQUARTERLY);
    System.out.println("orderBook = " + orderBook);
    BitmexTradeService tradeService = (BitmexTradeService) exchange.getTradeService();
    String nosOrdId = System.currentTimeMillis() + "";
    BigDecimal originalOrderSize = new BigDecimal("30");
    // BigDecimal price = new BigDecimal("10000");
    BigDecimal price = orderBook.getBids().get(0).getLimitPrice().add(new BigDecimal("0.5"));
    // LimitOrder limitOrder =
    // new LimitOrder(
    // Order.OrderType.ASK,
    // originalOrderSize,
    // XBT_USD,
    // nosOrdId,
    // new Date(),
    // price);
    List<PlaceOrderCommand> commands = new ArrayList<>();
    commands.add(new PlaceOrderCommand(new BitmexPlaceOrderParameters.Builder(SYMBOL).setSide(BitmexSide.SELL).setOrderQuantity(originalOrderSize).setPrice(price).setClOrdId(nosOrdId).build()));
    List<BitmexPrivateOrder> bitmexPrivateOrders = tradeService.placeOrderBulk(commands);
    for (BitmexPrivateOrder bitmexPrivateOrder : bitmexPrivateOrders) {
    }
    Thread.sleep(5000);
    // BitmexPrivateOrder bitmexPrivateOrder =
    // tradeService.replaceLimitOrder(
    // "XBTUSD",
    // originalOrderSize.divide(new BigDecimal("2")),
    // null,
    // orderId,
    // //            null, null,
    // nosOrdId + "replace",
    // nosOrdId);
    // System.out.println("bitmexPrivateOrder = " + bitmexPrivateOrder);
    tradeService.cancelAllOrders();
// System.out.println("cancelled = " + bitmexPrivateOrders.get(0));
// service.getTicker(Currency.XBT.getSymbol());
}
Also used : OrderBook(org.knowm.xchange.dto.marketdata.OrderBook) ArrayList(java.util.ArrayList) BigDecimal(java.math.BigDecimal) PlaceOrderCommand(org.knowm.xchange.bitmex.dto.trade.PlaceOrderCommand) BitmexMarketDataService(org.knowm.xchange.bitmex.service.BitmexMarketDataService) BitmexPlaceOrderParameters(org.knowm.xchange.bitmex.dto.trade.BitmexPlaceOrderParameters) BitmexPrivateOrder(org.knowm.xchange.bitmex.dto.marketdata.BitmexPrivateOrder) BitmexTradeService(org.knowm.xchange.bitmex.service.BitmexTradeService) BitmexExchange(org.knowm.xchange.bitmex.BitmexExchange) ExchangeSpecification(org.knowm.xchange.ExchangeSpecification) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 2 with OrderBook

use of org.knowm.xchange.dto.marketdata.OrderBook in project XChange by knowm.

the class BitmexOrderReplaceTest method testOrderReplace.

@Test
@Ignore
public void testOrderReplace() throws Exception {
    CertHelper.trustAllCerts();
    BitmexExchange exchange = (BitmexExchange) ExchangeFactory.INSTANCE.createExchange(BitmexExchange.class);
    ExchangeSpecification defaultExchangeSpecification = exchange.getDefaultExchangeSpecification();
    defaultExchangeSpecification.setExchangeSpecificParametersItem("Use_Sandbox", true);
    defaultExchangeSpecification.setApiKey("QW8Ao_gx38e-8KFvDkFn-Ym4");
    defaultExchangeSpecification.setSecretKey("tn7rpzvOXSKThZD0f-xXehtydt4OTHZVf42gCCyxPixiiVOb");
    defaultExchangeSpecification.setShouldLoadRemoteMetaData(true);
    defaultExchangeSpecification.setProxyHost("localhost");
    defaultExchangeSpecification.setProxyPort(9999);
    exchange.applySpecification(defaultExchangeSpecification);
    BitmexMarketDataService marketDataService = (BitmexMarketDataService) exchange.getMarketDataService();
    OrderBook orderBook = marketDataService.getOrderBook(CurrencyPair.XBT_USD, PERPETUAL);
    // OrderBook orderBook = marketDataService.getOrderBook(new CurrencyPair(Currency.ADA,
    // Currency.BTC), BitmexPrompt.QUARTERLY);
    // OrderBook orderBook = marketDataService.getOrderBook(new CurrencyPair(Currency.BTC,
    // Currency.USD), BitmexPrompt.BIQUARTERLY);
    System.out.println("orderBook = " + orderBook);
    BitmexTradeService tradeService = (BitmexTradeService) exchange.getTradeService();
    String nosOrdId = System.currentTimeMillis() + "";
    BigDecimal originalOrderSize = new BigDecimal("30");
    // BigDecimal price = new BigDecimal("10000");
    BigDecimal price = orderBook.getBids().get(0).getLimitPrice().add(new BigDecimal("0.5"));
    LimitOrder limitOrder = new LimitOrder(Order.OrderType.ASK, originalOrderSize, CurrencyPair.XBT_USD, nosOrdId, new Date(), price);
    String orderId = tradeService.placeLimitOrder(limitOrder);
    Thread.sleep(5000);
    // BitmexPrivateOrder bitmexPrivateOrder =
    // tradeService.replaceLimitOrder(
    // "XBTUSD",
    // originalOrderSize.divide(new BigDecimal("2")),
    // null,
    // orderId,
    // //            null, null,
    // nosOrdId + "replace",
    // nosOrdId);
    // System.out.println("bitmexPrivateOrder = " + bitmexPrivateOrder);
    tradeService.cancelAllOrders();
// System.out.println("cancelled = " + bitmexPrivateOrders.get(0));
// service.getTicker(Currency.XBT.getSymbol());
}
Also used : BitmexMarketDataService(org.knowm.xchange.bitmex.service.BitmexMarketDataService) OrderBook(org.knowm.xchange.dto.marketdata.OrderBook) BitmexTradeService(org.knowm.xchange.bitmex.service.BitmexTradeService) BitmexExchange(org.knowm.xchange.bitmex.BitmexExchange) ExchangeSpecification(org.knowm.xchange.ExchangeSpecification) LimitOrder(org.knowm.xchange.dto.trade.LimitOrder) BigDecimal(java.math.BigDecimal) Date(java.util.Date) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 3 with OrderBook

use of org.knowm.xchange.dto.marketdata.OrderBook in project XChange by knowm.

the class BitsoAdapters method adaptOrderBook.

public static OrderBook adaptOrderBook(BitsoOrderBook bitsoOrderBook, CurrencyPair currencyPair, int timeScale) {
    List<LimitOrder> asks = createOrders(currencyPair, Order.OrderType.ASK, bitsoOrderBook.getAsks());
    List<LimitOrder> bids = createOrders(currencyPair, Order.OrderType.BID, bitsoOrderBook.getBids());
    Date date = new Date(bitsoOrderBook.getTimestamp() * // polled order books provide a timestamp in seconds, stream in ms
    timeScale);
    return new OrderBook(date, asks, bids);
}
Also used : BitsoOrderBook(org.knowm.xchange.bitso.dto.marketdata.BitsoOrderBook) OrderBook(org.knowm.xchange.dto.marketdata.OrderBook) LimitOrder(org.knowm.xchange.dto.trade.LimitOrder) Date(java.util.Date)

Example 4 with OrderBook

use of org.knowm.xchange.dto.marketdata.OrderBook in project XChange by knowm.

the class CoinfloorOrderBookIntegration method fetchOrderBookTest.

@Test
public void fetchOrderBookTest() throws IOException {
    Exchange exchange = ExchangeFactory.INSTANCE.createExchange(CoinfloorExchange.class);
    MarketDataService service = exchange.getMarketDataService();
    OrderBook orderBook = service.getOrderBook(CurrencyPair.BTC_GBP);
    assertThat(orderBook.getBids()).isNotEmpty();
    assertThat(orderBook.getAsks()).isNotEmpty();
    LimitOrder order = orderBook.getBids().get(0);
    assertThat(order.getCurrencyPair()).isEqualTo(CurrencyPair.BTC_GBP);
    assertThat(order.getOriginalAmount()).isGreaterThan(BigDecimal.ZERO);
    assertThat(order.getLimitPrice()).isGreaterThan(BigDecimal.ZERO);
}
Also used : CoinfloorExchange(org.knowm.xchange.coinfloor.CoinfloorExchange) 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) Test(org.junit.Test)

Example 5 with OrderBook

use of org.knowm.xchange.dto.marketdata.OrderBook in project XChange by knowm.

the class OkCoinDepthDemo method generic.

private static void generic(Exchange okcoinExchange) throws IOException {
    // Interested in the public market data feed (no authentication)
    MarketDataService marketDataService = okcoinExchange.getMarketDataService();
    // Get the latest full order book data for NMC/XRP
    OrderBook orderBook = marketDataService.getOrderBook(CurrencyPair.BTC_CNY);
    System.out.println(orderBook.toString());
    System.out.println("full orderbook size: " + (orderBook.getAsks().size() + orderBook.getBids().size()));
}
Also used : OrderBook(org.knowm.xchange.dto.marketdata.OrderBook) MarketDataService(org.knowm.xchange.service.marketdata.MarketDataService)

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