Search in sources :

Example 16 with UserTrade

use of org.knowm.xchange.dto.trade.UserTrade 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)

Example 17 with UserTrade

use of org.knowm.xchange.dto.trade.UserTrade in project XChange by knowm.

the class DVChainAdapters method adaptTradeHistory.

public static UserTrades adaptTradeHistory(List<DVChainTrade> trades) {
    List<UserTrade> pastTrades = new ArrayList<>(trades.size());
    for (DVChainTrade trade : trades) {
        Order.OrderType orderType = trade.getSide().equalsIgnoreCase("buy") ? Order.OrderType.BID : Order.OrderType.ASK;
        Date timestamp = Date.from(trade.getCreatedAt());
        CurrencyPair currencyPair = new CurrencyPair(trade.getAsset(), "USD");
        final BigDecimal fee = null;
        pastTrades.add(new UserTrade.Builder().type(orderType).originalAmount(trade.getQuantity()).currencyPair(currencyPair).price(trade.getPrice()).timestamp(timestamp).id(trade.getId()).orderId(trade.getId()).feeAmount(fee).feeCurrency(Currency.USD).build());
    }
    return new UserTrades(pastTrades, Trades.TradeSortType.SortByTimestamp);
}
Also used : LimitOrder(org.knowm.xchange.dto.trade.LimitOrder) Order(org.knowm.xchange.dto.Order) DVChainTrade(org.knowm.xchange.dvchain.dto.trade.DVChainTrade) UserTrades(org.knowm.xchange.dto.trade.UserTrades) ArrayList(java.util.ArrayList) UserTrade(org.knowm.xchange.dto.trade.UserTrade) Date(java.util.Date) BigDecimal(java.math.BigDecimal) CurrencyPair(org.knowm.xchange.currency.CurrencyPair)

Example 18 with UserTrade

use of org.knowm.xchange.dto.trade.UserTrade in project XChange by knowm.

the class IdexTradeService method getTradeHistory.

@Override
public UserTrades getTradeHistory(TradeHistoryParams tradeHistoryParams) {
    CurrencyPair currencyPairTmp = null;
    if (tradeHistoryParams instanceof TradeHistoryParamCurrencyPair) {
        currencyPairTmp = ((TradeHistoryParamCurrencyPair) tradeHistoryParams).getCurrencyPair();
    }
    final CurrencyPair currencyPair = currencyPairTmp;
    UserTrades ret = null;
    try {
        List<UserTrade> userTrades = returnTradeHistoryApi.tradeHistory((TradeHistoryReq) tradeHistoryParams).stream().map(tradeHistoryItem -> new UserTrade.Builder().originalAmount(IdexExchange.Companion.safeParse(tradeHistoryItem.getAmount())).price(IdexExchange.Companion.safeParse(tradeHistoryItem.getPrice())).currencyPair(currencyPair).timestamp(new Date(tradeHistoryItem.getTimestamp().longValue() * 1000)).id((tradeHistoryItem.getTransactionHash())).type(tradeHistoryItem.getType() == IdexBuySell.BUY ? Order.OrderType.BID : Order.OrderType.ASK).build()).sorted(Comparator.comparing(Trade::getTimestamp)).collect(Collectors.toList());
        return new UserTrades(userTrades, Trades.TradeSortType.SortByTimestamp);
    } catch (Exception e) {
        e.printStackTrace();
    }
    return ret;
}
Also used : UserTrade(org.knowm.xchange.dto.trade.UserTrade) Trade(org.knowm.xchange.dto.marketdata.Trade) UserTrades(org.knowm.xchange.dto.trade.UserTrades) Builder(org.knowm.xchange.dto.trade.LimitOrder.Builder) ExchangeRestProxyBuilder(org.knowm.xchange.client.ExchangeRestProxyBuilder) UserTrade(org.knowm.xchange.dto.trade.UserTrade) Date(java.util.Date) NotAvailableFromExchangeException(org.knowm.xchange.exceptions.NotAvailableFromExchangeException) Companion.getCurrencyPair(org.knowm.xchange.idex.IdexExchange.Companion.getCurrencyPair) CurrencyPair(org.knowm.xchange.currency.CurrencyPair) TradeHistoryParamCurrencyPair(org.knowm.xchange.service.trade.params.TradeHistoryParamCurrencyPair) TradeHistoryParamCurrencyPair(org.knowm.xchange.service.trade.params.TradeHistoryParamCurrencyPair)

Example 19 with UserTrade

use of org.knowm.xchange.dto.trade.UserTrade in project XChange by knowm.

the class IndependentReserveTradeServiceIntegration method testGetTradeHistory.

@Test
public void testGetTradeHistory() throws Exception {
    Assume.assumeNotNull(exchange.getExchangeSpecification().getApiKey());
    UserTrades userTrades = tradeService.getTradeHistory(tradeService.createTradeHistoryParams());
    if (userTrades.getUserTrades().size() > 0) {
        UserTrade userTrade = userTrades.getUserTrades().get(0);
        String orderId = userTrade.getOrderId();
        Collection<Order> orders = tradeService.getOrder(orderId);
    }
}
Also used : Order(org.knowm.xchange.dto.Order) UserTrades(org.knowm.xchange.dto.trade.UserTrades) UserTrade(org.knowm.xchange.dto.trade.UserTrade) Test(org.junit.Test)

Example 20 with UserTrade

use of org.knowm.xchange.dto.trade.UserTrade in project XChange by knowm.

the class HuobiAdapters method adaptTradeHistory.

public static UserTrades adaptTradeHistory(HuobiOrder[] openOrders) {
    OpenOrders orders = adaptOpenOrders(openOrders);
    List<UserTrade> trades = new ArrayList<>();
    for (LimitOrder order : orders.getOpenOrders()) {
        trades.add(adaptTrade(order));
    }
    return new UserTrades(trades, TradeSortType.SortByTimestamp);
}
Also used : UserTrades(org.knowm.xchange.dto.trade.UserTrades) ArrayList(java.util.ArrayList) UserTrade(org.knowm.xchange.dto.trade.UserTrade) OpenOrders(org.knowm.xchange.dto.trade.OpenOrders) LimitOrder(org.knowm.xchange.dto.trade.LimitOrder)

Aggregations

UserTrade (org.knowm.xchange.dto.trade.UserTrade)112 UserTrades (org.knowm.xchange.dto.trade.UserTrades)62 ArrayList (java.util.ArrayList)57 BigDecimal (java.math.BigDecimal)50 CurrencyPair (org.knowm.xchange.currency.CurrencyPair)40 Date (java.util.Date)31 Test (org.junit.Test)25 OrderType (org.knowm.xchange.dto.Order.OrderType)19 List (java.util.List)14 Test (org.junit.jupiter.api.Test)14 TradeHistoryParams (org.knowm.xchange.service.trade.params.TradeHistoryParams)14 IOException (java.io.IOException)13 Currency (org.knowm.xchange.currency.Currency)13 LimitOrder (org.knowm.xchange.dto.trade.LimitOrder)13 TradeHistoryParamCurrencyPair (org.knowm.xchange.service.trade.params.TradeHistoryParamCurrencyPair)12 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)11 TradeService (org.knowm.xchange.service.trade.TradeService)11 InputStream (java.io.InputStream)10 Order (org.knowm.xchange.dto.Order)10 OpenOrders (org.knowm.xchange.dto.trade.OpenOrders)10