Search in sources :

Example 1 with TradeHistoryParamsIdSpan

use of org.knowm.xchange.service.trade.params.TradeHistoryParamsIdSpan in project XChange by knowm.

the class YoBitTradeService method getTradeHistory.

@Override
public UserTrades getTradeHistory(TradeHistoryParams params) throws IOException {
    Integer count = 1000;
    if (params instanceof TradeHistoryParamLimit) {
        count = ((TradeHistoryParamLimit) params).getLimit();
    }
    Long offset = 0L;
    if (params instanceof TradeHistoryParamOffset) {
        offset = ((TradeHistoryParamOffset) params).getOffset();
    }
    String market = null;
    if (params instanceof TradeHistoryParamCurrencyPair) {
        CurrencyPair currencyPair = ((TradeHistoryParamCurrencyPair) params).getCurrencyPair();
        market = YoBitAdapters.adaptCcyPairToUrlFormat(currencyPair);
    }
    Long fromTransactionId = null;
    Long endTransactionId = null;
    if (params instanceof TradeHistoryParamsIdSpan) {
        TradeHistoryParamsIdSpan tradeHistoryParamsIdSpan = (TradeHistoryParamsIdSpan) params;
        String startId = tradeHistoryParamsIdSpan.getStartId();
        if (startId != null)
            fromTransactionId = Long.valueOf(startId);
        String endId = tradeHistoryParamsIdSpan.getEndId();
        if (endId != null)
            endTransactionId = Long.valueOf(endId);
    }
    String order = "DESC";
    if (params instanceof TradeHistoryParamsSorted) {
        order = ((TradeHistoryParamsSorted) params).getOrder().equals(TradeHistoryParamsSorted.Order.desc) ? "DESC" : "ASC";
    }
    Long fromTimestamp = null;
    Long toTimestamp = null;
    if (params instanceof TradeHistoryParamsTimeSpan) {
        TradeHistoryParamsTimeSpan tradeHistoryParamsTimeSpan = (TradeHistoryParamsTimeSpan) params;
        Date startTime = tradeHistoryParamsTimeSpan.getStartTime();
        if (startTime != null)
            fromTimestamp = DateUtils.toUnixTimeNullSafe(startTime);
        Date endTime = tradeHistoryParamsTimeSpan.getEndTime();
        if (endTime != null)
            toTimestamp = DateUtils.toUnixTimeNullSafe(endTime);
    }
    BaseYoBitResponse response = tradeHistory(count, offset, market, fromTransactionId, endTransactionId, order, fromTimestamp, toTimestamp);
    List<UserTrade> trades = new ArrayList<>();
    if (response.returnData != null) {
        for (Object key : response.returnData.keySet()) {
            Map tradeData = (Map) response.returnData.get(key);
            trades.add(YoBitAdapters.adaptUserTrade(key, tradeData));
        }
    }
    return new UserTrades(trades, Trades.TradeSortType.SortByTimestamp);
}
Also used : TradeHistoryParamOffset(org.knowm.xchange.service.trade.params.TradeHistoryParamOffset) TradeHistoryParamsTimeSpan(org.knowm.xchange.service.trade.params.TradeHistoryParamsTimeSpan) ArrayList(java.util.ArrayList) TradeHistoryParamsIdSpan(org.knowm.xchange.service.trade.params.TradeHistoryParamsIdSpan) UserTrade(org.knowm.xchange.dto.trade.UserTrade) Date(java.util.Date) UserTrades(org.knowm.xchange.dto.trade.UserTrades) TradeHistoryParamsSorted(org.knowm.xchange.service.trade.params.TradeHistoryParamsSorted) BaseYoBitResponse(org.knowm.xchange.yobit.dto.BaseYoBitResponse) Map(java.util.Map) TradeHistoryParamLimit(org.knowm.xchange.service.trade.params.TradeHistoryParamLimit) TradeHistoryParamCurrencyPair(org.knowm.xchange.service.trade.params.TradeHistoryParamCurrencyPair) OpenOrdersParamCurrencyPair(org.knowm.xchange.service.trade.params.orders.OpenOrdersParamCurrencyPair) CurrencyPair(org.knowm.xchange.currency.CurrencyPair) TradeHistoryParamCurrencyPair(org.knowm.xchange.service.trade.params.TradeHistoryParamCurrencyPair)

