Search in sources :

Example 1 with BinanceOrder

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);
    }
}
Also used : BinanceOrder(org.knowm.xchange.binance.dto.trade.BinanceOrder) StopOrder(org.knowm.xchange.dto.trade.StopOrder) BinanceNewOrder(org.knowm.xchange.binance.dto.trade.BinanceNewOrder) BinanceOrder(org.knowm.xchange.binance.dto.trade.BinanceOrder) Order(org.knowm.xchange.dto.Order) LimitOrder(org.knowm.xchange.dto.trade.LimitOrder) MarketOrder(org.knowm.xchange.dto.trade.MarketOrder) BinanceException(org.knowm.xchange.binance.dto.BinanceException) ArrayList(java.util.ArrayList) LimitOrder(org.knowm.xchange.dto.trade.LimitOrder) OpenOrders(org.knowm.xchange.dto.trade.OpenOrders) OpenOrdersParamCurrencyPair(org.knowm.xchange.service.trade.params.orders.OpenOrdersParamCurrencyPair) DefaultOpenOrdersParamCurrencyPair(org.knowm.xchange.service.trade.params.orders.DefaultOpenOrdersParamCurrencyPair) CancelOrderByCurrencyPair(org.knowm.xchange.service.trade.params.CancelOrderByCurrencyPair) OpenOrdersParamCurrencyPair(org.knowm.xchange.service.trade.params.orders.OpenOrdersParamCurrencyPair) DefaultOpenOrdersParamCurrencyPair(org.knowm.xchange.service.trade.params.orders.DefaultOpenOrdersParamCurrencyPair) OrderQueryParamCurrencyPair(org.knowm.xchange.service.trade.params.orders.OrderQueryParamCurrencyPair) CurrencyPair(org.knowm.xchange.currency.CurrencyPair) TradeHistoryParamCurrencyPair(org.knowm.xchange.service.trade.params.TradeHistoryParamCurrencyPair)

Example 2 with BinanceOrder

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);
}
Also used : BinanceOrder(org.knowm.xchange.binance.dto.trade.BinanceOrder) Order(org.knowm.xchange.dto.Order) MarketOrder(org.knowm.xchange.dto.trade.MarketOrder) BinanceOrder(org.knowm.xchange.binance.dto.trade.BinanceOrder) MarketOrder(org.knowm.xchange.dto.trade.MarketOrder) Test(org.junit.Test)

Example 3 with BinanceOrder

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();
}
Also used : StopOrder(org.knowm.xchange.dto.trade.StopOrder) BinanceOrder(org.knowm.xchange.binance.dto.trade.BinanceOrder) Order(org.knowm.xchange.dto.Order) LimitOrder(org.knowm.xchange.dto.trade.LimitOrder) MarketOrder(org.knowm.xchange.dto.trade.MarketOrder) OrderType(org.knowm.xchange.dto.Order.OrderType) StopOrder(org.knowm.xchange.dto.trade.StopOrder) MarketOrder(org.knowm.xchange.dto.trade.MarketOrder) LimitOrder(org.knowm.xchange.dto.trade.LimitOrder) CurrencyPair(org.knowm.xchange.currency.CurrencyPair)

Aggregations

BinanceOrder (org.knowm.xchange.binance.dto.trade.BinanceOrder)3 Order (org.knowm.xchange.dto.Order)3 MarketOrder (org.knowm.xchange.dto.trade.MarketOrder)3 CurrencyPair (org.knowm.xchange.currency.CurrencyPair)2 LimitOrder (org.knowm.xchange.dto.trade.LimitOrder)2 StopOrder (org.knowm.xchange.dto.trade.StopOrder)2 ArrayList (java.util.ArrayList)1 Test (org.junit.Test)1 BinanceException (org.knowm.xchange.binance.dto.BinanceException)1 BinanceNewOrder (org.knowm.xchange.binance.dto.trade.BinanceNewOrder)1 OrderType (org.knowm.xchange.dto.Order.OrderType)1 OpenOrders (org.knowm.xchange.dto.trade.OpenOrders)1 CancelOrderByCurrencyPair (org.knowm.xchange.service.trade.params.CancelOrderByCurrencyPair)1 TradeHistoryParamCurrencyPair (org.knowm.xchange.service.trade.params.TradeHistoryParamCurrencyPair)1 DefaultOpenOrdersParamCurrencyPair (org.knowm.xchange.service.trade.params.orders.DefaultOpenOrdersParamCurrencyPair)1 OpenOrdersParamCurrencyPair (org.knowm.xchange.service.trade.params.orders.OpenOrdersParamCurrencyPair)1 OrderQueryParamCurrencyPair (org.knowm.xchange.service.trade.params.orders.OrderQueryParamCurrencyPair)1