Search in sources :

Example 1 with CurrencyPairNotValidException

use of org.knowm.xchange.exceptions.CurrencyPairNotValidException in project XChange by knowm.

the class IndependentReserveTradeServiceRaw method independentReservePlaceMarketOrder.

public String independentReservePlaceMarketOrder(Instrument instrument, Order.OrderType type, BigDecimal originalAmount) throws IOException {
    CurrencyPair currencyPair;
    if (instrument instanceof CurrencyPair) {
        currencyPair = (CurrencyPair) instrument;
    } else {
        throw new CurrencyPairNotValidException("Given instrument is not an instance of CurrencyPair");
    }
    Long nonce = exchange.getNonceFactory().createValue();
    String apiKey = exchange.getExchangeSpecification().getApiKey();
    String orderType = null;
    if (type == Order.OrderType.ASK) {
        orderType = "MarketOffer";
    } else if (type == Order.OrderType.BID) {
        orderType = "MarketBid";
    }
    IndependentReservePlaceMarketOrderRequest independentReservePlaceMarketOrderRequest = new IndependentReservePlaceMarketOrderRequest(apiKey, nonce, currencyPair.base.getCurrencyCode(), currencyPair.counter.getCurrencyCode(), orderType, originalAmount.toString());
    independentReservePlaceMarketOrderRequest.setSignature(signatureCreator.digestParamsToString(ExchangeEndpoint.PLACE_MARKET_ORDER, nonce, independentReservePlaceMarketOrderRequest.getParameters()));
    IndependentReservePlaceMarketOrderResponse independentReservePlaceMarketOrderResponse = independentReserveAuthenticated.placeMarketOrder(independentReservePlaceMarketOrderRequest);
    return independentReservePlaceMarketOrderResponse.getOrderGuid();
}
Also used : CurrencyPairNotValidException(org.knowm.xchange.exceptions.CurrencyPairNotValidException) IndependentReservePlaceMarketOrderResponse(org.knowm.xchange.independentreserve.dto.trade.IndependentReservePlaceMarketOrderResponse) IndependentReservePlaceMarketOrderRequest(org.knowm.xchange.independentreserve.dto.trade.IndependentReservePlaceMarketOrderRequest) CurrencyPair(org.knowm.xchange.currency.CurrencyPair)

Example 2 with CurrencyPairNotValidException

use of org.knowm.xchange.exceptions.CurrencyPairNotValidException in project XChange by knowm.

the class DeribitAdapters method adapt.

/**
 * Parse errors from HTTP exceptions
 */
public static ExchangeException adapt(DeribitException ex) {
    DeribitError error = ex.getError();
    if (error != null && error.getClass().equals(DeribitError.class) && isNotEmpty(error.getMessage())) {
        int code = error.getCode();
        String msg = error.getMessage();
        String data = error.getData().toString();
        if (isNotEmpty(data)) {
            msg += " - " + data;
        }
        switch(code) {
            case -32602:
                return new CurrencyPairNotValidException(data, ex);
            default:
                return new ExchangeException(msg, ex);
        }
    }
    return new ExchangeException("Operation failed without any error message", ex);
}
Also used : DeribitError(org.knowm.xchange.deribit.v2.dto.DeribitError) CurrencyPairNotValidException(org.knowm.xchange.exceptions.CurrencyPairNotValidException) ExchangeException(org.knowm.xchange.exceptions.ExchangeException)

Example 3 with CurrencyPairNotValidException

use of org.knowm.xchange.exceptions.CurrencyPairNotValidException in project XChange by knowm.

the class BitfinexErrorAdapter method adapt.

public static ExchangeException adapt(BitfinexException e) {
    String message = e.getMessage();
    if (StringUtils.isEmpty(message)) {
        return new ExchangeException(e);
    }
    message = message.toLowerCase();
    if (message.contains("unknown symbol") || message.contains("symbol: invalid")) {
        return new CurrencyPairNotValidException(message, e);
    } else if (message.contains("not enough exchange balance")) {
        return new FundsExceededException(message, e);
    } else if (message.contains("err_rate_limit") || message.contains("ratelimit")) {
        return new RateLimitExceededException(e);
    } else if (message.contains("nonce")) {
        return new NonceException(e);
    }
    return new ExchangeException(message, e);
}
Also used : NonceException(org.knowm.xchange.exceptions.NonceException) CurrencyPairNotValidException(org.knowm.xchange.exceptions.CurrencyPairNotValidException) ExchangeException(org.knowm.xchange.exceptions.ExchangeException) RateLimitExceededException(org.knowm.xchange.exceptions.RateLimitExceededException) FundsExceededException(org.knowm.xchange.exceptions.FundsExceededException)

Aggregations

CurrencyPairNotValidException (org.knowm.xchange.exceptions.CurrencyPairNotValidException)3 ExchangeException (org.knowm.xchange.exceptions.ExchangeException)2 CurrencyPair (org.knowm.xchange.currency.CurrencyPair)1 DeribitError (org.knowm.xchange.deribit.v2.dto.DeribitError)1 FundsExceededException (org.knowm.xchange.exceptions.FundsExceededException)1 NonceException (org.knowm.xchange.exceptions.NonceException)1 RateLimitExceededException (org.knowm.xchange.exceptions.RateLimitExceededException)1 IndependentReservePlaceMarketOrderRequest (org.knowm.xchange.independentreserve.dto.trade.IndependentReservePlaceMarketOrderRequest)1 IndependentReservePlaceMarketOrderResponse (org.knowm.xchange.independentreserve.dto.trade.IndependentReservePlaceMarketOrderResponse)1