Search in sources :

Example 1 with TradeHistoryParamOffset

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

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

the class ExmoTradeService method getTradeHistory.

@Override
public UserTrades getTradeHistory(TradeHistoryParams params) throws IOException {
    Integer limit = 10000;
    Long offset = 0L;
    List<CurrencyPair> currencyPairs = new ArrayList<>();
    if (params instanceof ExmoTradeHistoryParams) {
        ExmoTradeHistoryParams exmoTradeHistoryParams = (ExmoTradeHistoryParams) params;
        currencyPairs.addAll(exmoTradeHistoryParams.getCurrencyPairs());
    } else if (params instanceof TradeHistoryParamCurrencyPair) {
        TradeHistoryParamCurrencyPair tradeHistoryParamCurrencyPair = (TradeHistoryParamCurrencyPair) params;
        currencyPairs.add(tradeHistoryParamCurrencyPair.getCurrencyPair());
    }
    if (params instanceof TradeHistoryParamLimit) {
        limit = ((TradeHistoryParamLimit) params).getLimit();
    }
    if (params instanceof TradeHistoryParamOffset) {
        offset = ((TradeHistoryParamOffset) params).getOffset();
    }
    List<UserTrade> trades = trades(limit, offset, currencyPairs);
    return new UserTrades(trades, Trades.TradeSortType.SortByTimestamp);
}
Also used : ExmoUserTrades(org.knowm.xchange.exmo.dto.trade.ExmoUserTrades) UserTrades(org.knowm.xchange.dto.trade.UserTrades) TradeHistoryParamOffset(org.knowm.xchange.service.trade.params.TradeHistoryParamOffset) ArrayList(java.util.ArrayList) ExmoTradeHistoryParams(org.knowm.xchange.exmo.dto.trade.ExmoTradeHistoryParams) UserTrade(org.knowm.xchange.dto.trade.UserTrade) TradeHistoryParamLimit(org.knowm.xchange.service.trade.params.TradeHistoryParamLimit) 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 TradeHistoryParamOffset

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

the class HitbtcTradeService method getTradeHistory.

/**
 * Required parameters: {@link TradeHistoryParamPaging} {@link TradeHistoryParamCurrencyPair}
 */
@Override
public UserTrades getTradeHistory(TradeHistoryParams params) throws IOException {
    Integer limit = 1000;
    long offset = 0;
    if (params instanceof TradeHistoryParamLimit) {
        limit = ((TradeHistoryParamLimit) params).getLimit();
    }
    if (params instanceof TradeHistoryParamOffset) {
        TradeHistoryParamOffset tradeHistoryParamOffset = (TradeHistoryParamOffset) params;
        offset = tradeHistoryParamOffset.getOffset();
    }
    String symbol = null;
    if (params instanceof TradeHistoryParamCurrencyPair) {
        CurrencyPair pair = ((TradeHistoryParamCurrencyPair) params).getCurrencyPair();
        symbol = HitbtcAdapters.adaptCurrencyPair(pair);
    }
    List<HitbtcOwnTrade> tradeHistoryRaw = getTradeHistoryRaw(symbol, limit, offset);
    return HitbtcAdapters.adaptTradeHistory(tradeHistoryRaw);
}
Also used : TradeHistoryParamOffset(org.knowm.xchange.service.trade.params.TradeHistoryParamOffset) HitbtcOwnTrade(org.knowm.xchange.hitbtc.v2.dto.HitbtcOwnTrade) TradeHistoryParamLimit(org.knowm.xchange.service.trade.params.TradeHistoryParamLimit) TradeHistoryParamCurrencyPair(org.knowm.xchange.service.trade.params.TradeHistoryParamCurrencyPair) OrderQueryParamCurrencyPair(org.knowm.xchange.service.trade.params.orders.OrderQueryParamCurrencyPair) CurrencyPair(org.knowm.xchange.currency.CurrencyPair) TradeHistoryParamCurrencyPair(org.knowm.xchange.service.trade.params.TradeHistoryParamCurrencyPair)

Example 4 with TradeHistoryParamOffset

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

the class HitbtcAccountService method getFundingHistory.

