Search in sources :

Example 1 with UserTrades

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

the class CoinfloorUserTradesIntegration method fetchUserTradesTest.

@Test
public void fetchUserTradesTest() throws IOException {
    final ExchangeSpecification specification = new ExchangeSpecification(CoinfloorExchange.class);
    String username = System.getProperty("xchange.coinfloor.username");
    String password = System.getProperty("xchange.coinfloor.password");
    if (username == null || password == null) {
        return;
    }
    specification.setUserName(username);
    specification.setPassword(password);
    Exchange exchange = ExchangeFactory.INSTANCE.createExchange(specification);
    TradeService service = exchange.getTradeService();
    CoinfloorTradeHistoryParams params = (CoinfloorTradeHistoryParams) service.createTradeHistoryParams();
    UserTrades trades = service.getTradeHistory(params);
    logger.info("{}", trades);
}
Also used : CoinfloorExchange(org.knowm.xchange.coinfloor.CoinfloorExchange) Exchange(org.knowm.xchange.Exchange) UserTrades(org.knowm.xchange.dto.trade.UserTrades) TradeService(org.knowm.xchange.service.trade.TradeService) ExchangeSpecification(org.knowm.xchange.ExchangeSpecification) Test(org.junit.Test)

Example 2 with UserTrades

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

the class CoingiAdapters method adaptTradeHistory.

public static UserTrades adaptTradeHistory(CoingiOrdersList ordersList) {
    List<UserTrade> trades = new ArrayList<>();
    for (CoingiOrder o : ordersList.getList()) {
        final OrderType orderType = o.getType() == 0 ? OrderType.BID : OrderType.ASK;
        final CurrencyPair pair = new CurrencyPair(o.getCurrencyPair().get("base").toUpperCase(), o.getCurrencyPair().get("counter").toUpperCase());
        UserTrade trade = new UserTrade.Builder().type(orderType).originalAmount(o.getOriginalBaseAmount()).currencyPair(pair).price(o.getPrice()).timestamp(new Date(o.getTimestamp())).id(o.getId()).orderId(o.getId()).feeAmount(BigDecimal.ZERO).build();
        trades.add(trade);
    }
    return new UserTrades(trades, TradeSortType.SortByID);
}
Also used : UserTrades(org.knowm.xchange.dto.trade.UserTrades) OrderType(org.knowm.xchange.dto.Order.OrderType) ArrayList(java.util.ArrayList) CoingiOrder(org.knowm.xchange.coingi.dto.trade.CoingiOrder) UserTrade(org.knowm.xchange.dto.trade.UserTrade) Date(java.util.Date) CurrencyPair(org.knowm.xchange.currency.CurrencyPair)

Example 3 with UserTrades

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

the class KucoinTradeHistoryDemo method getHistoricalTrades.

private static void getHistoricalTrades(TradeService tradeService) throws IOException {
    System.out.println("Requesting trades from the old API (before 18 Feb 2019 UTC+8, no time span limitation)...");
    KucoinTradeHistoryParams tradeHistoryParams = (KucoinTradeHistoryParams) tradeService.createTradeHistoryParams();
    Date aWhileBack = Date.from(LocalDate.of(2019, 2, 1).atStartOfDay().atZone(ZoneId.systemDefault()).toInstant());
    tradeHistoryParams.setEndTime(aWhileBack);
    UserTrades tradeHistory = tradeService.getTradeHistory(tradeHistoryParams);
    tradeHistory.getUserTrades().forEach(System.out::println);
}
Also used : UserTrades(org.knowm.xchange.dto.trade.UserTrades) KucoinTradeHistoryParams(org.knowm.xchange.kucoin.KucoinTradeHistoryParams) Date(java.util.Date) LocalDate(java.time.LocalDate)

Example 4 with UserTrades

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

the class KucoinTradeHistoryDemo method getRecentTrades.

