@Override
  public UserTrades getTradeHistory(TradeHistoryParams params) throws IOException {
    try {
      final String symbol;
      if (params instanceof TradeHistoryParamCurrencyPair
          && ((TradeHistoryParamCurrencyPair) params).getCurrencyPair() != null) {
        symbol =
            BitfinexAdapters.adaptCurrencyPair(
                ((TradeHistoryParamCurrencyPair) params).getCurrencyPair());
      } else {
        // Exchange will return the errors below if CurrencyPair is not provided.
        // field not on request: "Key symbol was not present."
        // field supplied but blank: "Key symbol may not be the empty string"
        throw new ExchangeException("CurrencyPair must be supplied");
      }

      long startTime = 0;
      Long endTime = null;
      Integer limit = 50;

      if (params instanceof TradeHistoryParamsTimeSpan) {
        TradeHistoryParamsTimeSpan paramsTimeSpan = (TradeHistoryParamsTimeSpan) params;
        startTime = DateUtils.toUnixTimeNullSafe(paramsTimeSpan.getStartTime());
        endTime = DateUtils.toUnixTimeNullSafe(paramsTimeSpan.getEndTime());
      }

      if (params instanceof TradeHistoryParamPaging) {
        TradeHistoryParamPaging pagingParams = (TradeHistoryParamPaging) params;
        Integer pageLength = pagingParams.getPageLength();
        Integer pageNum = pagingParams.getPageNumber();
        limit = (pageLength != null && pageNum != null) ? pageLength * (pageNum + 1) : 50;
      }

      if (params instanceof TradeHistoryParamLimit) {
        TradeHistoryParamLimit tradeHistoryParamLimit = (TradeHistoryParamLimit) params;
        limit = tradeHistoryParamLimit.getLimit();
      }

      final BitfinexTradeResponse[] trades =
          getBitfinexTradeHistory(symbol, startTime, endTime, limit, null);
      return BitfinexAdapters.adaptTradeHistory(trades, symbol);
    } catch (BitfinexException e) {
      throw BitfinexErrorAdapter.adapt(e);
    }
  }
@ Override public UserTrades getTradeHistory ( TradeHistoryParams params ) throws IOException { try { final String symbol ; if ( params instanceof TradeHistoryParamCurrencyPair && ( ( TradeHistoryParamCurrencyPair ) params ) . getCurrencyPair ( ) != null ) { symbol = BitfinexAdapters . adaptCurrencyPair ( ( ( TradeHistoryParamCurrencyPair ) params ) . getCurrencyPair ( ) ) ; } else { throw new ExchangeException ( "CurrencyPair must be supplied" ) ; } long startTime = 0 ; Long endTime = null ; Integer limit = 50 ; if ( params instanceof TradeHistoryParamsTimeSpan ) { TradeHistoryParamsTimeSpan paramsTimeSpan = ( TradeHistoryParamsTimeSpan ) params ; startTime = DateUtils . toUnixTimeNullSafe ( paramsTimeSpan . getStartTime ( ) ) ; endTime = DateUtils . toUnixTimeNullSafe ( paramsTimeSpan . getEndTime ( ) ) ; } if ( params instanceof TradeHistoryParamPaging ) { TradeHistoryParamPaging pagingParams = ( TradeHistoryParamPaging ) params ; Integer pageLength = pagingParams . getPageLength ( ) ; Integer pageNum = pagingParams . getPageNumber ( ) ; limit = ( pageLength != null && pageNum != null ) ? pageLength * ( pageNum + 1 ) : 50 ; } if ( params instanceof TradeHistoryParamLimit ) { TradeHistoryParamLimit tradeHistoryParamLimit = ( TradeHistoryParamLimit ) params ; limit = tradeHistoryParamLimit . getLimit ( ) ; } final BitfinexTradeResponse [ ] trades = getBitfinexTradeHistory ( symbol , startTime , endTime , limit , null ) ; return BitfinexAdapters . adaptTradeHistory ( trades , symbol ) ; } catch ( BitfinexException e ) { throw BitfinexErrorAdapter . adapt ( e ) ; } }
@param params Implementation of {@link TradeHistoryParamCurrencyPair} is mandatory. Can
optionally implement {@link TradeHistoryParamPaging} and {@link
TradeHistoryParamsTimeSpan#getStartTime()}. All other TradeHistoryParams types will be
ignored.