Search in sources :

Example 1 with BitmexMarketDataService

use of org.knowm.xchange.bitmex.service.BitmexMarketDataService 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 BitmexMarketDataService

use of org.knowm.xchange.bitmex.service.BitmexMarketDataService 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 BitmexMarketDataService

use of org.knowm.xchange.bitmex.service.BitmexMarketDataService in project XChange by knowm.

the class BitmexDeadManSwitchTest method testDeadmanSwitch.

@Test
@Ignore
public void testDeadmanSwitch() throws Exception {
    CertHelper.trustAllCerts();
    BitmexStreamingExchange exchange = (BitmexStreamingExchange) ExchangeFactory.INSTANCE.createExchange(BitmexStreamingExchange.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);
    // 
    // defaultExchangeSpecification.setExchangeSpecificParametersItem(StreamingExchange.SOCKS_PROXY_HOST, "localhost");
    // 
    // defaultExchangeSpecification.setExchangeSpecificParametersItem(StreamingExchange.SOCKS_PROXY_PORT, 8889);
    defaultExchangeSpecification.setExchangeSpecificParametersItem(StreamingExchange.USE_SANDBOX, true);
    defaultExchangeSpecification.setExchangeSpecificParametersItem(StreamingExchange.ACCEPT_ALL_CERITICATES, true);
    // 
    // defaultExchangeSpecification.setExchangeSpecificParametersItem(StreamingExchange.ENABLE_LOGGING_HANDLER, true);
    exchange.applySpecification(defaultExchangeSpecification);
    exchange.connect().blockingAwait();
    BitmexMarketDataService marketDataService = (BitmexMarketDataService) exchange.getMarketDataService();
    BitmexTradeService tradeService = (BitmexTradeService) exchange.getTradeService();
    final BitmexStreamingMarketDataService streamingMarketDataService = (BitmexStreamingMarketDataService) exchange.getStreamingMarketDataService();
    // streamingMarketDataService.authenticate();
    CurrencyPair xbtUsd = exchange.determineActiveContract(CurrencyPair.XBT_USD.base.toString(), CurrencyPair.XBT_USD.counter.toString(), PERPETUAL);
    streamingMarketDataService.getRawExecutions("XBTUSD").subscribe(bitmexExecution -> {
        logger.info("!!!!EXECUTION!!!! = {}", bitmexExecution);
    });
    OrderBook orderBook = marketDataService.getOrderBook(xbtUsd);
    // 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);
    streamingMarketDataService.enableDeadManSwitch(10000, 30000);
    String nosOrdId = System.currentTimeMillis() + "";
    BigDecimal originalOrderSize = new BigDecimal("300");
    // BigDecimal price = new BigDecimal("10000");
    BigDecimal price = orderBook.getBids().get(0).getLimitPrice().add(new BigDecimal("100"));
    LimitOrder limitOrder = new LimitOrder.Builder(Order.OrderType.ASK, CurrencyPair.XBT_USD).originalAmount(originalOrderSize).limitPrice(price).id(nosOrdId).build();
    String xbtusd = tradeService.placeLimitOrder(limitOrder);
    logger.info("!!!!!PRIVATE_ORDER!!!! {}", xbtusd);
    Thread.sleep(100000);
    System.out.println();
    System.out.println();
    exchange.disconnect();
}
Also used : BitmexMarketDataService(org.knowm.xchange.bitmex.service.BitmexMarketDataService) OrderBook(org.knowm.xchange.dto.marketdata.OrderBook) BitmexTradeService(org.knowm.xchange.bitmex.service.BitmexTradeService) ExchangeSpecification(org.knowm.xchange.ExchangeSpecification) LimitOrder(org.knowm.xchange.dto.trade.LimitOrder) BigDecimal(java.math.BigDecimal) CurrencyPair(org.knowm.xchange.currency.CurrencyPair) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 4 with BitmexMarketDataService

use of org.knowm.xchange.bitmex.service.BitmexMarketDataService in project XChange by knowm.

the class BitmexOrderIT method setup.

@Before
public void setup() throws IOException {
    LocalExchangeConfig localConfig = PropsLoader.loadKeys("bitmex.secret.keys", "bitmex.secret.keys.origin", "bitmex");
    exchange = (BitmexStreamingExchange) StreamingExchangeFactory.INSTANCE.createExchange(BitmexStreamingExchange.class);
    exchange.applySpecification(BitmexTestsCommons.getExchangeSpecification(localConfig, exchange.getDefaultExchangeSpecification()));
    exchange.connect().blockingAwait();
    xbtUsd = exchange.determineActiveContract(CurrencyPair.XBT_USD.base.toString(), CurrencyPair.XBT_USD.counter.toString(), PERPETUAL);
    BitmexMarketDataService marketDataService = (BitmexMarketDataService) exchange.getMarketDataService();
    OrderBook orderBook = marketDataService.getOrderBook(xbtUsd);
    List<LimitOrder> asks = orderBook.getAsks();
    // todo : for the streaming service best ask is at 0 pos
    BigDecimal topPriceAsk = getPrice(asks, asks.size() - 1);
    BigDecimal topPriceBid = getPrice(orderBook.getBids(), 0);
    LOG.info("Got best ask = {}, best bid = {}", topPriceAsk, topPriceBid);
    Assert.assertTrue("Got empty order book", topPriceAsk != null || topPriceBid != null);
    testAskPrice = topPriceAsk;
    testBidPrice = topPriceBid;
    tradeService = (BitmexTradeService) exchange.getTradeService();
}
Also used : BitmexMarketDataService(org.knowm.xchange.bitmex.service.BitmexMarketDataService) OrderBook(org.knowm.xchange.dto.marketdata.OrderBook) LocalExchangeConfig(info.bitrich.xchangestream.util.LocalExchangeConfig) LimitOrder(org.knowm.xchange.dto.trade.LimitOrder) BigDecimal(java.math.BigDecimal) Before(org.junit.Before)

Example 5 with BitmexMarketDataService

use of org.knowm.xchange.bitmex.service.BitmexMarketDataService in project XChange by knowm.

the class BitmexExchange method initServices.

@Override
protected void initServices() {
    concludeHostParams(exchangeSpecification);
    this.marketDataService = new BitmexMarketDataService(this);
    this.accountService = new BitmexAccountService(this);
    this.tradeService = new BitmexTradeService(this);
}
Also used : BitmexMarketDataService(org.knowm.xchange.bitmex.service.BitmexMarketDataService) BitmexTradeService(org.knowm.xchange.bitmex.service.BitmexTradeService) BitmexAccountService(org.knowm.xchange.bitmex.service.BitmexAccountService)

Aggregations

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