Search in sources :

Example 1 with OkCoinAccountRecords

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;
}
Also used : OkCoinAccountRecords(org.knowm.xchange.okcoin.dto.account.OkCoinAccountRecords) FundingRecord(org.knowm.xchange.dto.account.FundingRecord) ArrayList(java.util.ArrayList) NotAvailableFromExchangeException(org.knowm.xchange.exceptions.NotAvailableFromExchangeException) ExchangeException(org.knowm.xchange.exceptions.ExchangeException) DefaultTradeHistoryParamPaging(org.knowm.xchange.service.trade.params.DefaultTradeHistoryParamPaging) TradeHistoryParamPaging(org.knowm.xchange.service.trade.params.TradeHistoryParamPaging) HistoryParamsFundingType(org.knowm.xchange.service.trade.params.HistoryParamsFundingType) TradeHistoryParamCurrency(org.knowm.xchange.service.trade.params.TradeHistoryParamCurrency) Type(org.knowm.xchange.dto.account.FundingRecord.Type)

Example 2 with OkCoinAccountRecords

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");
}
Also used : OkCoinAccountRecords(org.knowm.xchange.okcoin.dto.account.OkCoinAccountRecords) InputStream(java.io.InputStream) FundingRecord(org.knowm.xchange.dto.account.FundingRecord) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) BigDecimal(java.math.BigDecimal) Test(org.junit.Test)

Aggregations

FundingRecord (org.knowm.xchange.dto.account.FundingRecord)2 OkCoinAccountRecords (org.knowm.xchange.okcoin.dto.account.OkCoinAccountRecords)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 InputStream (java.io.InputStream)1 BigDecimal (java.math.BigDecimal)1 ArrayList (java.util.ArrayList)1 Test (org.junit.Test)1 Type (org.knowm.xchange.dto.account.FundingRecord.Type)1 ExchangeException (org.knowm.xchange.exceptions.ExchangeException)1 NotAvailableFromExchangeException (org.knowm.xchange.exceptions.NotAvailableFromExchangeException)1 DefaultTradeHistoryParamPaging (org.knowm.xchange.service.trade.params.DefaultTradeHistoryParamPaging)1 HistoryParamsFundingType (org.knowm.xchange.service.trade.params.HistoryParamsFundingType)1 TradeHistoryParamCurrency (org.knowm.xchange.service.trade.params.TradeHistoryParamCurrency)1 TradeHistoryParamPaging (org.knowm.xchange.service.trade.params.TradeHistoryParamPaging)1