Search in sources :

Example 6 with MarketOrder

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

the class DVChainExchangeIntegration method testMarketOrder.

@Test
public void testMarketOrder() {
    final Exchange exchange = ExchangeFactory.INSTANCE.createExchange(DVChainExchange.class, secret, secret);
    ExchangeSpecification exchangeSpecification = exchange.getExchangeSpecification();
    exchangeSpecification.setSslUri("https://sandbox.trade.dvchain.co");
    exchangeSpecification.setHost("sandbox.trade.dvchain.co");
    exchange.applySpecification(exchangeSpecification);
    TradeService tradeService = exchange.getTradeService();
    try {
        String order = tradeService.placeMarketOrder(new MarketOrder(Order.OrderType.BID, new BigDecimal(1), new CurrencyPair("BTC", "USD")));
        assertNotNull(order);
    } catch (Exception exception) {
        System.out.println(exception.getMessage());
        assert (false);
    }
}
Also used : Exchange(org.knowm.xchange.Exchange) DVChainExchange(org.knowm.xchange.dvchain.DVChainExchange) TradeService(org.knowm.xchange.service.trade.TradeService) MarketOrder(org.knowm.xchange.dto.trade.MarketOrder) ExchangeSpecification(org.knowm.xchange.ExchangeSpecification) BigDecimal(java.math.BigDecimal) CurrencyPair(org.knowm.xchange.currency.CurrencyPair) Test(org.junit.Test)

Example 7 with MarketOrder

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

the class HitbtcTradeServiceRawIntegration method testPlaceMarketOrderRaw.

@Test
public void testPlaceMarketOrderRaw() throws IOException {
    Date date = new Date();
    String id = date.toString().replace(" ", "");
    LOGGER.info("Placing order id : " + id);
    exception.expect(HitbtcException.class);
    exception.expectMessage("Insufficient funds");
    MarketOrder limitOrder = new MarketOrder(Order.OrderType.BID, new BigDecimal("0.01"), CurrencyPair.BTC_USD, id, new Date());
    service.placeMarketOrderRaw(limitOrder);
}
Also used : MarketOrder(org.knowm.xchange.dto.trade.MarketOrder) Date(java.util.Date) BigDecimal(java.math.BigDecimal) BaseAuthenticatedServiceTest(org.knowm.xchange.hitbtc.v2.BaseAuthenticatedServiceTest) Test(org.junit.Test)

Example 8 with MarketOrder

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

the class CoinmateAdapters method adaptOrder.

/**
 * Adapt a single order.
 *
 * @param coinmateOrder The raw order
 * @param orderByIdFetcher function to fetch order by id - needed to fetch market orders generated
 *     by stop-loss orders.
 * @return
 */
public static Order adaptOrder(CoinmateOrder coinmateOrder, Function<String, CoinmateOrder> orderByIdFetcher) throws CoinmateException {
    Order.OrderType orderType;
    if ("BUY".equals(coinmateOrder.getType())) {
        orderType = Order.OrderType.BID;
    } else if ("SELL".equals(coinmateOrder.getType())) {
        orderType = Order.OrderType.ASK;
    } else {
        throw new CoinmateException("Unknown order type");
    }
    Order.OrderStatus orderStatus;
    if ("CANCELLED".equals(coinmateOrder.getStatus())) {
        if (coinmateOrder.getStopLossOrderId() != null) {
            // this is a stopped order
            orderStatus = Order.OrderStatus.STOPPED;
        } else {
            orderStatus = Order.OrderStatus.CANCELED;
        }
    } else if ("FILLED".equals(coinmateOrder.getStatus())) {
        orderStatus = Order.OrderStatus.FILLED;
    } else if ("PARTIALLY_FILLED".equals(coinmateOrder.getStatus())) {
        orderStatus = Order.OrderStatus.PARTIALLY_FILLED;
    } else if ("OPEN".equals(coinmateOrder.getStatus())) {
        orderStatus = Order.OrderStatus.NEW;
    } else {
        orderStatus = Order.OrderStatus.UNKNOWN;
    }
    BigDecimal originalAmount;
    BigDecimal remainingAmount;
    BigDecimal averagePrice;
    if (orderStatus == Order.OrderStatus.STOPPED) {
        // fetch generated market order and get its average price and amount
        CoinmateOrder marketOrderRaw = orderByIdFetcher.apply(coinmateOrder.getStopLossOrderId());
        if (marketOrderRaw == null) {
            throw new CoinmateException("Failed to fetch market order generated by stoploss order.");
        }
        averagePrice = marketOrderRaw.getAvgPrice();
        originalAmount = marketOrderRaw.getOriginalAmount();
        remainingAmount = marketOrderRaw.getRemainingAmount();
    } else {
        averagePrice = coinmateOrder.getAvgPrice();
        originalAmount = coinmateOrder.getOriginalAmount();
        remainingAmount = coinmateOrder.getRemainingAmount();
    }
    // TODO: we can probably use `orderTradeType` to distinguish between Market and Limit order
    Order order = new MarketOrder(orderType, originalAmount, null, Long.toString(coinmateOrder.getId()), new Date(coinmateOrder.getTimestamp()), averagePrice, getCumulativeAmount(originalAmount, remainingAmount), null, orderStatus, null);
    return order;
}
Also used : StopOrder(org.knowm.xchange.dto.trade.StopOrder) Order(org.knowm.xchange.dto.Order) CoinmateOrder(org.knowm.xchange.coinmate.dto.trade.CoinmateOrder) LimitOrder(org.knowm.xchange.dto.trade.LimitOrder) MarketOrder(org.knowm.xchange.dto.trade.MarketOrder) CoinmateOrder(org.knowm.xchange.coinmate.dto.trade.CoinmateOrder) MarketOrder(org.knowm.xchange.dto.trade.MarketOrder) BigDecimal(java.math.BigDecimal) Date(java.util.Date)

