Search in sources :

Example 1 with TradeHistoryParamCurrencyPair

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

the class OkCoinAccountDemo method fundingHistory.

private static void fundingHistory(AccountService accountService) throws IOException {
    // Get the funds information
    TradeHistoryParams params = accountService.createFundingHistoryParams();
    if (params instanceof TradeHistoryParamPaging) {
        TradeHistoryParamPaging pagingParams = (TradeHistoryParamPaging) params;
        pagingParams.setPageLength(50);
        pagingParams.setPageNumber(1);
    }
    if (params instanceof TradeHistoryParamCurrencyPair) {
        ((TradeHistoryParamCurrencyPair) params).setCurrencyPair(CurrencyPair.BTC_CNY);
    }
    final List<FundingRecord> fundingRecords = accountService.getFundingHistory(params);
    AccountServiceTestUtil.printFundingHistory(fundingRecords);
}
Also used : FundingRecord(org.knowm.xchange.dto.account.FundingRecord) TradeHistoryParams(org.knowm.xchange.service.trade.params.TradeHistoryParams) TradeHistoryParamPaging(org.knowm.xchange.service.trade.params.TradeHistoryParamPaging) TradeHistoryParamCurrencyPair(org.knowm.xchange.service.trade.params.TradeHistoryParamCurrencyPair)

Example 2 with TradeHistoryParamCurrencyPair

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

the class LatokenTradeService method getTradeHistory.

@Override
public UserTrades getTradeHistory(TradeHistoryParams params) throws IOException {
    if (params instanceof TradeHistoryParamCurrencyPair == false) {
        throw new ExchangeException("CurrencyPair must be provided to get user trades.");
    }
    TradeHistoryParamCurrencyPair pairParams = (TradeHistoryParamCurrencyPair) params;
    CurrencyPair pair = pairParams.getCurrencyPair();
    if (pair == null) {
        throw new ExchangeException("CurrencyPair must be provided to get user trades.");
    }
    // Limit is an optional parameter
    Integer limit = null;
    if (params instanceof TradeHistoryParamLimit) {
        TradeHistoryParamLimit limitParams = (TradeHistoryParamLimit) params;
        limit = limitParams.getLimit();
    }
    try {
        LatokenUserTrades latokenTrades = getLatokenUserTrades(pair, limit);
        return LatokenAdapters.adaptUserTrades(this.exchange, latokenTrades);
    } catch (LatokenException e) {
        throw LatokenErrorAdapter.adapt(e);
    }
}
Also used : LatokenException(org.knowm.xchange.latoken.dto.LatokenException) ExchangeException(org.knowm.xchange.exceptions.ExchangeException) TradeHistoryParamLimit(org.knowm.xchange.service.trade.params.TradeHistoryParamLimit) LatokenUserTrades(org.knowm.xchange.latoken.dto.trade.LatokenUserTrades) TradeHistoryParamCurrencyPair(org.knowm.xchange.service.trade.params.TradeHistoryParamCurrencyPair) OpenOrdersParamCurrencyPair(org.knowm.xchange.service.trade.params.orders.OpenOrdersParamCurrencyPair) DefaultOpenOrdersParamCurrencyPair(org.knowm.xchange.service.trade.params.orders.DefaultOpenOrdersParamCurrencyPair) OrderQueryParamCurrencyPair(org.knowm.xchange.service.trade.params.orders.OrderQueryParamCurrencyPair) CurrencyPair(org.knowm.xchange.currency.CurrencyPair) TradeHistoryParamCurrencyPair(org.knowm.xchange.service.trade.params.TradeHistoryParamCurrencyPair)

Example 3 with TradeHistoryParamCurrencyPair

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

the class BitbayTradeService method getTradeHistory.

@Override
public UserTrades getTradeHistory(TradeHistoryParams params) throws IOException {
    CurrencyPair currencyPair = null;
    if (params instanceof TradeHistoryParamCurrencyPair) {
        currencyPair = ((TradeHistoryParamCurrencyPair) params).getCurrencyPair();
    }
    List<Map> response = getBitbayTransactions(currencyPair);
    List<UserTrade> trades = BitbayAdapters.adaptTransactions(response);
    return new UserTrades(trades, Trades.TradeSortType.SortByTimestamp);
}
Also used : UserTrades(org.knowm.xchange.dto.trade.UserTrades) UserTrade(org.knowm.xchange.dto.trade.UserTrade) Map(java.util.Map) CurrencyPair(org.knowm.xchange.currency.CurrencyPair) TradeHistoryParamCurrencyPair(org.knowm.xchange.service.trade.params.TradeHistoryParamCurrencyPair) TradeHistoryParamCurrencyPair(org.knowm.xchange.service.trade.params.TradeHistoryParamCurrencyPair)

