Skip to content

Commit

Permalink
Add the ability to request only deposits or only withdrawal to the ge…
Browse files Browse the repository at this point in the history
…neric API; implemented for Kraken.
  • Loading branch information
mmazi committed Apr 7, 2017
1 parent 02e0053 commit f75b0d3
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package org.knowm.xchange.service.trade.params;

import org.knowm.xchange.dto.account.FundingRecord;

public interface HistoryParamsFundingType extends TradeHistoryParams {

FundingRecord.Type getType();

void setType(FundingRecord.Type type);
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import org.knowm.xchange.examples.util.AccountServiceTestUtil;
import org.knowm.xchange.kraken.service.KrakenAccountServiceRaw;
import org.knowm.xchange.service.account.AccountService;
import org.knowm.xchange.service.trade.params.HistoryParamsFundingType;
import org.knowm.xchange.service.trade.params.TradeHistoryParamCurrencies;
import org.knowm.xchange.service.trade.params.TradeHistoryParams;
import org.knowm.xchange.service.trade.params.TradeHistoryParamsTimeSpan;
Expand Down Expand Up @@ -57,6 +58,10 @@ private static void fundingHistory(AccountService accountService) throws IOExcep
timeSpanParam.setStartTime(new Date(System.currentTimeMillis() - (1 * 12 * 30 * 24 * 60 * 60 * 1000L)));
}

if (params instanceof HistoryParamsFundingType) {
((HistoryParamsFundingType) params).setType(FundingRecord.Type.DEPOSIT);
}

if (params instanceof TradeHistoryParamCurrencies) {
final TradeHistoryParamCurrencies currenciesParam = (TradeHistoryParamCurrencies) params;
currenciesParam.setCurrencies(new Currency[] {Currency.BTC, Currency.USD});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,10 @@
import org.knowm.xchange.exceptions.NotYetImplementedForExchangeException;
import org.knowm.xchange.kraken.KrakenAdapters;
import org.knowm.xchange.kraken.dto.account.KrakenDepositAddress;
import org.knowm.xchange.kraken.dto.account.LedgerType;
import org.knowm.xchange.service.account.AccountService;
import org.knowm.xchange.service.trade.params.DefaultTradeHistoryParamsTimeSpan;
import org.knowm.xchange.service.trade.params.HistoryParamsFundingType;
import org.knowm.xchange.service.trade.params.TradeHistoryParamCurrencies;
import org.knowm.xchange.service.trade.params.TradeHistoryParamOffset;
import org.knowm.xchange.service.trade.params.TradeHistoryParams;
Expand Down Expand Up @@ -86,15 +88,23 @@ public List<FundingRecord> getFundingHistory(TradeHistoryParams params) throws E
}
}

return KrakenAdapters.adaptFundingHistory(getKrakenLedgerInfo(null, startTime, endTime, offset, currencies));
LedgerType ledgerType = null;
if (params instanceof HistoryParamsFundingType) {
final FundingRecord.Type type = ((HistoryParamsFundingType) params).getType();
ledgerType = type == FundingRecord.Type.DEPOSIT ? LedgerType.DEPOSIT
: type == FundingRecord.Type.WITHDRAWAL ? LedgerType.WITHDRAWAL
: null;
}
return KrakenAdapters.adaptFundingHistory(getKrakenLedgerInfo(ledgerType, startTime, endTime, offset, currencies));
}


public static class KrakenFundingHistoryParams extends DefaultTradeHistoryParamsTimeSpan
implements TradeHistoryParamOffset, TradeHistoryParamCurrencies{
implements TradeHistoryParamOffset, TradeHistoryParamCurrencies, HistoryParamsFundingType {

private Long offset;
private Currency[] currencies;
private FundingRecord.Type type;

public KrakenFundingHistoryParams(final Date startTime, final Date endTime, final Long offset, final Currency... currencies) {
super(startTime, endTime);
Expand All @@ -121,6 +131,16 @@ public void setCurrencies(Currency[] currencies) {
public Currency[] getCurrencies() {
return this.currencies;
}

@Override
public FundingRecord.Type getType() {
return type;
}

@Override
public void setType(FundingRecord.Type type) {
this.type = type;
}
}

}

0 comments on commit f75b0d3

Please sign in to comment.