Search in sources :

Example 1 with ExchangeSpecification

use of org.knowm.xchange.ExchangeSpecification 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 ExchangeSpecification

use of org.knowm.xchange.ExchangeSpecification 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 ExchangeSpecification

use of org.knowm.xchange.ExchangeSpecification in project XChange by knowm.

the class BitsoExchange method getDefaultExchangeSpecification.

@Override
public ExchangeSpecification getDefaultExchangeSpecification() {
    ExchangeSpecification exchangeSpecification = new ExchangeSpecification(this.getClass());
    exchangeSpecification.setSslUri("https://api.bitso.com");
    exchangeSpecification.setHost("bitso.com");
    exchangeSpecification.setPort(80);
    exchangeSpecification.setExchangeName("Bitso");
    exchangeSpecification.setExchangeDescription("A new hub for trade and remittance of Bitcoin in Mexico.");
    return exchangeSpecification;
}
Also used : ExchangeSpecification(org.knowm.xchange.ExchangeSpecification)

Example 4 with ExchangeSpecification

use of org.knowm.xchange.ExchangeSpecification in project XChange by knowm.

the class BitstampExchange method getDefaultExchangeSpecification.

@Override
public ExchangeSpecification getDefaultExchangeSpecification() {
    ExchangeSpecification exchangeSpecification = new ExchangeSpecification(this.getClass());
    exchangeSpecification.setSslUri("https://www.bitstamp.net");
    exchangeSpecification.setHost("www.bitstamp.net");
    exchangeSpecification.setPort(80);
    exchangeSpecification.setExchangeName("Bitstamp");
    exchangeSpecification.setExchangeDescription("Bitstamp is a Bitcoin exchange registered in Slovenia.");
    return exchangeSpecification;
}
Also used : ExchangeSpecification(org.knowm.xchange.ExchangeSpecification)

Example 5 with ExchangeSpecification

use of org.knowm.xchange.ExchangeSpecification in project XChange by knowm.

the class CoinfloorPlaceMarketOrderIntegration method placeMarketOrderTest.

@Test
public void placeMarketOrderTest() throws IOException {
    final ExchangeSpecification specification = new ExchangeSpecification(CoinfloorExchange.class);
    String username = System.getProperty("xchange.coinfloor.username");
    String password = System.getProperty("xchange.coinfloor.password");
    if (username == null || password == null) {
        return;
    }
    specification.setUserName(username);
    specification.setPassword(password);
    Exchange exchange = ExchangeFactory.INSTANCE.createExchange(specification);
    CoinfloorTradeServiceRaw rawService = (CoinfloorTradeServiceRaw) exchange.getTradeService();
    CoinfloorMarketOrderResponse order = rawService.placeMarketOrder(CurrencyPair.BTC_EUR, OrderType.ASK, new BigDecimal("0.0001"));
    logger.info("placed market order with remainingQty={}", order.getRemaining());
}
Also used : CoinfloorExchange(org.knowm.xchange.coinfloor.CoinfloorExchange) Exchange(org.knowm.xchange.Exchange) ExchangeSpecification(org.knowm.xchange.ExchangeSpecification) CoinfloorMarketOrderResponse(org.knowm.xchange.coinfloor.dto.trade.CoinfloorMarketOrderResponse) BigDecimal(java.math.BigDecimal) Test(org.junit.Test)

Aggregations

ExchangeSpecification (org.knowm.xchange.ExchangeSpecification)327 Exchange (org.knowm.xchange.Exchange)93 Test (org.junit.Test)66 IOException (java.io.IOException)22 MarketDataService (org.knowm.xchange.service.marketdata.MarketDataService)20 StreamingExchange (info.bitrich.xchangestream.core.StreamingExchange)17 BigDecimal (java.math.BigDecimal)16 CurrencyPair (org.knowm.xchange.currency.CurrencyPair)16 Before (org.junit.Before)15 CoinsuperExchange (org.knowm.xchange.coinsuper.CoinsuperExchange)15 TradeService (org.knowm.xchange.service.trade.TradeService)14 Disposable (io.reactivex.disposables.Disposable)12 ProductSubscription (info.bitrich.xchangestream.core.ProductSubscription)11 OrderBook (org.knowm.xchange.dto.marketdata.OrderBook)9 LimitOrder (org.knowm.xchange.dto.trade.LimitOrder)9 Ticker (org.knowm.xchange.dto.marketdata.Ticker)8 OkCoinExchange (org.knowm.xchange.okcoin.OkCoinExchange)7 BitcoiniumExchange (org.knowm.xchange.bitcoinium.BitcoiniumExchange)6 CoinfloorExchange (org.knowm.xchange.coinfloor.CoinfloorExchange)6 DVChainExchange (org.knowm.xchange.dvchain.DVChainExchange)6