@Override
public List<FundingRecord> getFundingHistory(TradeHistoryParams params) throws IOException {
    List<HitbtcTransaction> transactions;
    String currencyCode = null;
    Integer limit = 1000;
    Integer offset = 0;
    if (params instanceof TradeHistoryParamCurrency) {
        Currency currency = ((TradeHistoryParamCurrency) params).getCurrency();
        currencyCode = currency != null ? currency.getCurrencyCode() : null;
    }
    if (params instanceof TradeHistoryParamLimit) {
        limit = ((TradeHistoryParamLimit) params).getLimit();
    }
    if (params instanceof TradeHistoryParamOffset) {
        offset = ((TradeHistoryParamOffset) params).getOffset().intValue();
    }
    transactions = getTransactions(currencyCode, limit, offset);
    List<FundingRecord> records = new ArrayList<>();
    for (HitbtcTransaction transaction : transactions) {
        records.add(HitbtcAdapters.adapt(transaction));
    }
    return records;
}
Also used : TradeHistoryParamOffset(org.knowm.xchange.service.trade.params.TradeHistoryParamOffset) TradeHistoryParamCurrency(org.knowm.xchange.service.trade.params.TradeHistoryParamCurrency) Currency(org.knowm.xchange.currency.Currency) FundingRecord(org.knowm.xchange.dto.account.FundingRecord) ArrayList(java.util.ArrayList) HitbtcTransaction(org.knowm.xchange.hitbtc.v2.dto.HitbtcTransaction) TradeHistoryParamCurrency(org.knowm.xchange.service.trade.params.TradeHistoryParamCurrency) TradeHistoryParamLimit(org.knowm.xchange.service.trade.params.TradeHistoryParamLimit)

Example 5 with TradeHistoryParamOffset

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

the class LivecoinAccountService method getFundingHistory.

@Override
public List<FundingRecord> getFundingHistory(TradeHistoryParams params) throws IOException {
    try {
        Date start = new Date(0);
        Date end = new Date();
        if (params instanceof TradeHistoryParamsTimeSpan) {
            TradeHistoryParamsTimeSpan tradeHistoryParamsTimeSpan = (TradeHistoryParamsTimeSpan) params;
            start = tradeHistoryParamsTimeSpan.getStartTime();
            end = tradeHistoryParamsTimeSpan.getEndTime();
        }
        Long offset = 0L;
        if (params instanceof TradeHistoryParamOffset) {
            offset = ((TradeHistoryParamOffset) params).getOffset();
        }
        Integer limit = 100;
        if (params instanceof TradeHistoryParamLimit) {
            limit = ((TradeHistoryParamLimit) params).getLimit();
        }
        List<Map> fundingRaw = funding(start, end, limit, offset);
        return fundingRaw.stream().map(LivecoinAdapters::adaptFundingRecord).collect(Collectors.toList());
    } catch (LivecoinException e) {
        throw LivecoinErrorAdapter.adapt(e);
    }
}
Also used : TradeHistoryParamsTimeSpan(org.knowm.xchange.service.trade.params.TradeHistoryParamsTimeSpan) TradeHistoryParamOffset(org.knowm.xchange.service.trade.params.TradeHistoryParamOffset) LivecoinException(org.knowm.xchange.livecoin.dto.LivecoinException) Map(java.util.Map) Date(java.util.Date) TradeHistoryParamLimit(org.knowm.xchange.service.trade.params.TradeHistoryParamLimit)

Aggregations

TradeHistoryParamOffset (org.knowm.xchange.service.trade.params.TradeHistoryParamOffset)19 TradeHistoryParamLimit (org.knowm.xchange.service.trade.params.TradeHistoryParamLimit)15 TradeHistoryParamCurrencyPair (org.knowm.xchange.service.trade.params.TradeHistoryParamCurrencyPair)9 TradeHistoryParamsTimeSpan (org.knowm.xchange.service.trade.params.TradeHistoryParamsTimeSpan)9 ArrayList (java.util.ArrayList)8 CurrencyPair (org.knowm.xchange.currency.CurrencyPair)8 TradeHistoryParamsSorted (org.knowm.xchange.service.trade.params.TradeHistoryParamsSorted)6 Date (java.util.Date)5 Currency (org.knowm.xchange.currency.Currency)5 FundingRecord (org.knowm.xchange.dto.account.FundingRecord)5 UserTrades (org.knowm.xchange.dto.trade.UserTrades)5 UserTrade (org.knowm.xchange.dto.trade.UserTrade)4 TradeHistoryParamsIdSpan (org.knowm.xchange.service.trade.params.TradeHistoryParamsIdSpan)4 OpenOrdersParamCurrencyPair (org.knowm.xchange.service.trade.params.orders.OpenOrdersParamCurrencyPair)4 TradeHistoryParamCurrency (org.knowm.xchange.service.trade.params.TradeHistoryParamCurrency)3 Map (java.util.Map)2 LivecoinException (org.knowm.xchange.livecoin.dto.LivecoinException)2 PaymiumOrder (org.knowm.xchange.paymium.dto.account.PaymiumOrder)2 DefaultTradeHistoryParamsTimeSpan (org.knowm.xchange.service.trade.params.DefaultTradeHistoryParamsTimeSpan)2 TradeHistoryParamPaging (org.knowm.xchange.service.trade.params.TradeHistoryParamPaging)2