Search in sources :

Example 1 with TradeHistoryParams

use of org.knowm.xchange.service.trade.params.TradeHistoryParams in project XChange by knowm.

the class OkCoinAccountDemo method fundingHistory.

private static void fundingHistory(AccountService accountService) throws IOException {
    // Get the funds information
    TradeHistoryParams params = accountService.createFundingHistoryParams();
    if (params instanceof TradeHistoryParamPaging) {
        TradeHistoryParamPaging pagingParams = (TradeHistoryParamPaging) params;
        pagingParams.setPageLength(50);
        pagingParams.setPageNumber(1);
    }
    if (params instanceof TradeHistoryParamCurrencyPair) {
        ((TradeHistoryParamCurrencyPair) params).setCurrencyPair(CurrencyPair.BTC_CNY);
    }
    final List<FundingRecord> fundingRecords = accountService.getFundingHistory(params);
    AccountServiceTestUtil.printFundingHistory(fundingRecords);
}
Also used : FundingRecord(org.knowm.xchange.dto.account.FundingRecord) TradeHistoryParams(org.knowm.xchange.service.trade.params.TradeHistoryParams) TradeHistoryParamPaging(org.knowm.xchange.service.trade.params.TradeHistoryParamPaging) TradeHistoryParamCurrencyPair(org.knowm.xchange.service.trade.params.TradeHistoryParamCurrencyPair)

Example 2 with TradeHistoryParams

use of org.knowm.xchange.service.trade.params.TradeHistoryParams in project XChange by knowm.

the class KrakenAccountDemo method fundingHistory.

private static void fundingHistory(AccountService accountService) throws IOException {
    // Get the funds information
    TradeHistoryParams params = accountService.createFundingHistoryParams();
    if (params instanceof TradeHistoryParamsTimeSpan) {
        final TradeHistoryParamsTimeSpan timeSpanParam = (TradeHistoryParamsTimeSpan) params;
        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 });
    }
    List<FundingRecord> fundingRecords = accountService.getFundingHistory(params);
    AccountServiceTestUtil.printFundingHistory(fundingRecords);
}
Also used : TradeHistoryParamsTimeSpan(org.knowm.xchange.service.trade.params.TradeHistoryParamsTimeSpan) TradeHistoryParamCurrencies(org.knowm.xchange.service.trade.params.TradeHistoryParamCurrencies) FundingRecord(org.knowm.xchange.dto.account.FundingRecord) TradeHistoryParams(org.knowm.xchange.service.trade.params.TradeHistoryParams) HistoryParamsFundingType(org.knowm.xchange.service.trade.params.HistoryParamsFundingType) Date(java.util.Date)

Example 3 with TradeHistoryParams

use of org.knowm.xchange.service.trade.params.TradeHistoryParams in project XChange by knowm.

the class AccountServiceIntegration method testWithdrawalHistory.

@Test
public void testWithdrawalHistory() throws Exception {
    assumeProduction();
    TradeHistoryParams params = accountService.createFundingHistoryParams();
    List<FundingRecord> fundingHistory = accountService.getFundingHistory(params);
    Assert.assertNotNull(fundingHistory);
    fundingHistory.forEach(record -> {
        Assert.assertTrue(record.getAmount().compareTo(BigDecimal.ZERO) > 0);
    });
}
Also used : FundingRecord(org.knowm.xchange.dto.account.FundingRecord) TradeHistoryParams(org.knowm.xchange.service.trade.params.TradeHistoryParams) Test(org.junit.Test)

Example 4 with TradeHistoryParams

use of org.knowm.xchange.service.trade.params.TradeHistoryParams in project XChange by knowm.

the class PoloniexAccountDemo method generic.