private static void getRecentTrades(TradeService tradeService) throws IOException {
    System.out.println("Requesting trades from the last 8 days (API allows up to 8 days)...");
    KucoinTradeHistoryParams tradeHistoryParams = (KucoinTradeHistoryParams) tradeService.createTradeHistoryParams();
    UserTrades tradeHistory = tradeService.getTradeHistory(tradeHistoryParams);
    tradeHistory.getUserTrades().forEach(System.out::println);
}
Also used : UserTrades(org.knowm.xchange.dto.trade.UserTrades) KucoinTradeHistoryParams(org.knowm.xchange.kucoin.KucoinTradeHistoryParams)

Example 5 with UserTrades

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

the class CoinmateStreamingTradeService method getUserTrades.

@Override
public Observable<UserTrade> getUserTrades(CurrencyPair currencyPair, Object... args) {
    String channelName = "private-user-trades-" + coinmateStreamingService.getUserId() + "-" + CoinmateStreamingAdapter.getChannelPostfix(currencyPair);
    ObjectReader reader = StreamingObjectMapperHelper.getObjectMapper().readerFor(new TypeReference<List<CoinmateWebSocketUserTrade>>() {
    });
    return coinmateStreamingService.subscribeChannel(channelName, true).map((message) -> {
        List<CoinmateWebSocketUserTrade> webSocketUserTrades = reader.readValue(message.get("payload"));
        return CoinmateStreamingAdapter.adaptWebSocketUserTrades(webSocketUserTrades, currencyPair);
    }).concatMapIterable(UserTrades::getUserTrades);
}
Also used : Arrays(java.util.Arrays) CoinmateWebsocketOpenOrder(info.bitrich.xchangestream.coinmate.v2.dto.CoinmateWebsocketOpenOrder) UserTrades(org.knowm.xchange.dto.trade.UserTrades) UserTrade(org.knowm.xchange.dto.trade.UserTrade) StreamingObjectMapperHelper(info.bitrich.xchangestream.service.netty.StreamingObjectMapperHelper) ObjectReader(com.fasterxml.jackson.databind.ObjectReader) CoinmateWebSocketUserTrade(info.bitrich.xchangestream.coinmate.v2.dto.CoinmateWebSocketUserTrade) Order(org.knowm.xchange.dto.Order) List(java.util.List) JsonNode(com.fasterxml.jackson.databind.JsonNode) Observable(io.reactivex.Observable) OpenOrders(org.knowm.xchange.dto.trade.OpenOrders) TypeReference(com.fasterxml.jackson.core.type.TypeReference) StreamingTradeService(info.bitrich.xchangestream.core.StreamingTradeService) Collections(java.util.Collections) CurrencyPair(org.knowm.xchange.currency.CurrencyPair) UserTrades(org.knowm.xchange.dto.trade.UserTrades) ObjectReader(com.fasterxml.jackson.databind.ObjectReader) List(java.util.List)

Aggregations

UserTrades (org.knowm.xchange.dto.trade.UserTrades)107 UserTrade (org.knowm.xchange.dto.trade.UserTrade)63 ArrayList (java.util.ArrayList)42 BigDecimal (java.math.BigDecimal)34 CurrencyPair (org.knowm.xchange.currency.CurrencyPair)34 Date (java.util.Date)25 Test (org.junit.Test)21 OrderType (org.knowm.xchange.dto.Order.OrderType)17 OpenOrders (org.knowm.xchange.dto.trade.OpenOrders)16 LimitOrder (org.knowm.xchange.dto.trade.LimitOrder)15 TradeService (org.knowm.xchange.service.trade.TradeService)15 TradeHistoryParamCurrencyPair (org.knowm.xchange.service.trade.params.TradeHistoryParamCurrencyPair)15 TradeHistoryParams (org.knowm.xchange.service.trade.params.TradeHistoryParams)12 List (java.util.List)11 Currency (org.knowm.xchange.currency.Currency)11 Exchange (org.knowm.xchange.Exchange)10 MarketOrder (org.knowm.xchange.dto.trade.MarketOrder)10 OpenOrdersParamCurrencyPair (org.knowm.xchange.service.trade.params.orders.OpenOrdersParamCurrencyPair)9 Order (org.knowm.xchange.dto.Order)8 TradeHistoryParamLimit (org.knowm.xchange.service.trade.params.TradeHistoryParamLimit)8