use of org.knowm.xchange.dto.trade.MarketOrder in project XChange by knowm.
the class KrakenAdapters method adaptOrder.
public static Order adaptOrder(String orderId, KrakenOrder krakenOrder) {
OrderType orderType = adaptOrderType(krakenOrder.getOrderDescription().getType());
CurrencyPair currencyPair = adaptCurrencyPair(krakenOrder.getOrderDescription().getAssetPair());
OrderStatus orderStatus = adaptOrderStatus(krakenOrder.getStatus());
BigDecimal filledAmount = krakenOrder.getVolumeExecuted();
BigDecimal originalAmount = krakenOrder.getVolume();
BigDecimal fee = krakenOrder.getFee();
if (orderStatus == OrderStatus.NEW && filledAmount.compareTo(BigDecimal.ZERO) > 0 && filledAmount.compareTo(originalAmount) < 0) {
orderStatus = OrderStatus.PARTIALLY_FILLED;
}
// eg: "opentm":1519731205.9987
Double time = krakenOrder.getOpenTimestamp() * 1000;
Date timestamp = new Date(time.longValue());
if (krakenOrder.getOrderDescription().getOrderType().equals(KrakenOrderType.LIMIT))
return new LimitOrder(orderType, krakenOrder.getVolume(), currencyPair, orderId, timestamp, krakenOrder.getOrderDescription().getPrice(), krakenOrder.getPrice(), krakenOrder.getVolumeExecuted(), fee, orderStatus, krakenOrder.getUserRefId());
if (krakenOrder.getOrderDescription().getOrderType().equals(KrakenOrderType.MARKET))
return new MarketOrder(orderType, krakenOrder.getVolume(), currencyPair, orderId, timestamp, krakenOrder.getPrice(), krakenOrder.getVolumeExecuted(), fee, orderStatus, krakenOrder.getUserRefId());
throw new NotYetImplementedForExchangeException();
}
use of org.knowm.xchange.dto.trade.MarketOrder in project XChange by knowm.
the class IndependentReserveAdaptersTest method adaptOrderDetails.
@Test
public void adaptOrderDetails() throws InvalidFormatException {
IndependentReserveOrderDetailsResponse orderDetailsResponse = new IndependentReserveOrderDetailsResponse("abcf-123", "2014-09-23T12:39:34.3817763Z", "MarketBid", new BigDecimal(5.0), new BigDecimal(4.0), new BigDecimal(100), new BigDecimal(95), new BigDecimal(0), "PartiallyFilled", "Xbt", "Usd");
MarketOrder order = (MarketOrder) IndependentReserveAdapters.adaptOrderDetails(orderDetailsResponse);
assertThat(order.getId()).isEqualTo("abcf-123");
assertThat(order.getTimestamp()).isEqualTo(Date.from(ZonedDateTime.of(2014, 9, 23, 12, 39, 34, 0, UTC).toInstant()));
assertThat(order.getType()).isEqualTo(Order.OrderType.BID);
assertThat(order.getOriginalAmount()).isEqualByComparingTo(new BigDecimal(5));
assertThat(order.getCumulativeAmount()).isEqualByComparingTo(new BigDecimal(4));
assertThat(order.getAveragePrice()).isEqualByComparingTo(new BigDecimal(95));
assertThat(order.getFee()).isNull();
assertThat(order.getStatus()).isEqualTo(Order.OrderStatus.PARTIALLY_FILLED);
assertThat(order.getCurrencyPair()).isEqualTo(new CurrencyPair("Xbt", "Usd"));
}
use of org.knowm.xchange.dto.trade.MarketOrder in project XChange by knowm.
the class LgoExchangeTradeIntegration method placeMarketOrder.
@Test
public void placeMarketOrder() throws IOException {
LgoExchange lgoExchange = exchangeWithCredentials(false);
LgoTradeService tradeService = lgoExchange.getTradeService();
String orderId = tradeService.placeMarketOrder(new MarketOrder(OrderType.ASK, new BigDecimal("2"), CurrencyPair.BTC_USD, null, new Date()));
System.out.println(orderId);
}
use of org.knowm.xchange.dto.trade.MarketOrder in project XChange by knowm.
the class LgoExchangeTradeIntegration method placeEncryptedMarketOrder.
@Test
public void placeEncryptedMarketOrder() throws IOException {
LgoExchange lgoExchange = exchangeWithCredentials(true);
LgoTradeService tradeService = lgoExchange.getTradeService();
String orderId = tradeService.placeMarketOrder(new MarketOrder(OrderType.ASK, new BigDecimal("2"), CurrencyPair.BTC_USD, null, new Date()));
System.out.println(orderId);
}
use of org.knowm.xchange.dto.trade.MarketOrder in project cassandre-trading-bot by cassandre-tech.
the class TradeServiceXChangeImplementation method createMarketOrder.
/**
* Creates market order.
*
* @param strategy strategy
* @param orderTypeDTO order type
* @param currencyPair currency pair
* @param amount amount
* @return order creation result
*/
private OrderCreationResultDTO createMarketOrder(final GenericCassandreStrategy strategy, final OrderTypeDTO orderTypeDTO, final CurrencyPairDTO currencyPair, final BigDecimal amount) {
try {
// Making the order.
MarketOrder m = new MarketOrder(UTIL_MAPPER.mapToOrderType(orderTypeDTO), amount.setScale(currencyPair.getBaseCurrencyPrecision(), FLOOR), CURRENCY_MAPPER.mapToCurrencyPair(currencyPair), getGeneratedOrderId(), null);
logger.debug("Sending market order: {} - {} - {}", orderTypeDTO, currencyPair, amount.setScale(currencyPair.getBaseCurrencyPrecision(), FLOOR));
// Sending the order.
OrderDTO order = OrderDTO.builder().orderId(tradeService.placeMarketOrder(m)).type(orderTypeDTO).strategy(strategy.getStrategyDTO()).currencyPair(currencyPair).amount(CurrencyAmountDTO.builder().value(amount).currency(currencyPair.getBaseCurrency()).build()).cumulativeAmount(CurrencyAmountDTO.builder().value(amount).currency(currencyPair.getBaseCurrency()).build()).averagePrice(CurrencyAmountDTO.builder().value(strategy.getLastPriceForCurrencyPair(currencyPair)).currency(currencyPair.getQuoteCurrency()).build()).marketPrice(CurrencyAmountDTO.builder().value(strategy.getLastPriceForCurrencyPair(currencyPair)).currency(currencyPair.getQuoteCurrency()).build()).status(PENDING_NEW).timestamp(ZonedDateTime.now()).build();
// We save the order.
Optional<Order> savedOrder = orderRepository.findByOrderId(order.getOrderId());
if (savedOrder.isEmpty()) {
savedOrder = Optional.of(orderRepository.save(ORDER_MAPPER.mapToOrder(order)));
}
final OrderCreationResultDTO result = new OrderCreationResultDTO(ORDER_MAPPER.mapToOrderDTO(savedOrder.get()));
logger.debug("Order created: {}", result);
return result;
} catch (Exception e) {
final String error = "TradeService - Error calling createMarketOrder for " + amount + " " + currencyPair + ": " + e.getMessage();
e.printStackTrace();
logger.error(error);
return new OrderCreationResultDTO(error, e);
}
}
Aggregations