private static void generic(AccountService accountService) throws IOException {
    System.out.println("----------GENERIC----------");
    System.out.println(accountService.requestDepositAddress(Currency.BTC));
    System.out.println(accountService.getAccountInfo());
    System.out.println(accountService.withdrawFunds(Currency.BTC, new BigDecimal("0.03"), "XXX"));
    final TradeHistoryParams params = accountService.createFundingHistoryParams();
    ((TradeHistoryParamsTimeSpan) params).setStartTime(new Date(System.currentTimeMillis() - 7L * 24 * 60 * 60 * 1000));
    final List<FundingRecord> fundingHistory = accountService.getFundingHistory(params);
    for (FundingRecord fundingRecord : fundingHistory) {
        System.out.println(fundingRecord);
    }
}
Also used : TradeHistoryParamsTimeSpan(org.knowm.xchange.service.trade.params.TradeHistoryParamsTimeSpan) FundingRecord(org.knowm.xchange.dto.account.FundingRecord) TradeHistoryParams(org.knowm.xchange.service.trade.params.TradeHistoryParams) BigDecimal(java.math.BigDecimal) Date(java.util.Date)

Example 5 with TradeHistoryParams

use of org.knowm.xchange.service.trade.params.TradeHistoryParams in project XChange by knowm.

the class DragonexTradeService method getTradeHistory.

@Override
public UserTrades getTradeHistory(TradeHistoryParams params) throws IOException {
    if (!(params instanceof TradeHistoryParamCurrencyPair)) {
        throw new ExchangeException("You need to provide the currency pair.");
    }
    TradeHistoryParamCurrencyPair pairParams = (TradeHistoryParamCurrencyPair) params;
    CurrencyPair pair = pairParams.getCurrencyPair();
    if (pair == null) {
        throw new ExchangeException("You need to provide the currency pair.");
    }
    long symbolId = exchange.symbolId(pair);
    Integer direction = null;
    if (params instanceof TradeHistoryParamsSorted) {
        TradeHistoryParamsSorted sort = (TradeHistoryParamsSorted) params;
        direction = sort.getOrder() == Order.asc ? 1 : 2;
    }
    DealHistoryRequest req = new DealHistoryRequest(symbolId, direction, null, 1000);
    DealHistory dealHistory = super.dealHistory(exchange.getOrCreateToken().token, req);
    List<UserTrade> trades = dealHistory.getList().stream().map(d -> {
        CurrencyPair currencyPair = exchange.pair(d.symbolId);
        return new UserTrade.Builder().type(d.orderType == 1 ? OrderType.BID : OrderType.ASK).originalAmount(d.volume).currencyPair(currencyPair).price(d.price).timestamp(d.getTimestamp()).id(d.tradeId).orderId(d.orderId).feeAmount(d.charge).feeCurrency(currencyPair.counter).build();
    }).collect(Collectors.toList());
    return new UserTrades(trades, TradeSortType.SortByTimestamp);
}
Also used : TradeHistoryParams(org.knowm.xchange.service.trade.params.TradeHistoryParams) OrderType(org.knowm.xchange.dto.Order.OrderType) CancelOrderByCurrencyPair(org.knowm.xchange.service.trade.params.CancelOrderByCurrencyPair) DefaultTradeHistoryParamCurrencyPair(org.knowm.xchange.service.trade.params.DefaultTradeHistoryParamCurrencyPair) Exchange(org.knowm.xchange.Exchange) OrderHistory(org.knowm.xchange.dragonex.dto.trade.OrderHistory) TradeSortType(org.knowm.xchange.dto.marketdata.Trades.TradeSortType) DealHistoryRequest(org.knowm.xchange.dragonex.dto.trade.DealHistoryRequest) OrderHistoryRequest(org.knowm.xchange.dragonex.dto.trade.OrderHistoryRequest) CancelOrderByIdParams(org.knowm.xchange.service.trade.params.CancelOrderByIdParams) OpenOrders(org.knowm.xchange.dto.trade.OpenOrders) OpenOrdersParamCurrencyPair(org.knowm.xchange.service.trade.params.orders.OpenOrdersParamCurrencyPair) DealHistory(org.knowm.xchange.dragonex.dto.trade.DealHistory) LimitOrder(org.knowm.xchange.dto.trade.LimitOrder) DefaultOpenOrdersParamCurrencyPair(org.knowm.xchange.service.trade.params.orders.DefaultOpenOrdersParamCurrencyPair) IOException(java.io.IOException) UserTrades(org.knowm.xchange.dto.trade.UserTrades) OrderReference(org.knowm.xchange.dragonex.dto.trade.OrderReference) UserTrade(org.knowm.xchange.dto.trade.UserTrade) Collectors(java.util.stream.Collectors) ExchangeException(org.knowm.xchange.exceptions.ExchangeException) UserOrder(org.knowm.xchange.dragonex.dto.trade.UserOrder) OrderPlacement(org.knowm.xchange.dragonex.dto.trade.OrderPlacement) List(java.util.List) Order(org.knowm.xchange.service.trade.params.TradeHistoryParamsSorted.Order) TradeService(org.knowm.xchange.service.trade.TradeService) TradeHistoryParamsSorted(org.knowm.xchange.service.trade.params.TradeHistoryParamsSorted) OpenOrdersParams(org.knowm.xchange.service.trade.params.orders.OpenOrdersParams) CancelOrderParams(org.knowm.xchange.service.trade.params.CancelOrderParams) CurrencyPair(org.knowm.xchange.currency.CurrencyPair) TradeHistoryParamCurrencyPair(org.knowm.xchange.service.trade.params.TradeHistoryParamCurrencyPair) DealHistoryRequest(org.knowm.xchange.dragonex.dto.trade.DealHistoryRequest) UserTrade(org.knowm.xchange.dto.trade.UserTrade) UserTrades(org.knowm.xchange.dto.trade.UserTrades) DealHistory(org.knowm.xchange.dragonex.dto.trade.DealHistory) TradeHistoryParamsSorted(org.knowm.xchange.service.trade.params.TradeHistoryParamsSorted) ExchangeException(org.knowm.xchange.exceptions.ExchangeException) DefaultTradeHistoryParamCurrencyPair(org.knowm.xchange.service.trade.params.DefaultTradeHistoryParamCurrencyPair) TradeHistoryParamCurrencyPair(org.knowm.xchange.service.trade.params.TradeHistoryParamCurrencyPair) CancelOrderByCurrencyPair(org.knowm.xchange.service.trade.params.CancelOrderByCurrencyPair) DefaultTradeHistoryParamCurrencyPair(org.knowm.xchange.service.trade.params.DefaultTradeHistoryParamCurrencyPair) OpenOrdersParamCurrencyPair(org.knowm.xchange.service.trade.params.orders.OpenOrdersParamCurrencyPair) DefaultOpenOrdersParamCurrencyPair(org.knowm.xchange.service.trade.params.orders.DefaultOpenOrdersParamCurrencyPair) CurrencyPair(org.knowm.xchange.currency.CurrencyPair) TradeHistoryParamCurrencyPair(org.knowm.xchange.service.trade.params.TradeHistoryParamCurrencyPair)

