Search in sources :

Example 6 with PoloniexException

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

the class PoloniexErrorAdapterTest method throwIfErrorResponse_unauthorizedStatus.

@Test
public void throwIfErrorResponse_unauthorizedStatus() {
    PoloniexException e = new PoloniexException();
    e.setError("Some error msg");
    e.setHttpStatusCode(403);
    ExchangeException adapted = PoloniexErrorAdapter.adapt(e);
    assertThat(adapted).isExactlyInstanceOf(ExchangeSecurityException.class);
}
Also used : ExchangeException(org.knowm.xchange.exceptions.ExchangeException) PoloniexException(org.knowm.xchange.poloniex.dto.PoloniexException) Test(org.junit.Test)

Example 7 with PoloniexException

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

the class PoloniexAccountService method getFundingHistory.

@Override
public List<FundingRecord> getFundingHistory(TradeHistoryParams params) throws IOException {
    try {
        Date start = null;
        Date end = null;
        if (params instanceof TradeHistoryParamsTimeSpan) {
            start = ((TradeHistoryParamsTimeSpan) params).getStartTime();
            end = ((TradeHistoryParamsTimeSpan) params).getEndTime();
        }
        final PoloniexDepositsWithdrawalsResponse poloFundings = returnDepositsWithdrawals(start, end);
        return PoloniexAdapters.adaptFundingRecords(poloFundings);
    } catch (PoloniexException e) {
        throw PoloniexErrorAdapter.adapt(e);
    }
}
Also used : DefaultTradeHistoryParamsTimeSpan(org.knowm.xchange.service.trade.params.DefaultTradeHistoryParamsTimeSpan) TradeHistoryParamsTimeSpan(org.knowm.xchange.service.trade.params.TradeHistoryParamsTimeSpan) PoloniexDepositsWithdrawalsResponse(org.knowm.xchange.poloniex.dto.trade.PoloniexDepositsWithdrawalsResponse) PoloniexException(org.knowm.xchange.poloniex.dto.PoloniexException) Date(java.util.Date)

Example 8 with PoloniexException

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

the class PoloniexOrderTest method sellRejectTest.

@Test(expected = PoloniexException.class)
public void sellRejectTest() throws Exception {
    InvocationResult invocationResult = new InvocationResult("{\"error\":\"Not enough LTC.\"}", 200);
    Method apiMethod = PoloniexAuthenticated.class.getDeclaredMethod("sell", 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 9 with PoloniexException

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

the class PoloniexOrderTest method moveOrderRejectTest.

@Test(expected = PoloniexException.class)
public void moveOrderRejectTest() throws Exception {
    InvocationResult invocationResult = new InvocationResult("{\"success\":0,\"error\":\"Not enough LTC.\"}", 200);
    Method apiMethod = PoloniexAuthenticated.class.getDeclaredMethod("moveOrder", String.class, ParamsDigest.class, SynchronizedValueFactory.class, String.class, String.class, String.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 10 with PoloniexException

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

the class PoloniexBalanceTest method balanceRejectTest.

@Test(expected = PoloniexException.class)
public void balanceRejectTest() throws Exception {
    InvocationResult invocationResult = new InvocationResult("{\"error\":\"Invalid API key\\/secret pair.\"}", 200);
    Method apiMethod = PoloniexAuthenticated.class.getDeclaredMethod("returnCompleteBalances", String.class, ParamsDigest.class, SynchronizedValueFactory.class, String.class);
    RestMethodMetadata balances = RestMethodMetadata.create(apiMethod, "", "");
    try {
        new JacksonResponseReader(new DefaultJacksonObjectMapperFactory().createObjectMapper(), false).read(invocationResult, balances);
    } catch (PoloniexException e) {
        Assert.assertTrue(e.getMessage().startsWith("Invalid API key/secret pair."));
        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)

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