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);
}
}
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);
}
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;
}
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");
}
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");
}
Aggregations