Search in sources :

Example 26 with ExchangeException

use of org.knowm.xchange.exceptions.ExchangeException in project XChange by knowm.

the class EXXTradeService method cancelOrder.

@Override
public boolean cancelOrder(CancelOrderParams cancelOrderParams) throws IOException {
    if (!(cancelOrderParams instanceof CancelOrderParams) && !(cancelOrderParams instanceof EXXCancelOrderByCurrencyPair)) {
        throw new ExchangeException("You need to provide the currency pair and the order id to cancel an order.");
    }
    EXXCancelOrderByCurrencyPair params = (EXXCancelOrderByCurrencyPair) cancelOrderParams;
    CurrencyPair currencyPair = params.getCurrencyPair();
    // etp_btc
    String currency = currencyPairFormat(currencyPair);
    return cancelExxOrder(params.getId(), currency);
}
Also used : CancelOrderParams(org.knowm.xchange.service.trade.params.CancelOrderParams) EXXCancelOrderByCurrencyPair(org.knowm.xchange.exx.dto.params.EXXCancelOrderByCurrencyPair) ExchangeException(org.knowm.xchange.exceptions.ExchangeException) EXXCancelOrderByCurrencyPair(org.knowm.xchange.exx.dto.params.EXXCancelOrderByCurrencyPair) CurrencyPair(org.knowm.xchange.currency.CurrencyPair)

Example 27 with ExchangeException

use of org.knowm.xchange.exceptions.ExchangeException in project XChange by knowm.

the class LunoTradeService method getTradeHistory.

@Override
public UserTrades getTradeHistory(TradeHistoryParams params) throws ExchangeException, IOException {
    if (!(params instanceof TradeHistoryParamCurrencyPair)) {
        throw new ExchangeException("THe currency pair is mandatory in order to get user trades.");
    }
    CurrencyPair currencyPair = ((TradeHistoryParamCurrencyPair) params).getCurrencyPair();
    Long since = null;
    if (params instanceof TradeHistoryParamsTimeSpan) {
        since = ((TradeHistoryParamsTimeSpan) params).getStartTime().getTime();
    }
    Integer limit = null;
    if (params instanceof TradeHistoryParamLimit) {
        limit = ((TradeHistoryParamLimit) params).getLimit();
    }
    LunoUserTrades lunoTrades = lunoAPI.listTrades(LunoUtil.toLunoPair(currencyPair), since, limit);
    List<UserTrade> trades = new ArrayList<>();
    for (org.knowm.xchange.luno.dto.trade.LunoUserTrades.UserTrade t : lunoTrades.getTrades()) {
        final CurrencyPair pair = LunoUtil.fromLunoPair(t.pair);
        // currently there is no trade id!
        final String tradeId = null;
        final BigDecimal feeAmount;
        final Currency feeCurrency;
        if (t.feeBase.compareTo(BigDecimal.ZERO) > 0) {
            feeAmount = t.feeBase;
            feeCurrency = pair.base;
        } else {
            feeAmount = t.feeCounter;
            feeCurrency = pair.counter;
        }
        trades.add(new UserTrade.Builder().type(t.buy ? OrderType.BID : OrderType.ASK).originalAmount(t.volume).currencyPair(pair).price(t.price).timestamp(t.getTimestamp()).id(tradeId).orderId(t.orderId).feeAmount(feeAmount).feeCurrency(feeCurrency).build());
    }
    return new UserTrades(trades, TradeSortType.SortByTimestamp);
}
Also used : TradeHistoryParamsTimeSpan(org.knowm.xchange.service.trade.params.TradeHistoryParamsTimeSpan) LunoUserTrades(org.knowm.xchange.luno.dto.trade.LunoUserTrades) ArrayList(java.util.ArrayList) Exchange(org.knowm.xchange.Exchange) UserTrade(org.knowm.xchange.dto.trade.UserTrade) BigDecimal(java.math.BigDecimal) UserTrades(org.knowm.xchange.dto.trade.UserTrades) LunoUserTrades(org.knowm.xchange.luno.dto.trade.LunoUserTrades) Currency(org.knowm.xchange.currency.Currency) NotAvailableFromExchangeException(org.knowm.xchange.exceptions.NotAvailableFromExchangeException) NotYetImplementedForExchangeException(org.knowm.xchange.exceptions.NotYetImplementedForExchangeException) ExchangeException(org.knowm.xchange.exceptions.ExchangeException) TradeHistoryParamLimit(org.knowm.xchange.service.trade.params.TradeHistoryParamLimit) TradeHistoryParamCurrencyPair(org.knowm.xchange.service.trade.params.TradeHistoryParamCurrencyPair) CurrencyPair(org.knowm.xchange.currency.CurrencyPair) TradeHistoryParamCurrencyPair(org.knowm.xchange.service.trade.params.TradeHistoryParamCurrencyPair)

Example 28 with ExchangeException

use of org.knowm.xchange.exceptions.ExchangeException in project XChange by knowm.

the class TheRockTradeService method getTradeHistory.

