use of org.knowm.xchange.poloniex.dto.PoloniexException in project XChange by knowm.
the class PoloniexMarketDataService method getOrderBook.
@Override
public OrderBook getOrderBook(CurrencyPair currencyPair, Object... args) throws ExchangeException, IOException {
try {
PoloniexDepth depth = null;
// ~full order book
int depthLimit = 999999;
if (args != null && args.length > 0) {
if (args[0] instanceof Integer) {
depthLimit = (Integer) args[0];
} else {
throw new ExchangeException("Orderbook size argument must be an Integer!");
}
}
depth = getPoloniexDepth(currencyPair, depthLimit);
if (depth == null) {
depth = getPoloniexDepth(currencyPair);
}
return PoloniexAdapters.adaptPoloniexDepth(depth, currencyPair);
} catch (PoloniexException e) {
throw PoloniexErrorAdapter.adapt(e);
}
}
use of org.knowm.xchange.poloniex.dto.PoloniexException in project XChange by knowm.
the class PoloniexMarketDataServiceRaw method getPoloniexTicker.
public PoloniexTicker getPoloniexTicker(CurrencyPair currencyPair) throws IOException {
String command = "returnTicker";
String pairString = PoloniexUtils.toPairString(currencyPair);
long now = System.currentTimeMillis();
if (TickermarketData == null || next_refresh < now) {
try {
TickermarketData = poloniex.getTicker(command);
} catch (PoloniexException e) {
throw PoloniexErrorAdapter.adapt(e);
} finally {
// also nice to take a short break on an error
next_refresh = now + cache_delay;
}
}
PoloniexMarketData data = TickermarketData.get(pairString);
if (data == null) {
return null;
}
return new PoloniexTicker(data, currencyPair);
}
use of org.knowm.xchange.poloniex.dto.PoloniexException in project XChange by knowm.
the class PoloniexTradeService method getOpenOrders.
@Override
public OpenOrders getOpenOrders(OpenOrdersParams params) throws ExchangeException, IOException {
try {
CurrencyPair currencyPair = null;
if (params instanceof OpenOrdersParamCurrencyPair) {
currencyPair = ((OpenOrdersParamCurrencyPair) params).getCurrencyPair();
}
final Map<String, PoloniexOpenOrder[]> poloniexOpenOrders;
if (currencyPair == null) {
poloniexOpenOrders = returnOpenOrders();
} else {
final PoloniexOpenOrder[] cpOpenOrders = returnOpenOrders(currencyPair);
poloniexOpenOrders = new HashMap<>(1);
poloniexOpenOrders.put(PoloniexUtils.toPairString(currencyPair), cpOpenOrders);
}
return PoloniexAdapters.adaptPoloniexOpenOrders(poloniexOpenOrders);
} catch (PoloniexException e) {
throw PoloniexErrorAdapter.adapt(e);
}
}
use of org.knowm.xchange.poloniex.dto.PoloniexException in project XChange by knowm.
the class PoloniexErrorAdapterTest method throwIfErrorResponse_unrecognizedStatusAndErrorMessage.
@Test
public void throwIfErrorResponse_unrecognizedStatusAndErrorMessage() {
PoloniexException e = new PoloniexException();
e.setError("Some error msg");
e.setHttpStatusCode(123);
ExchangeException adapted = PoloniexErrorAdapter.adapt(e);
assertThat(adapted).isExactlyInstanceOf(ExchangeException.class);
}
use of org.knowm.xchange.poloniex.dto.PoloniexException in project XChange by knowm.
the class PoloniexErrorAdapterTest method throwIfErrorResponse_invalidPair.
@Test
public void throwIfErrorResponse_invalidPair() {
PoloniexException e = new PoloniexException();
e.setError("Invalid currency pair");
// Poloniex actualy returns 200 on this with an error
e.setHttpStatusCode(200);
ExchangeException adapted = PoloniexErrorAdapter.adapt(e);
assertThat(adapted).isExactlyInstanceOf(CurrencyPairNotValidException.class);
}
Aggregations