use of org.knowm.xchange.binance.dto.trade.BinanceOrder in project XChange by knowm.
the class BinanceTradeService method getOpenOrders.
@Override
public OpenOrders getOpenOrders(OpenOrdersParams params) throws IOException {
try {
List<BinanceOrder> binanceOpenOrders;
if (params instanceof OpenOrdersParamCurrencyPair) {
OpenOrdersParamCurrencyPair pairParams = (OpenOrdersParamCurrencyPair) params;
CurrencyPair pair = pairParams.getCurrencyPair();
binanceOpenOrders = super.openOrders(pair);
} else {
binanceOpenOrders = super.openOrders();
}
List<LimitOrder> limitOrders = new ArrayList<>();
List<Order> otherOrders = new ArrayList<>();
binanceOpenOrders.forEach(binanceOrder -> {
Order order = BinanceAdapters.adaptOrder(binanceOrder);
if (order instanceof LimitOrder) {
limitOrders.add((LimitOrder) order);
} else {
otherOrders.add(order);
}
});
return new OpenOrders(limitOrders, otherOrders);
} catch (BinanceException e) {
throw BinanceErrorAdapter.adapt(e);
}
}
use of org.knowm.xchange.binance.dto.trade.BinanceOrder in project XChange by knowm.
the class BinanceAdaptersTest method testFilledMarketOrder.
@Test
public void testFilledMarketOrder() throws IOException {
BinanceOrder binanceOrder = ObjectMapperHelper.readValue(BinanceAdaptersTest.class.getResource("/org/knowm/xchange/binance/filled-market-order.json"), BinanceOrder.class);
Order order = BinanceAdapters.adaptOrder(binanceOrder);
assertThat(order).isInstanceOf(MarketOrder.class);
MarketOrder marketOrder = (MarketOrder) order;
assertThat(marketOrder.getStatus()).isEqualByComparingTo(Order.OrderStatus.FILLED);
assertThat(marketOrder.getOriginalAmount()).isEqualByComparingTo("0.10700000");
assertThat(marketOrder.getCumulativeAmount()).isEqualByComparingTo("0.10700000");
assertThat(marketOrder.getRemainingAmount()).isEqualByComparingTo(BigDecimal.ZERO);
assertThat(marketOrder.getAveragePrice()).isEqualByComparingTo("0.01858383");
assertThat(marketOrder.getOrderFlags()).contains(BinanceOrderFlags.withClientId("gzcLIkn86ag3FycOCEl6Vi"));
MarketOrder copy = ObjectMapperHelper.viaJSON(marketOrder);
assertThat(copy).isEqualToComparingFieldByField(marketOrder);
}
use of org.knowm.xchange.binance.dto.trade.BinanceOrder in project XChange by knowm.
the class BinanceAdapters method adaptOrder.
public static Order adaptOrder(BinanceOrder order) {
OrderType type = convert(order.side);
CurrencyPair currencyPair = adaptSymbol(order.symbol);
Order.Builder builder;
if (order.type.equals(org.knowm.xchange.binance.dto.trade.OrderType.MARKET)) {
builder = new MarketOrder.Builder(type, currencyPair);
} else if (order.type.equals(org.knowm.xchange.binance.dto.trade.OrderType.LIMIT) || order.type.equals(org.knowm.xchange.binance.dto.trade.OrderType.LIMIT_MAKER)) {
builder = new LimitOrder.Builder(type, currencyPair).limitPrice(order.price);
} else {
builder = new StopOrder.Builder(type, currencyPair).stopPrice(order.stopPrice);
}
builder.orderStatus(adaptOrderStatus(order.status)).originalAmount(order.origQty).id(Long.toString(order.orderId)).timestamp(order.getTime()).cumulativeAmount(order.executedQty);
if (order.executedQty.signum() != 0 && order.cummulativeQuoteQty.signum() != 0) {
builder.averagePrice(order.cummulativeQuoteQty.divide(order.executedQty, MathContext.DECIMAL32));
}
if (order.clientOrderId != null) {
builder.flag(BinanceOrderFlags.withClientId(order.clientOrderId));
}
return builder.build();
}
Aggregations