Search in sources :

Example 1 with BinanceException

use of org.knowm.xchange.binance.dto.BinanceException in project XChange by knowm.

the class BinanceTradeService method cancelOrder.

@Override
public boolean cancelOrder(CancelOrderParams params) throws IOException {
    try {
        if (!(params instanceof CancelOrderByCurrencyPair) && !(params instanceof CancelOrderByIdParams)) {
            throw new ExchangeException("You need to provide the currency pair and the order id to cancel an order.");
        }
        CancelOrderByCurrencyPair paramCurrencyPair = (CancelOrderByCurrencyPair) params;
        CancelOrderByIdParams paramId = (CancelOrderByIdParams) params;
        super.cancelOrder(paramCurrencyPair.getCurrencyPair(), BinanceAdapters.id(paramId.getOrderId()), null, null);
        return true;
    } catch (BinanceException e) {
        throw BinanceErrorAdapter.adapt(e);
    }
}
Also used : BinanceException(org.knowm.xchange.binance.dto.BinanceException) CancelOrderByIdParams(org.knowm.xchange.service.trade.params.CancelOrderByIdParams) NotAvailableFromExchangeException(org.knowm.xchange.exceptions.NotAvailableFromExchangeException) ExchangeException(org.knowm.xchange.exceptions.ExchangeException) CancelOrderByCurrencyPair(org.knowm.xchange.service.trade.params.CancelOrderByCurrencyPair)

Example 2 with BinanceException

use of org.knowm.xchange.binance.dto.BinanceException in project XChange by knowm.

the class BinanceTradeService method getOrder.

@Override
public Collection<Order> getOrder(OrderQueryParams... params) throws IOException {
    try {
        Collection<Order> orders = new ArrayList<>();
        for (OrderQueryParams param : params) {
            if (!(param instanceof OrderQueryParamCurrencyPair)) {
                throw new ExchangeException("Parameters must be an instance of OrderQueryParamCurrencyPair");
            }
            OrderQueryParamCurrencyPair orderQueryParamCurrencyPair = (OrderQueryParamCurrencyPair) param;
            if (orderQueryParamCurrencyPair.getCurrencyPair() == null || orderQueryParamCurrencyPair.getOrderId() == null) {
                throw new ExchangeException("You need to provide the currency pair and the order id to query an order.");
            }
            orders.add(BinanceAdapters.adaptOrder(super.orderStatus(orderQueryParamCurrencyPair.getCurrencyPair(), BinanceAdapters.id(orderQueryParamCurrencyPair.getOrderId()), null)));
        }
        return orders;
    } catch (BinanceException e) {
        throw BinanceErrorAdapter.adapt(e);
    }
}
Also used : 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) OrderQueryParamCurrencyPair(org.knowm.xchange.service.trade.params.orders.OrderQueryParamCurrencyPair) ArrayList(java.util.ArrayList) NotAvailableFromExchangeException(org.knowm.xchange.exceptions.NotAvailableFromExchangeException) ExchangeException(org.knowm.xchange.exceptions.ExchangeException) OrderQueryParams(org.knowm.xchange.service.trade.params.orders.OrderQueryParams)

Example 3 with BinanceException

use of org.knowm.xchange.binance.dto.BinanceException in project XChange by knowm.

the class BinanceTradeService method placeTestOrder.

public void placeTestOrder(OrderType type, Order order, BigDecimal limitPrice, BigDecimal stopPrice) throws IOException {
    try {
        TimeInForce tif = timeInForceFromOrder(order).orElse(null);
        Long recvWindow = (Long) exchange.getExchangeSpecification().getExchangeSpecificParametersItem("recvWindow");
        testNewOrder(order.getCurrencyPair(), BinanceAdapters.convert(order.getType()), type, tif, order.getOriginalAmount(), limitPrice, getClientOrderId(order), stopPrice, null);
    } catch (BinanceException e) {
        throw BinanceErrorAdapter.adapt(e);
    }
}
Also used : BinanceException(org.knowm.xchange.binance.dto.BinanceException) TimeInForce(org.knowm.xchange.binance.dto.trade.TimeInForce)

Example 4 with BinanceException

use of org.knowm.xchange.binance.dto.BinanceException in project XChange by knowm.

the class BinanceErrorAdapterTest method testBinanceExceptionWithCode1013MsgLotSize.

@Test
public void testBinanceExceptionWithCode1013MsgLotSize() {
    final ExchangeException adaptedException = BinanceErrorAdapter.adapt(new BinanceException(-1013, "LOT_SIZE"));
    assertThat(adaptedException).isInstanceOf(OrderNotValidException.class);
}
Also used : BinanceException(org.knowm.xchange.binance.dto.BinanceException) ExchangeException(org.knowm.xchange.exceptions.ExchangeException) Test(org.junit.Test)

Example 5 with BinanceException

use of org.knowm.xchange.binance.dto.BinanceException in project XChange by knowm.

the class BinanceErrorAdapterTest method testBinanceExceptionWithCode1013MsgMinNotional.

@Test
public void testBinanceExceptionWithCode1013MsgMinNotional() {
    final ExchangeException adaptedException = BinanceErrorAdapter.adapt(new BinanceException(-1013, "MIN_NOTIONAL"));
    assertThat(adaptedException).isInstanceOf(OrderAmountUnderMinimumException.class);
}
Also used : BinanceException(org.knowm.xchange.binance.dto.BinanceException) ExchangeException(org.knowm.xchange.exceptions.ExchangeException) Test(org.junit.Test)

Aggregations

BinanceException (org.knowm.xchange.binance.dto.BinanceException)13 ArrayList (java.util.ArrayList)5 ExchangeException (org.knowm.xchange.exceptions.ExchangeException)5 BinanceNewOrder (org.knowm.xchange.binance.dto.trade.BinanceNewOrder)4 CurrencyPair (org.knowm.xchange.currency.CurrencyPair)4 BigDecimal (java.math.BigDecimal)3 BinanceOrder (org.knowm.xchange.binance.dto.trade.BinanceOrder)3 Order (org.knowm.xchange.dto.Order)3 LimitOrder (org.knowm.xchange.dto.trade.LimitOrder)3 MarketOrder (org.knowm.xchange.dto.trade.MarketOrder)3 StopOrder (org.knowm.xchange.dto.trade.StopOrder)3 CancelOrderByCurrencyPair (org.knowm.xchange.service.trade.params.CancelOrderByCurrencyPair)3 TradeHistoryParamLimit (org.knowm.xchange.service.trade.params.TradeHistoryParamLimit)3 TradeHistoryParamsTimeSpan (org.knowm.xchange.service.trade.params.TradeHistoryParamsTimeSpan)3 OrderQueryParamCurrencyPair (org.knowm.xchange.service.trade.params.orders.OrderQueryParamCurrencyPair)3 IOException (java.io.IOException)2 Date (java.util.Date)2 HashMap (java.util.HashMap)2 List (java.util.List)2 Collectors (java.util.stream.Collectors)2