Example 2 with TradeHistoryParamsIdSpan

use of org.knowm.xchange.service.trade.params.TradeHistoryParamsIdSpan in project XChange by knowm.

the class BTCMarketsTradeService method getTradeHistory.

@Override
public UserTrades getTradeHistory(TradeHistoryParams params) throws IOException {
    Integer limit = 200;
    if (params instanceof TradeHistoryParamPaging) {
        limit = ((TradeHistoryParamPaging) params).getPageLength();
    }
    String after = null;
    if (params instanceof TradeHistoryParamsIdSpan) {
        TradeHistoryParamsIdSpan tradeHistoryParamsIdSpan = (TradeHistoryParamsIdSpan) params;
        after = tradeHistoryParamsIdSpan.getStartId();
    }
    String before = null;
    if (params instanceof TradeHistoryParamsIdSpan) {
        TradeHistoryParamsIdSpan tradeHistoryParamsIdSpan = (TradeHistoryParamsIdSpan) params;
        before = tradeHistoryParamsIdSpan.getEndId();
    }
    CurrencyPair cp = null;
    if (params instanceof TradeHistoryParamCurrencyPair) {
        CurrencyPair paramsCp = ((TradeHistoryParamCurrencyPair) params).getCurrencyPair();
        if (paramsCp != null) {
            cp = paramsCp;
        }
    }
    List<BTCMarketsTradeHistoryResponse> response = getBTCMarketsUserTransactions(cp, before, after, limit);
    return BTCMarketsAdapters.adaptTradeHistory(response);
}
Also used : TradeHistoryParamPaging(org.knowm.xchange.service.trade.params.TradeHistoryParamPaging) TradeHistoryParamsIdSpan(org.knowm.xchange.service.trade.params.TradeHistoryParamsIdSpan) BTCMarketsTradeHistoryResponse(org.knowm.xchange.btcmarkets.dto.v3.trade.BTCMarketsTradeHistoryResponse) 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 3 with TradeHistoryParamsIdSpan

use of org.knowm.xchange.service.trade.params.TradeHistoryParamsIdSpan in project XChange by knowm.

the class MercadoBitcoinTradeService method getTradeHistory.

/**
 * @param params Required parameter types: {@link TradeHistoryParamCurrencyPair}. Supported types:
 *     {@link TradeHistoryParamsIdSpan}, {@link TradeHistoryParamsTimeSpan}.
 */
