Search in sources :

Example 1 with LimitOrder

use of org.knowm.xchange.dto.trade.LimitOrder 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 2 with LimitOrder

use of org.knowm.xchange.dto.trade.LimitOrder 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 3 with LimitOrder

use of org.knowm.xchange.dto.trade.LimitOrder in project XChange by knowm.

the class BitstampTradeService method getOpenOrders.

@Override
public OpenOrders getOpenOrders(OpenOrdersParams params) throws ExchangeException, IOException {
    BitstampOrder[] openOrders = getBitstampOpenOrders();
    List<LimitOrder> limitOrders = new ArrayList<>(openOrders.length);
    for (BitstampOrder bitstampOrder : openOrders) {
        OrderType orderType = bitstampOrder.getType() == 0 ? OrderType.BID : OrderType.ASK;
        String id = Long.toString(bitstampOrder.getId());
        BigDecimal price = bitstampOrder.getPrice();
        limitOrders.add(new LimitOrder(orderType, bitstampOrder.getAmount(), new BitstampV2.Pair(bitstampOrder.getCurrencyPair()).pair, id, bitstampOrder.getDatetime(), price, // avgPrice
        null, // cumAmount
        null, // fee
        null, Order.OrderStatus.NEW));
    }
    return new OpenOrders(limitOrders);
}
Also used : OrderType(org.knowm.xchange.dto.Order.OrderType) BitstampV2(org.knowm.xchange.bitstamp.BitstampV2) BitstampOrder(org.knowm.xchange.bitstamp.dto.trade.BitstampOrder) ArrayList(java.util.ArrayList) LimitOrder(org.knowm.xchange.dto.trade.LimitOrder) OpenOrders(org.knowm.xchange.dto.trade.OpenOrders) BigDecimal(java.math.BigDecimal)

Example 4 with LimitOrder

use of org.knowm.xchange.dto.trade.LimitOrder in project XChange by knowm.

the class CoingiAdapters method adaptOpenOrders.

public static OpenOrders adaptOpenOrders(CoingiOrdersList orders) {
    List<LimitOrder> list = new ArrayList<>();
    for (CoingiOrder order : orders) {
        LimitOrder limitOrder = new LimitOrder(order.getType() == 0 ? OrderType.BID : OrderType.ASK, order.getOriginalBaseAmount(), adaptCurrency(order.getCurrencyPair()), order.getId(), new Date(order.getTimestamp()), order.getPrice());
        limitOrder.setOrderStatus(adaptOrderStatus(order.getStatus()));
        list.add(limitOrder);
    }
    return new OpenOrders(list);
}
Also used : ArrayList(java.util.ArrayList) CoingiOrder(org.knowm.xchange.coingi.dto.trade.CoingiOrder) LimitOrder(org.knowm.xchange.dto.trade.LimitOrder) OpenOrders(org.knowm.xchange.dto.trade.OpenOrders) Date(java.util.Date)

Example 5 with LimitOrder

use of org.knowm.xchange.dto.trade.LimitOrder in project XChange by knowm.

the class CoinfloorCancelOrderIntegration method cancelOpenOrdersTest.

@Test
public void cancelOpenOrdersTest() 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);
    TradeService service = exchange.getTradeService();
    // fetch open orders
    CoinfloorOpenOrdersParams params = (CoinfloorOpenOrdersParams) service.createOpenOrdersParams();
    OpenOrders openOrders = service.getOpenOrders(params);
    // cancel one order
    if (openOrders.getOpenOrders().size() > 0) {
        LimitOrder order = openOrders.getOpenOrders().iterator().next();
        boolean success = service.cancelOrder(order.getId());
        logger.info("cancel of order={} success={}", order, success);
    }
}
Also used : CoinfloorExchange(org.knowm.xchange.coinfloor.CoinfloorExchange) Exchange(org.knowm.xchange.Exchange) TradeService(org.knowm.xchange.service.trade.TradeService) ExchangeSpecification(org.knowm.xchange.ExchangeSpecification) OpenOrders(org.knowm.xchange.dto.trade.OpenOrders) LimitOrder(org.knowm.xchange.dto.trade.LimitOrder) Test(org.junit.Test)

Aggregations

LimitOrder (org.knowm.xchange.dto.trade.LimitOrder)337 BigDecimal (java.math.BigDecimal)188 Test (org.junit.Test)122 Date (java.util.Date)110 ArrayList (java.util.ArrayList)95 CurrencyPair (org.knowm.xchange.currency.CurrencyPair)90 OrderBook (org.knowm.xchange.dto.marketdata.OrderBook)89 OpenOrders (org.knowm.xchange.dto.trade.OpenOrders)77 Order (org.knowm.xchange.dto.Order)50 OrderType (org.knowm.xchange.dto.Order.OrderType)39 Exchange (org.knowm.xchange.Exchange)31 MarketOrder (org.knowm.xchange.dto.trade.MarketOrder)29 List (java.util.List)28 TradeService (org.knowm.xchange.service.trade.TradeService)28 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)23 IOException (java.io.IOException)20 Collectors (java.util.stream.Collectors)20 MarketDataService (org.knowm.xchange.service.marketdata.MarketDataService)17 InputStream (java.io.InputStream)15 DefaultOpenOrdersParamCurrencyPair (org.knowm.xchange.service.trade.params.orders.DefaultOpenOrdersParamCurrencyPair)15