Skip to content

Commit

Permalink
TradeHistoryParams implementations check added to avoid
Browse files Browse the repository at this point in the history
ClassCastException
  • Loading branch information
ww3456 committed Jan 31, 2015
1 parent 1221b93 commit bf6aeea
Showing 1 changed file with 22 additions and 11 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package com.xeiam.xchange.kraken.service.polling;

import java.io.IOException;
import java.util.Date;

import com.xeiam.xchange.Exchange;
import com.xeiam.xchange.dto.trade.LimitOrder;
Expand All @@ -15,6 +14,7 @@
import com.xeiam.xchange.service.polling.trade.params.TradeHistoryParamOffset;
import com.xeiam.xchange.service.polling.trade.params.TradeHistoryParams;
import com.xeiam.xchange.service.polling.trade.params.TradeHistoryParamsTimeSpan;
import com.xeiam.xchange.utils.DateUtils;

public class KrakenTradeService extends KrakenTradeServiceRaw implements PollingTradeService {

Expand Down Expand Up @@ -59,16 +59,32 @@ public UserTrades getTradeHistory(Object... args) throws IOException {
}

/**
* Required parameters {@link TradeHistoryParamsTimeSpan} {@link TradeHistoryParamOffset}
* @param params Can optionally implement {@link TradeHistoryParamOffset} and
* {@link TradeHistoryParamsTimeSpan}. All other TradeHistoryParams
* types will be ignored.
*/
@Override
public UserTrades getTradeHistory(TradeHistoryParams params) throws ExchangeException, IOException {

TradeHistoryParamsTimeSpan timeSpan = (TradeHistoryParamsTimeSpan) params;
TradeHistoryParamOffset offset = (TradeHistoryParamOffset) params;
final Long startTime;
final Long endTime;
if (params instanceof TradeHistoryParamsTimeSpan) {
TradeHistoryParamsTimeSpan timeSpan = (TradeHistoryParamsTimeSpan) params;
startTime = DateUtils.toUnixTimeNullSafe(timeSpan.getStartTime());
endTime = DateUtils.toUnixTimeNullSafe(timeSpan.getEndTime());
} else {
startTime = null;
endTime = null;
}

final Long offset;
if (params instanceof TradeHistoryParamOffset) {
offset = ((TradeHistoryParamOffset) params).getOffset();
} else {
offset = null;
}

return KrakenAdapters.adaptTradesHistory(getKrakenTradeHistory(null, false, getTime(timeSpan.getStartTime()), getTime(timeSpan.getEndTime()),
offset.getOffset()));
return KrakenAdapters.adaptTradesHistory(getKrakenTradeHistory(null, false, startTime, endTime, offset));
}

@Override
Expand All @@ -77,11 +93,6 @@ public com.xeiam.xchange.service.polling.trade.params.TradeHistoryParams createT
return new KrakenTradeHistoryParams();
}

private static Long getTime(Date date) {

return date == null ? null : date.getTime();
}

public static class KrakenTradeHistoryParams extends DefaultTradeHistoryParamsTimeSpan implements TradeHistoryParamOffset {

private Long offset;
Expand Down

0 comments on commit bf6aeea

Please sign in to comment.