Search in sources :

Example 11 with PoloniexException

use of org.knowm.xchange.poloniex.dto.PoloniexException in project XChange by knowm.

the class PoloniexOrderTest method buyRejectTest.

@Test(expected = PoloniexException.class)
public void buyRejectTest() throws Exception {
    InvocationResult invocationResult = new InvocationResult("{\"error\":\"Not enough LTC.\"}", 200);
    Method apiMethod = PoloniexAuthenticated.class.getDeclaredMethod("buy", String.class, ParamsDigest.class, SynchronizedValueFactory.class, String.class, String.class, String.class, Integer.class, Integer.class, Integer.class);
    RestMethodMetadata data = RestMethodMetadata.create(apiMethod, "", "");
    try {
        new JacksonResponseReader(new DefaultJacksonObjectMapperFactory().createObjectMapper(), false).read(invocationResult, data);
    } catch (PoloniexException e) {
        Assert.assertTrue(e.getMessage().startsWith("Not enough LTC."));
        throw e;
    }
}
Also used : DefaultJacksonObjectMapperFactory(si.mazi.rescu.serialization.jackson.DefaultJacksonObjectMapperFactory) Method(java.lang.reflect.Method) InvocationResult(si.mazi.rescu.InvocationResult) JacksonResponseReader(si.mazi.rescu.serialization.jackson.JacksonResponseReader) PoloniexException(org.knowm.xchange.poloniex.dto.PoloniexException) RestMethodMetadata(si.mazi.rescu.RestMethodMetadata) Test(org.junit.Test)

Example 12 with PoloniexException

use of org.knowm.xchange.poloniex.dto.PoloniexException in project XChange by knowm.

the class PoloniexTradeService method placeLimitOrder.

@Override
public String placeLimitOrder(LimitOrder limitOrder) throws IOException {
    try {
        PoloniexTradeResponse response;
        if (limitOrder.getType() == OrderType.BID || limitOrder.getType() == OrderType.EXIT_ASK) {
            response = buy(limitOrder);
        } else {
            response = sell(limitOrder);
        }
        // PoloniexLimitOrder.
        if (limitOrder instanceof PoloniexLimitOrder) {
            PoloniexLimitOrder raw = (PoloniexLimitOrder) limitOrder;
            raw.setResponse(response);
        }
        return response.getOrderNumber().toString();
    } catch (PoloniexException e) {
        throw PoloniexErrorAdapter.adapt(e);
    }
}
Also used : PoloniexTradeResponse(org.knowm.xchange.poloniex.dto.trade.PoloniexTradeResponse) PoloniexException(org.knowm.xchange.poloniex.dto.PoloniexException) PoloniexLimitOrder(org.knowm.xchange.poloniex.dto.trade.PoloniexLimitOrder)

Example 13 with PoloniexException

use of org.knowm.xchange.poloniex.dto.PoloniexException in project XChange by knowm.

the class PoloniexTradeService method getTradeHistory.

/**
 * @param params Can optionally implement {@link TradeHistoryParamCurrencyPair} and {@link
 *     TradeHistoryParamsTimeSpan}. All other TradeHistoryParams types will be ignored.
 */
@Override
public UserTrades getTradeHistory(TradeHistoryParams params) throws IOException {
    try {
        CurrencyPair currencyPair = null;
        Date startTime = null;
        Date endTime = null;
        if (params instanceof TradeHistoryParamCurrencyPair) {
            currencyPair = ((TradeHistoryParamCurrencyPair) params).getCurrencyPair();
        }
        if (params instanceof TradeHistoryParamsTimeSpan) {
            startTime = ((TradeHistoryParamsTimeSpan) params).getStartTime();
            endTime = ((TradeHistoryParamsTimeSpan) params).getEndTime();
        }
        Integer limit = 500;
        if (params instanceof TradeHistoryParamLimit) {
            TradeHistoryParamLimit tradeHistoryParamLimit = (TradeHistoryParamLimit) params;
            limit = tradeHistoryParamLimit.getLimit();
        }
        return getTradeHistory(currencyPair, DateUtils.toUnixTimeNullSafe(startTime), DateUtils.toUnixTimeNullSafe(endTime), limit);
    } catch (PoloniexException e) {
        throw PoloniexErrorAdapter.adapt(e);
    }
}
Also used : TradeHistoryParamsTimeSpan(org.knowm.xchange.service.trade.params.TradeHistoryParamsTimeSpan) PoloniexException(org.knowm.xchange.poloniex.dto.PoloniexException) Date(java.util.Date) TradeHistoryParamLimit(org.knowm.xchange.service.trade.params.TradeHistoryParamLimit) 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) TradeHistoryParamCurrencyPair(org.knowm.xchange.service.trade.params.TradeHistoryParamCurrencyPair)

Example 14 with PoloniexException

use of org.knowm.xchange.poloniex.dto.PoloniexException in project XChange by knowm.

the class PoloniexTradeService method getOrderTrades.

public UserTrades getOrderTrades(String orderId, CurrencyPair currencyPair) throws IOException {
    try {
        List<UserTrade> trades = new ArrayList<>();
        PoloniexUserTrade[] poloniexUserTrades = returnOrderTrades(orderId);
        if (poloniexUserTrades != null) {
            for (PoloniexUserTrade poloniexUserTrade : poloniexUserTrades) {
                // returnOrderTrades doesn't fill in orderId
                poloniexUserTrade.setOrderNumber(orderId);
                trades.add(PoloniexAdapters.adaptPoloniexUserTrade(poloniexUserTrade, currencyPair));
            }
        }
        return new UserTrades(trades, TradeSortType.SortByTimestamp);
    } catch (PoloniexException e) {
        throw PoloniexErrorAdapter.adapt(e);
    }
}
Also used : UserTrades(org.knowm.xchange.dto.trade.UserTrades) ArrayList(java.util.ArrayList) PoloniexUserTrade(org.knowm.xchange.poloniex.dto.trade.PoloniexUserTrade) UserTrade(org.knowm.xchange.dto.trade.UserTrade) PoloniexUserTrade(org.knowm.xchange.poloniex.dto.trade.PoloniexUserTrade) PoloniexException(org.knowm.xchange.poloniex.dto.PoloniexException)

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