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();
}
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);
}
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);
}
Aggregations