Example 4 with TradeHistoryParamCurrencyPair

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

the class CryptopiaTradeService method getTradeHistory.

@Override
public UserTrades getTradeHistory(TradeHistoryParams params) throws IOException {
    try {
        CurrencyPair currencyPair = null;
        Integer limit = 100;
        if (params instanceof TradeHistoryParamCurrencyPair) {
            currencyPair = ((TradeHistoryParamCurrencyPair) params).getCurrencyPair();
        }
        if (params instanceof TradeHistoryParamLimit) {
            limit = ((TradeHistoryParamLimit) params).getLimit();
        }
        return new UserTrades(tradeHistory(currencyPair, limit), Trades.TradeSortType.SortByTimestamp);
    } catch (CryptopiaException e) {
        throw CryptopiaErrorAdapter.adapt(e);
    }
}
Also used : UserTrades(org.knowm.xchange.dto.trade.UserTrades) CryptopiaException(org.knowm.xchange.cryptopia.dto.CryptopiaException) TradeHistoryParamLimit(org.knowm.xchange.service.trade.params.TradeHistoryParamLimit) DefaultOpenOrdersParamCurrencyPair(org.knowm.xchange.service.trade.params.orders.DefaultOpenOrdersParamCurrencyPair) CurrencyPair(org.knowm.xchange.currency.CurrencyPair) OpenOrdersParamCurrencyPair(org.knowm.xchange.service.trade.params.orders.OpenOrdersParamCurrencyPair) TradeHistoryParamCurrencyPair(org.knowm.xchange.service.trade.params.TradeHistoryParamCurrencyPair) TradeHistoryParamCurrencyPair(org.knowm.xchange.service.trade.params.TradeHistoryParamCurrencyPair)

Example 5 with TradeHistoryParamCurrencyPair

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

Aggregations

TradeHistoryParamCurrencyPair (org.knowm.xchange.service.trade.params.TradeHistoryParamCurrencyPair)42 CurrencyPair (org.knowm.xchange.currency.CurrencyPair)34 TradeHistoryParamsTimeSpan (org.knowm.xchange.service.trade.params.TradeHistoryParamsTimeSpan)20 TradeHistoryParamLimit (org.knowm.xchange.service.trade.params.TradeHistoryParamLimit)18 OpenOrdersParamCurrencyPair (org.knowm.xchange.service.trade.params.orders.OpenOrdersParamCurrencyPair)17 UserTrades (org.knowm.xchange.dto.trade.UserTrades)15 DefaultOpenOrdersParamCurrencyPair (org.knowm.xchange.service.trade.params.orders.DefaultOpenOrdersParamCurrencyPair)13 Date (java.util.Date)12 UserTrade (org.knowm.xchange.dto.trade.UserTrade)11 ExchangeException (org.knowm.xchange.exceptions.ExchangeException)11 TradeHistoryParamPaging (org.knowm.xchange.service.trade.params.TradeHistoryParamPaging)11 TradeHistoryParamsIdSpan (org.knowm.xchange.service.trade.params.TradeHistoryParamsIdSpan)10 TradeHistoryParamOffset (org.knowm.xchange.service.trade.params.TradeHistoryParamOffset)9 ArrayList (java.util.ArrayList)8 TradeHistoryParamsSorted (org.knowm.xchange.service.trade.params.TradeHistoryParamsSorted)8 NotAvailableFromExchangeException (org.knowm.xchange.exceptions.NotAvailableFromExchangeException)7 BigDecimal (java.math.BigDecimal)6 CancelOrderByCurrencyPair (org.knowm.xchange.service.trade.params.CancelOrderByCurrencyPair)6 Currency (org.knowm.xchange.currency.Currency)5 OrderType (org.knowm.xchange.dto.Order.OrderType)5