use of org.knowm.xchange.bitfinex.dto.BitfinexException in project XChange by knowm.
the class BitfinexTradeService method getTradeHistory.
/**
* @param params Implementation of {@link TradeHistoryParamCurrencyPair} is mandatory. Can
* optionally implement {@link TradeHistoryParamPaging} and {@link
* TradeHistoryParamsTimeSpan#getStartTime()}. All other TradeHistoryParams types will be
* ignored.
*/
@Override
public UserTrades getTradeHistory(TradeHistoryParams params) throws IOException {
try {
String symbol = null;
if (params instanceof TradeHistoryParamCurrencyPair && ((TradeHistoryParamCurrencyPair) params).getCurrencyPair() != null) {
symbol = BitfinexAdapters.adaptCurrencyPair(((TradeHistoryParamCurrencyPair) params).getCurrencyPair());
}
Long startTime = 0L;
Long endTime = null;
Long limit = 50L;
Long sort = null;
if (params instanceof TradeHistoryParamsTimeSpan) {
TradeHistoryParamsTimeSpan paramsTimeSpan = (TradeHistoryParamsTimeSpan) params;
startTime = DateUtils.toMillisNullSafe(paramsTimeSpan.getStartTime());
endTime = DateUtils.toMillisNullSafe(paramsTimeSpan.getEndTime());
}
if (params instanceof TradeHistoryParamLimit) {
TradeHistoryParamLimit tradeHistoryParamLimit = (TradeHistoryParamLimit) params;
if (tradeHistoryParamLimit.getLimit() != null) {
limit = Long.valueOf(tradeHistoryParamLimit.getLimit());
}
}
if (params instanceof TradeHistoryParamsSorted) {
TradeHistoryParamsSorted tradeHistoryParamsSorted = (TradeHistoryParamsSorted) params;
sort = tradeHistoryParamsSorted.getOrder() == TradeHistoryParamsSorted.Order.asc ? 1L : -1L;
}
final List<Trade> trades = getBitfinexTradesV2(symbol, startTime, endTime, limit, sort);
return BitfinexAdapters.adaptTradeHistoryV2(trades);
} catch (BitfinexException e) {
throw BitfinexErrorAdapter.adapt(e);
}
}
use of org.knowm.xchange.bitfinex.dto.BitfinexException in project XChange by knowm.
the class BitfinexTradeService method getOrder.
@Override
public Collection<Order> getOrder(String... orderIds) throws IOException {
try {
List<Order> openOrders = new ArrayList<>();
for (String orderId : orderIds) {
BitfinexOrderStatusResponse orderStatus = getBitfinexOrderStatus(orderId);
BitfinexOrderStatusResponse[] orderStatuses = new BitfinexOrderStatusResponse[1];
if (orderStatus != null) {
orderStatuses[0] = orderStatus;
OpenOrders orders = BitfinexAdapters.adaptOrders(orderStatuses);
openOrders.add(orders.getOpenOrders().get(0));
}
}
return openOrders;
} catch (BitfinexException e) {
throw BitfinexErrorAdapter.adapt(e);
}
}
use of org.knowm.xchange.bitfinex.dto.BitfinexException in project XChange by knowm.
the class BitfinexTradeService method changeOrder.
@Override
public String changeOrder(LimitOrder order) throws IOException {
boolean useRemaining = order.getOriginalAmount() == null || order.hasFlag(BitfinexOrderFlags.USE_REMAINING);
BitfinexReplaceOrderRequest request = new BitfinexReplaceOrderRequest(String.valueOf(exchange.getNonceFactory().createValue()), Long.valueOf(order.getId()), BitfinexAdapters.adaptCurrencyPair(order.getCurrencyPair()), order.getOriginalAmount(), order.getLimitPrice(), "bitfinex", BitfinexAdapters.adaptOrderType(order.getType()), BitfinexAdapters.adaptOrderFlagsToType(order.getOrderFlags()).getValue(), order.hasFlag(BitfinexOrderFlags.HIDDEN), order.hasFlag(BitfinexOrderFlags.POST_ONLY), useRemaining);
try {
BitfinexOrderStatusResponse response = bitfinex.replaceOrder(apiKey, payloadCreator, signatureCreator, request);
return String.valueOf(response.getId());
} catch (BitfinexException e) {
throw BitfinexErrorAdapter.adapt(e);
}
}
Aggregations