Example 9 with MarketOrder

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

the class LgoTradeServiceTest method cannotPlaceBidMarketOrderWithAmountToLow.

@Test
public void cannotPlaceBidMarketOrderWithAmountToLow() {
    ThrowingCallable check = () -> tradeService.verifyOrder(new MarketOrder(OrderType.BID, new BigDecimal("0.00001"), CurrencyPair.BTC_USD, new Date()));
    assertThatThrownBy(check).isInstanceOf(IllegalArgumentException.class).hasMessage("Quantity to low");
}
Also used : ThrowingCallable(org.assertj.core.api.ThrowableAssert.ThrowingCallable) MarketOrder(org.knowm.xchange.dto.trade.MarketOrder) BigDecimal(java.math.BigDecimal) Date(java.util.Date) LgoProductsTest(org.knowm.xchange.lgo.dto.product.LgoProductsTest) Test(org.junit.Test)

Example 10 with MarketOrder

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

the class LgoTradeServiceTest method cannotPlaceBidMarketOrderWithAmountToHigh.

@Test
public void cannotPlaceBidMarketOrderWithAmountToHigh() {
    ThrowingCallable check = () -> tradeService.verifyOrder(new MarketOrder(OrderType.BID, new BigDecimal("1000001"), CurrencyPair.BTC_USD, new Date()));
    assertThatThrownBy(check).isInstanceOf(IllegalArgumentException.class).hasMessage("Quantity to high");
}
Also used : ThrowingCallable(org.assertj.core.api.ThrowableAssert.ThrowingCallable) MarketOrder(org.knowm.xchange.dto.trade.MarketOrder) BigDecimal(java.math.BigDecimal) Date(java.util.Date) LgoProductsTest(org.knowm.xchange.lgo.dto.product.LgoProductsTest) Test(org.junit.Test)

Aggregations

MarketOrder (org.knowm.xchange.dto.trade.MarketOrder)45 BigDecimal (java.math.BigDecimal)37 Test (org.junit.Test)20 Date (java.util.Date)17 LimitOrder (org.knowm.xchange.dto.trade.LimitOrder)15 CurrencyPair (org.knowm.xchange.currency.CurrencyPair)10 TradeService (org.knowm.xchange.service.trade.TradeService)9 UserTrades (org.knowm.xchange.dto.trade.UserTrades)8 Order (org.knowm.xchange.dto.Order)7 OrderType (org.knowm.xchange.dto.Order.OrderType)6 LgoProductsTest (org.knowm.xchange.lgo.dto.product.LgoProductsTest)6 OpenOrders (org.knowm.xchange.dto.trade.OpenOrders)5 IOException (java.io.IOException)4 ThrowingCallable (org.assertj.core.api.ThrowableAssert.ThrowingCallable)4 Exchange (org.knowm.xchange.Exchange)4 StopOrder (org.knowm.xchange.dto.trade.StopOrder)4 OrderStatus (org.knowm.xchange.dto.Order.OrderStatus)3 ArrayList (java.util.ArrayList)2 ExchangeSpecification (org.knowm.xchange.ExchangeSpecification)2 UserTrade (org.knowm.xchange.dto.trade.UserTrade)2