Aggregations

TradeHistoryParams (org.knowm.xchange.service.trade.params.TradeHistoryParams)23 UserTrade (org.knowm.xchange.dto.trade.UserTrade)14 UserTrades (org.knowm.xchange.dto.trade.UserTrades)12 IOException (java.io.IOException)9 BigDecimal (java.math.BigDecimal)9 List (java.util.List)9 TradeService (org.knowm.xchange.service.trade.TradeService)9 Collectors (java.util.stream.Collectors)8 Test (org.junit.Test)8 LimitOrder (org.knowm.xchange.dto.trade.LimitOrder)8 FundingRecord (org.knowm.xchange.dto.account.FundingRecord)7 OpenOrders (org.knowm.xchange.dto.trade.OpenOrders)7 ExchangeException (org.knowm.xchange.exceptions.ExchangeException)7 CancelOrderByIdParams (org.knowm.xchange.service.trade.params.CancelOrderByIdParams)7 OpenOrdersParams (org.knowm.xchange.service.trade.params.orders.OpenOrdersParams)7 CurrencyPair (org.knowm.xchange.currency.CurrencyPair)6 ArrayList (java.util.ArrayList)5 Date (java.util.Date)5 Currency (org.knowm.xchange.currency.Currency)5 CancelOrderByCurrencyPair (org.knowm.xchange.service.trade.params.CancelOrderByCurrencyPair)5