Search in sources :

Example 1 with BitmexPrivateOrder

use of org.knowm.xchange.bitmex.dto.marketdata.BitmexPrivateOrder 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 BitmexPrivateOrder

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

the class BitmexOrderIT method shouldReplaceOrder.

@Test
public void shouldReplaceOrder() throws Exception {
    final String clOrdId = generateOrderId();
    String orderId = placeLimitOrder(clOrdId, testAskPrice, "10", Order.OrderType.ASK);
    final String replaceId = clOrdId + "replace";
    BitmexReplaceOrderParameters params = new BitmexReplaceOrderParameters.Builder().setOrderQuantity(new BigDecimal("5")).setOrderId(orderId).setOrigClOrdId(clOrdId).setClOrdId(replaceId).build();
    BitmexPrivateOrder bitmexPrivateOrder = tradeService.replaceOrder(params);
    LOG.info("Order was replaced = {}", bitmexPrivateOrder);
    checkPrivateOrder(orderId, testAskPrice, "5", BitmexSide.SELL, bitmexPrivateOrder);
    cancelLimitOrder(replaceId);
}
Also used : BitmexPrivateOrder(org.knowm.xchange.bitmex.dto.marketdata.BitmexPrivateOrder) BitmexReplaceOrderParameters(org.knowm.xchange.bitmex.dto.trade.BitmexReplaceOrderParameters) BigDecimal(java.math.BigDecimal) Test(org.junit.Test)

Example 3 with BitmexPrivateOrder

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

the class BitmexOrderIT method shouldCancelOrder.

@Test
public void shouldCancelOrder() throws Exception {
    final String clOrdId = generateOrderId();
    String orderId = placeLimitOrder(clOrdId, testAskPrice, "10", Order.OrderType.ASK);
    BitmexPrivateOrder bitmexPrivateOrder = cancelLimitOrder(clOrdId);
    checkPrivateOrder(orderId, testAskPrice, "10", BitmexSide.SELL, bitmexPrivateOrder);
}
Also used : BitmexPrivateOrder(org.knowm.xchange.bitmex.dto.marketdata.BitmexPrivateOrder) Test(org.junit.Test)

Example 4 with BitmexPrivateOrder

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

the class BitmexOrderIT method shouldFillPlacedOrder.

@Test
public void shouldFillPlacedOrder() throws Exception {
    final String clOrdId = generateOrderId();
    String orderId = placeLimitOrder(clOrdId, testBidPrice.add(priceShift.multiply(new BigDecimal("2"))), "10", Order.OrderType.BID);
    Assert.assertNotNull(orderId);
    List<BitmexPrivateOrder> bitmexPrivateOrders = tradeService.cancelBitmexOrder(null, clOrdId);
    Assert.assertEquals(1, bitmexPrivateOrders.size());
    BitmexPrivateOrder order = bitmexPrivateOrders.get(0);
    Assert.assertEquals(BitmexPrivateOrder.OrderStatus.Filled, order.getOrderStatus());
}
Also used : BitmexPrivateOrder(org.knowm.xchange.bitmex.dto.marketdata.BitmexPrivateOrder) BigDecimal(java.math.BigDecimal) Test(org.junit.Test)

Example 5 with BitmexPrivateOrder

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

the class BitmexOrderIT method cancelLimitOrder.

private BitmexPrivateOrder cancelLimitOrder(String clOrdId) {
    List<BitmexPrivateOrder> bitmexPrivateOrders = tradeService.cancelBitmexOrder(null, clOrdId);
    Assert.assertEquals(1, bitmexPrivateOrders.size());
    BitmexPrivateOrder order = bitmexPrivateOrders.get(0);
    Assert.assertEquals(BitmexPrivateOrder.OrderStatus.Canceled, order.getOrderStatus());
    LOG.info("Order was cancelled = {}", order);
    return order;
}
Also used : BitmexPrivateOrder(org.knowm.xchange.bitmex.dto.marketdata.BitmexPrivateOrder)

Aggregations

BitmexPrivateOrder (org.knowm.xchange.bitmex.dto.marketdata.BitmexPrivateOrder)6 Test (org.junit.Test)5 BigDecimal (java.math.BigDecimal)4 Ignore (org.junit.Ignore)2 ExchangeSpecification (org.knowm.xchange.ExchangeSpecification)2 BitmexReplaceOrderParameters (org.knowm.xchange.bitmex.dto.trade.BitmexReplaceOrderParameters)2 BitmexMarketDataService (org.knowm.xchange.bitmex.service.BitmexMarketDataService)2 BitmexTradeService (org.knowm.xchange.bitmex.service.BitmexTradeService)2 OrderBook (org.knowm.xchange.dto.marketdata.OrderBook)2 ArrayList (java.util.ArrayList)1 BitmexExchange (org.knowm.xchange.bitmex.BitmexExchange)1 BitmexPlaceOrderParameters (org.knowm.xchange.bitmex.dto.trade.BitmexPlaceOrderParameters)1 PlaceOrderCommand (org.knowm.xchange.bitmex.dto.trade.PlaceOrderCommand)1 CurrencyPair (org.knowm.xchange.currency.CurrencyPair)1 LimitOrder (org.knowm.xchange.dto.trade.LimitOrder)1