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