@Override
public UserTrades getTradeHistory(TradeHistoryParams params) throws IOException {
    CurrencyPair pair = ((TradeHistoryParamCurrencyPair) params).getCurrencyPair();
    String fromId = null;
    String toId = null;
    if (params instanceof TradeHistoryParamsIdSpan) {
        TradeHistoryParamsIdSpan paramsIdSpan = (TradeHistoryParamsIdSpan) params;
        fromId = paramsIdSpan.getStartId();
        toId = paramsIdSpan.getEndId();
    }
    Long fromDate = null;
    Long toDate = null;
    if (params instanceof TradeHistoryParamsTimeSpan) {
        TradeHistoryParamsTimeSpan paramsTimeSpan = (TradeHistoryParamsTimeSpan) params;
        fromDate = toUnixTimeNullSafe(paramsTimeSpan.getStartTime());
        toDate = toUnixTimeNullSafe(paramsTimeSpan.getEndTime());
    }
    MercadoBitcoinBaseTradeApiResult<MercadoBitcoinUserOrders> orders = getMercadoBitcoinUserOrders(MercadoBitcoinAdapters.adaptCurrencyPair(pair), null, /* all */
    null, fromId, toId, fromDate, toDate);
    return MercadoBitcoinAdapters.toUserTrades(pair, orders);
}
Also used : TradeHistoryParamsTimeSpan(org.knowm.xchange.service.trade.params.TradeHistoryParamsTimeSpan) MercadoBitcoinUserOrders(org.knowm.xchange.mercadobitcoin.dto.trade.MercadoBitcoinUserOrders) TradeHistoryParamsIdSpan(org.knowm.xchange.service.trade.params.TradeHistoryParamsIdSpan) DefaultTradeHistoryParamCurrencyPair(org.knowm.xchange.service.trade.params.DefaultTradeHistoryParamCurrencyPair) CurrencyPair(org.knowm.xchange.currency.CurrencyPair) TradeHistoryParamCurrencyPair(org.knowm.xchange.service.trade.params.TradeHistoryParamCurrencyPair) DefaultTradeHistoryParamCurrencyPair(org.knowm.xchange.service.trade.params.DefaultTradeHistoryParamCurrencyPair) TradeHistoryParamCurrencyPair(org.knowm.xchange.service.trade.params.TradeHistoryParamCurrencyPair)

Example 4 with TradeHistoryParamsIdSpan

use of org.knowm.xchange.service.trade.params.TradeHistoryParamsIdSpan 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 5 with TradeHistoryParamsIdSpan

use of org.knowm.xchange.service.trade.params.TradeHistoryParamsIdSpan in project XChange by knowm.

the class DeribitTradeService method getTradeHistory.

@Override
public UserTrades getTradeHistory(TradeHistoryParams params) throws IOException {
    String instrumentName = null;
    if (params instanceof TradeHistoryParamInstrument) {
        Instrument instrument = ((TradeHistoryParamInstrument) params).getInstrument();
        if (instrument != null) {
            instrumentName = DeribitAdapters.adaptInstrumentName(instrument);
        }
    }
    String currency = null;
    // not implemented
    Kind kind = null;
    if (params instanceof TradeHistoryParamCurrencyPair) {
        CurrencyPair currencyPair = ((TradeHistoryParamCurrencyPair) params).getCurrencyPair();
        if (currencyPair != null) {
            currency = currencyPair.base.getCurrencyCode();
        }
    }
    Date startTime = null;
    Date endTime = null;
    if (params instanceof TradeHistoryParamsTimeSpan) {
        startTime = ((TradeHistoryParamsTimeSpan) params).getStartTime();
        endTime = ((TradeHistoryParamsTimeSpan) params).getEndTime();
    }
    String startId = null;
    String endId = null;
    if (params instanceof TradeHistoryParamsIdSpan) {
        startId = ((TradeHistoryParamsIdSpan) params).getStartId();
        endId = ((TradeHistoryParamsIdSpan) params).getEndId();
    }
    Integer limit = null;
    if (params instanceof TradeHistoryParamLimit) {
        limit = ((TradeHistoryParamLimit) params).getLimit();
    }
    String sorting = null;
    if (params instanceof TradeHistoryParamsSorted) {
        TradeHistoryParamsSorted.Order order = ((TradeHistoryParamsSorted) params).getOrder();
        sorting = order == TradeHistoryParamsSorted.Order.asc ? "asc" : order == TradeHistoryParamsSorted.Order.desc ? "desc" : null;
    }
    Boolean includeOld = null;
    if (params instanceof DeribitTradeHistoryParamsOld) {
        includeOld = ((DeribitTradeHistoryParamsOld) params).isIncludeOld();
    }
    org.knowm.xchange.deribit.v2.dto.trade.UserTrades userTrades = null;
    if (startTime != null && endTime != null) {
        if (instrumentName != null) {
            userTrades = super.getUserTradesByInstrumentAndTime(instrumentName, startTime, endTime, limit, includeOld, sorting);
        } else if (currency != null) {
            userTrades = super.getUserTradesByCurrencyAndTime(currency, kind, startTime, endTime, limit, includeOld, sorting);
        }
    } else {
        if (instrumentName != null) {
            Integer startSeq = startId != null ? Integer.valueOf(startId) : null;
            Integer endSeq = endId != null ? Integer.valueOf(endId) : null;
            userTrades = super.getUserTradesByInstrument(instrumentName, startSeq, endSeq, limit, includeOld, sorting);
        } else if (currency != null) {
            userTrades = super.getUserTradesByCurrency(currency, kind, startId, endId, limit, includeOld, sorting);
        }
    }
    if (userTrades == null) {
        throw new ExchangeException("You should specify either instrument or currency pair");
    }
    return DeribitAdapters.adaptUserTrades(userTrades);
}
Also used : TradeHistoryParamsTimeSpan(org.knowm.xchange.service.trade.params.TradeHistoryParamsTimeSpan) DeribitExchange(org.knowm.xchange.deribit.v2.DeribitExchange) TradeHistoryParamsIdSpan(org.knowm.xchange.service.trade.params.TradeHistoryParamsIdSpan) Date(java.util.Date) TradeHistoryParamInstrument(org.knowm.xchange.service.trade.params.TradeHistoryParamInstrument) Kind(org.knowm.xchange.deribit.v2.dto.Kind) OpenOrdersParamInstrument(org.knowm.xchange.service.trade.params.orders.OpenOrdersParamInstrument) DefaultOpenOrdersParamInstrument(org.knowm.xchange.service.trade.params.orders.DefaultOpenOrdersParamInstrument) TradeHistoryParamInstrument(org.knowm.xchange.service.trade.params.TradeHistoryParamInstrument) Instrument(org.knowm.xchange.instrument.Instrument) TradeHistoryParamsSorted(org.knowm.xchange.service.trade.params.TradeHistoryParamsSorted) 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) OpenOrdersParamCurrencyPair(org.knowm.xchange.service.trade.params.orders.OpenOrdersParamCurrencyPair) CurrencyPair(org.knowm.xchange.currency.CurrencyPair) TradeHistoryParamCurrencyPair(org.knowm.xchange.service.trade.params.TradeHistoryParamCurrencyPair)