@Override
public UserTrades getTradeHistory(TradeHistoryParams params) throws IOException {
    if (!(params instanceof TradeHistoryParamCurrencyPair)) {
        throw new ExchangeException("TheRock API recquires " + TradeHistoryParamCurrencyPair.class);
    }
    TradeHistoryParamCurrencyPair pairParams = (TradeHistoryParamCurrencyPair) params;
    // get all trades starting from a specific trade_id
    Long sinceTradeId = null;
    if (params instanceof TradeHistoryParamsIdSpan) {
        TradeHistoryParamsIdSpan trId = (TradeHistoryParamsIdSpan) params;
        try {
            sinceTradeId = Long.valueOf(trId.getStartId());
        } catch (Throwable ignored) {
        }
    }
    Date after = null;
    Date before = null;
    if (params instanceof TradeHistoryParamsTimeSpan) {
        TradeHistoryParamsTimeSpan time = (TradeHistoryParamsTimeSpan) params;
        after = time.getStartTime();
        before = time.getEndTime();
    }
    int pageLength = 200;
    int page = 0;
    if (params instanceof TradeHistoryParamPaging) {
        TradeHistoryParamPaging tradeHistoryParamPaging = (TradeHistoryParamPaging) params;
        pageLength = tradeHistoryParamPaging.getPageLength();
        page = tradeHistoryParamPaging.getPageNumber();
    }
    return TheRockAdapters.adaptUserTrades(getTheRockUserTrades(pairParams.getCurrencyPair(), sinceTradeId, after, before, pageLength, page), pairParams.getCurrencyPair());
}
Also used : TradeHistoryParamsTimeSpan(org.knowm.xchange.service.trade.params.TradeHistoryParamsTimeSpan) NotAvailableFromExchangeException(org.knowm.xchange.exceptions.NotAvailableFromExchangeException) ExchangeException(org.knowm.xchange.exceptions.ExchangeException) TradeHistoryParamPaging(org.knowm.xchange.service.trade.params.TradeHistoryParamPaging) TradeHistoryParamsIdSpan(org.knowm.xchange.service.trade.params.TradeHistoryParamsIdSpan) Date(java.util.Date) TradeHistoryParamCurrencyPair(org.knowm.xchange.service.trade.params.TradeHistoryParamCurrencyPair)

Example 29 with ExchangeException

use of org.knowm.xchange.exceptions.ExchangeException in project XChange by knowm.

the class BleutradeMarketDataServiceRaw method getBleutradeMarketHistory.

public List<BleutradeTrade> getBleutradeMarketHistory(CurrencyPair currencyPair, int count) throws IOException {
    String pairString = BleutradeUtils.toPairString(currencyPair);
    BleutradeMarketHistoryReturn response = bleutrade.getBleutradeMarketHistory(pairString, count);
    if (!response.getSuccess()) {
        throw new ExchangeException(response.getMessage());
    }
    return response.getResult();
}
Also used : BleutradeMarketHistoryReturn(org.knowm.xchange.bleutrade.dto.marketdata.BleutradeMarketHistoryReturn) ExchangeException(org.knowm.xchange.exceptions.ExchangeException)

Example 30 with ExchangeException

use of org.knowm.xchange.exceptions.ExchangeException in project XChange by knowm.

the class BleutradeTradeServiceRaw method sellLimit.

public String sellLimit(LimitOrder limitOrder) throws IOException {
    try {
        String pairString = BleutradeUtils.toPairString(limitOrder.getCurrencyPair());
        BleutradePlaceOrderReturn response = bleutrade.sellLimit(apiKey, signatureCreator, exchange.getNonceFactory(), pairString, limitOrder.getOriginalAmount().toPlainString(), limitOrder.getLimitPrice().toPlainString());
        if (!response.getSuccess()) {
            throw new ExchangeException(response.getMessage());
        }
        return response.getResult().getOrderid();
    } catch (BleutradeException e) {
        throw new ExchangeException(e);
    }
}
Also used : BleutradePlaceOrderReturn(org.knowm.xchange.bleutrade.dto.trade.BleutradePlaceOrderReturn) BleutradeException(org.knowm.xchange.bleutrade.BleutradeException) ExchangeException(org.knowm.xchange.exceptions.ExchangeException)

Aggregations

ExchangeException (org.knowm.xchange.exceptions.ExchangeException)138 CurrencyPair (org.knowm.xchange.currency.CurrencyPair)30 IOException (java.io.IOException)17 BiboxException (org.knowm.xchange.bibox.BiboxException)16 NotAvailableFromExchangeException (org.knowm.xchange.exceptions.NotAvailableFromExchangeException)16 TradeHistoryParamCurrencyPair (org.knowm.xchange.service.trade.params.TradeHistoryParamCurrencyPair)16 BigDecimal (java.math.BigDecimal)15 Currency (org.knowm.xchange.currency.Currency)15 LimitOrder (org.knowm.xchange.dto.trade.LimitOrder)15 ArrayList (java.util.ArrayList)13 List (java.util.List)13 OpenOrdersParamCurrencyPair (org.knowm.xchange.service.trade.params.orders.OpenOrdersParamCurrencyPair)13 Exchange (org.knowm.xchange.Exchange)11 CancelOrderByCurrencyPair (org.knowm.xchange.service.trade.params.CancelOrderByCurrencyPair)11 CancelOrderByIdParams (org.knowm.xchange.service.trade.params.CancelOrderByIdParams)11 Collectors (java.util.stream.Collectors)10 DefaultOpenOrdersParamCurrencyPair (org.knowm.xchange.service.trade.params.orders.DefaultOpenOrdersParamCurrencyPair)10 Test (org.junit.Test)9 NotYetImplementedForExchangeException (org.knowm.xchange.exceptions.NotYetImplementedForExchangeException)9 Date (java.util.Date)8