use of org.knowm.xchange.okcoin.dto.account.OkCoinAccountRecords in project XChange by knowm.
the class OkCoinAccountService method getFundingHistory.
@Override
public List<FundingRecord> getFundingHistory(TradeHistoryParams params) throws IOException {
String symbol = null;
if (params instanceof TradeHistoryParamCurrency && ((TradeHistoryParamCurrency) params).getCurrency() != null) {
symbol = OkCoinAdapters.adaptCurrencyToAccountRecordPair(((TradeHistoryParamCurrency) params).getCurrency());
}
if (symbol == null) {
throw new ExchangeException("Symbol must be supplied");
}
Integer pageLength = 50;
Integer pageNumber = null;
if (params instanceof TradeHistoryParamPaging) {
TradeHistoryParamPaging pagingParams = (TradeHistoryParamPaging) params;
if (pagingParams.getPageLength() != null) {
pageLength = pagingParams.getPageLength();
if (pageLength > 50) {
pageLength = 50;
}
}
pageNumber = pagingParams.getPageNumber() != null ? pagingParams.getPageNumber() : 1;
}
FundingRecord.Type type = null;
if (params instanceof HistoryParamsFundingType) {
type = ((HistoryParamsFundingType) params).getType();
}
List<FundingRecord> result = new ArrayList<>();
if (type == null || type == Type.DEPOSIT) {
final OkCoinAccountRecords depositRecord = getAccountRecords(symbol, "0", String.valueOf(pageNumber), String.valueOf(pageLength));
result.addAll(OkCoinAdapters.adaptFundingHistory(depositRecord, Type.DEPOSIT));
}
if (type == null || type == Type.WITHDRAWAL) {
final OkCoinAccountRecords withdrawalRecord = getAccountRecords(symbol, "1", String.valueOf(pageNumber), String.valueOf(pageLength));
result.addAll(OkCoinAdapters.adaptFundingHistory(withdrawalRecord, Type.WITHDRAWAL));
}
return result;
}
use of org.knowm.xchange.okcoin.dto.account.OkCoinAccountRecords in project XChange by knowm.
the class OkCoinAdaptersTest method testAdaptFundingHistory.
@Test
public void testAdaptFundingHistory() throws JsonParseException, JsonMappingException, IOException {
ObjectMapper mapper = new ObjectMapper();
InputStream is = OkCoinAdaptersTest.class.getResourceAsStream("/org/knowm/xchange/okcoin/dto/account/example-accountrecords-deposit-data.json");
OkCoinAccountRecords okCoinAccountDepositRecords = mapper.readValue(is, OkCoinAccountRecords.class);
is = OkCoinAdaptersTest.class.getResourceAsStream("/org/knowm/xchange/okcoin/dto/account/example-accountrecords-withdrawal-data.json");
OkCoinAccountRecords okCoinAccountWithdrawalRecords = mapper.readValue(is, OkCoinAccountRecords.class);
List<FundingRecord> records = OkCoinAdapters.adaptFundingHistory(okCoinAccountDepositRecords, FundingRecord.Type.DEPOSIT);
assertThat(records.size()).isEqualTo(2);
FundingRecord depositRecord = records.get(1);
assertThat(depositRecord).isInstanceOf(FundingRecord.class);
assertThat(depositRecord.getType()).isEqualTo(FundingRecord.Type.DEPOSIT);
assertThat(depositRecord.getStatus()).isEqualTo(FundingRecord.Status.COMPLETE);
assertThat(depositRecord.getAmount()).isEqualTo(new BigDecimal("50"));
assertThat(depositRecord.getFee().doubleValue()).isEqualTo(new BigDecimal("0.07").doubleValue());
assertThat(depositRecord.getAddress()).isEqualTo("1lEWjmlkmlhTqcYj3l33sg980slkjtdqd");
records = OkCoinAdapters.adaptFundingHistory(okCoinAccountDepositRecords, FundingRecord.Type.WITHDRAWAL);
FundingRecord withdrawalRecord = records.get(1);
assertThat(withdrawalRecord).isInstanceOf(FundingRecord.class);
assertThat(withdrawalRecord.getType()).isEqualTo(FundingRecord.Type.WITHDRAWAL);
assertThat(withdrawalRecord.getStatus()).isEqualTo(FundingRecord.Status.PROCESSING);
assertThat(withdrawalRecord.getAmount()).isEqualTo(new BigDecimal("50"));
assertThat(withdrawalRecord.getFee().doubleValue()).isEqualTo(new BigDecimal("0.07").doubleValue());
assertThat(withdrawalRecord.getAddress()).isEqualTo("1lEWjmlkmlhTqcYj3l33sg980slkjtdqd");
}
Aggregations