Aggregations

TradeHistoryParamsIdSpan (org.knowm.xchange.service.trade.params.TradeHistoryParamsIdSpan)11 TradeHistoryParamCurrencyPair (org.knowm.xchange.service.trade.params.TradeHistoryParamCurrencyPair)10 CurrencyPair (org.knowm.xchange.currency.CurrencyPair)9 TradeHistoryParamsTimeSpan (org.knowm.xchange.service.trade.params.TradeHistoryParamsTimeSpan)9 OpenOrdersParamCurrencyPair (org.knowm.xchange.service.trade.params.orders.OpenOrdersParamCurrencyPair)7 DefaultOpenOrdersParamCurrencyPair (org.knowm.xchange.service.trade.params.orders.DefaultOpenOrdersParamCurrencyPair)5 Date (java.util.Date)4 ExchangeException (org.knowm.xchange.exceptions.ExchangeException)4 TradeHistoryParamLimit (org.knowm.xchange.service.trade.params.TradeHistoryParamLimit)4 TradeHistoryParamOffset (org.knowm.xchange.service.trade.params.TradeHistoryParamOffset)4 TradeHistoryParamsSorted (org.knowm.xchange.service.trade.params.TradeHistoryParamsSorted)4 ArrayList (java.util.ArrayList)3 UserTrade (org.knowm.xchange.dto.trade.UserTrade)3 UserTrades (org.knowm.xchange.dto.trade.UserTrades)3 NotAvailableFromExchangeException (org.knowm.xchange.exceptions.NotAvailableFromExchangeException)3 IOException (java.io.IOException)2 Collection (java.util.Collection)2 List (java.util.List)2 Collectors (java.util.stream.Collectors)2 Order (org.knowm.xchange.dto.Order)2