Search in sources :

Example 1 with PoloniexException

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);
    }
}
Also used : ExchangeException(org.knowm.xchange.exceptions.ExchangeException) PoloniexDepth(org.knowm.xchange.poloniex.dto.marketdata.PoloniexDepth) PoloniexException(org.knowm.xchange.poloniex.dto.PoloniexException)

Example 2 with PoloniexException

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);
}
Also used : PoloniexTicker(org.knowm.xchange.poloniex.dto.marketdata.PoloniexTicker) PoloniexMarketData(org.knowm.xchange.poloniex.dto.marketdata.PoloniexMarketData) PoloniexException(org.knowm.xchange.poloniex.dto.PoloniexException)

Example 3 with PoloniexException

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);
    }
}
Also used : PoloniexException(org.knowm.xchange.poloniex.dto.PoloniexException) OpenOrdersParamCurrencyPair(org.knowm.xchange.service.trade.params.orders.OpenOrdersParamCurrencyPair) DefaultOpenOrdersParamCurrencyPair(org.knowm.xchange.service.trade.params.orders.DefaultOpenOrdersParamCurrencyPair) CurrencyPair(org.knowm.xchange.currency.CurrencyPair) TradeHistoryParamCurrencyPair(org.knowm.xchange.service.trade.params.TradeHistoryParamCurrencyPair) OpenOrdersParamCurrencyPair(org.knowm.xchange.service.trade.params.orders.OpenOrdersParamCurrencyPair) DefaultOpenOrdersParamCurrencyPair(org.knowm.xchange.service.trade.params.orders.DefaultOpenOrdersParamCurrencyPair) PoloniexOpenOrder(org.knowm.xchange.poloniex.dto.trade.PoloniexOpenOrder)

Example 4 with PoloniexException

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);
}
Also used : ExchangeException(org.knowm.xchange.exceptions.ExchangeException) PoloniexException(org.knowm.xchange.poloniex.dto.PoloniexException) Test(org.junit.Test)

Example 5 with PoloniexException

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);
}
Also used : ExchangeException(org.knowm.xchange.exceptions.ExchangeException) PoloniexException(org.knowm.xchange.poloniex.dto.PoloniexException) Test(org.junit.Test)

Aggregations

PoloniexException (org.knowm.xchange.poloniex.dto.PoloniexException)14 Test (org.junit.Test)7 Method (java.lang.reflect.Method)4 ExchangeException (org.knowm.xchange.exceptions.ExchangeException)4 InvocationResult (si.mazi.rescu.InvocationResult)4 RestMethodMetadata (si.mazi.rescu.RestMethodMetadata)4 DefaultJacksonObjectMapperFactory (si.mazi.rescu.serialization.jackson.DefaultJacksonObjectMapperFactory)4 JacksonResponseReader (si.mazi.rescu.serialization.jackson.JacksonResponseReader)4 Date (java.util.Date)2 CurrencyPair (org.knowm.xchange.currency.CurrencyPair)2 TradeHistoryParamCurrencyPair (org.knowm.xchange.service.trade.params.TradeHistoryParamCurrencyPair)2 TradeHistoryParamsTimeSpan (org.knowm.xchange.service.trade.params.TradeHistoryParamsTimeSpan)2 DefaultOpenOrdersParamCurrencyPair (org.knowm.xchange.service.trade.params.orders.DefaultOpenOrdersParamCurrencyPair)2 OpenOrdersParamCurrencyPair (org.knowm.xchange.service.trade.params.orders.OpenOrdersParamCurrencyPair)2 ArrayList (java.util.ArrayList)1 UserTrade (org.knowm.xchange.dto.trade.UserTrade)1 UserTrades (org.knowm.xchange.dto.trade.UserTrades)1 PoloniexDepth (org.knowm.xchange.poloniex.dto.marketdata.PoloniexDepth)1 PoloniexMarketData (org.knowm.xchange.poloniex.dto.marketdata.PoloniexMarketData)1 PoloniexTicker (org.knowm.xchange.poloniex.dto.marketdata.PoloniexTicker)1