Search in sources :

Example 26 with Trade

use of org.knowm.xchange.dto.marketdata.Trade in project XChange by knowm.

the class DsxAdapters method adaptTrades.

public static Trades adaptTrades(List<? extends DsxTrade> allDsxTrades, CurrencyPair currencyPair, DsxTradesSortBy sortBy) {
    List<Trade> trades = new ArrayList<>(allDsxTrades.size());
    long lastTradeId = 0;
    for (int i = 0; i < allDsxTrades.size(); i++) {
        DsxTrade dsxTrade = allDsxTrades.get(i);
        Date timestamp = dsxTrade.getTimestamp();
        BigDecimal price = dsxTrade.getPrice();
        BigDecimal amount = dsxTrade.getQuantity();
        String tid = dsxTrade.getId();
        long longTradeId = tid == null ? 0 : Long.parseLong(tid);
        if (longTradeId > lastTradeId) {
            lastTradeId = longTradeId;
        }
        OrderType orderType = adaptSide(dsxTrade.getSide());
        Trade trade = new Trade.Builder().type(orderType).originalAmount(amount).currencyPair(currencyPair).price(price).timestamp(timestamp).id(tid).build();
        trades.add(trade);
    }
    return new Trades(trades, lastTradeId, sortBy.sortType);
}
Also used : DsxUserTrade(org.knowm.xchange.dsx.dto.DsxUserTrade) DsxOwnTrade(org.knowm.xchange.dsx.dto.DsxOwnTrade) UserTrade(org.knowm.xchange.dto.trade.UserTrade) DsxTrade(org.knowm.xchange.dsx.dto.DsxTrade) Trade(org.knowm.xchange.dto.marketdata.Trade) OrderType(org.knowm.xchange.dto.Order.OrderType) UserTrades(org.knowm.xchange.dto.trade.UserTrades) Trades(org.knowm.xchange.dto.marketdata.Trades) ArrayList(java.util.ArrayList) DsxTrade(org.knowm.xchange.dsx.dto.DsxTrade) Date(java.util.Date) BigDecimal(java.math.BigDecimal)

Example 27 with Trade

use of org.knowm.xchange.dto.marketdata.Trade 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 28 with Trade

use of org.knowm.xchange.dto.marketdata.Trade in project XChange by knowm.

the class CoinmateAdapters method adaptTrades.

public static Trades adaptTrades(CoinmateTransactions coinmateTransactions) {
    List<Trade> trades = new ArrayList<>(coinmateTransactions.getData().size());
    for (CoinmateTransactionsEntry coinmateEntry : coinmateTransactions.getData()) {
        Trade trade = adaptTrade(coinmateEntry);
        trades.add(trade);
    }
    // TODO correct sort order?
    return new Trades(trades, Trades.TradeSortType.SortByID);
}
Also used : UserTrade(org.knowm.xchange.dto.trade.UserTrade) Trade(org.knowm.xchange.dto.marketdata.Trade) UserTrades(org.knowm.xchange.dto.trade.UserTrades) Trades(org.knowm.xchange.dto.marketdata.Trades) ArrayList(java.util.ArrayList) CoinmateTransactionsEntry(org.knowm.xchange.coinmate.dto.marketdata.CoinmateTransactionsEntry)

Example 29 with Trade

use of org.knowm.xchange.dto.marketdata.Trade in project XChange by knowm.

the class GeminiAdaptersTest method testAdaptTradeHistory.

@Test
public void testAdaptTradeHistory() {
    GeminiTradeResponse[] responses = initTradeResponses();
    Trades trades = GeminiAdapters.adaptTradeHistory(responses, SYMBOL);
    assertEquals(trades.getTrades().size(), responses.length);
    for (int i = 0; i < responses.length; i++) {
        Trade trade = trades.getTrades().get(i);
        long expectedTimestampMillis = responses[i].getTimestamp().multiply(new BigDecimal(1000L)).longValue();
        Order.OrderType expectedOrderType = responses[i].getType().equalsIgnoreCase("buy") ? OrderType.BID : OrderType.ASK;
        assertEquals(responses[i].getPrice(), trade.getPrice());
        assertEquals(responses[i].getAmount(), trade.getOriginalAmount());
        assertEquals(GeminiAdapters.adaptCurrencyPair(SYMBOL), trade.getCurrencyPair());
        assertEquals(expectedTimestampMillis, trade.getTimestamp().getTime());
        assertEquals(expectedOrderType, trade.getType());
        assertEquals(responses[i].getTradeId(), trade.getId());
    }
}
Also used : Order(org.knowm.xchange.dto.Order) LimitOrder(org.knowm.xchange.dto.trade.LimitOrder) Trade(org.knowm.xchange.dto.marketdata.Trade) Trades(org.knowm.xchange.dto.marketdata.Trades) GeminiTradeResponse(org.knowm.xchange.gemini.v1.dto.trade.GeminiTradeResponse) OrderType(org.knowm.xchange.dto.Order.OrderType) BigDecimal(java.math.BigDecimal) Test(org.junit.Test) GeminiWalletJSONTest(org.knowm.xchange.gemini.v1.dto.account.GeminiWalletJSONTest)

Example 30 with Trade

use of org.knowm.xchange.dto.marketdata.Trade in project XChange by knowm.

the class HitbtcAdapters method adaptTrades.

public static Trades adaptTrades(List<? extends HitbtcTrade> allHitbtcTrades, CurrencyPair currencyPair) {
    List<Trade> trades = new ArrayList<>(allHitbtcTrades.size());
    long lastTradeId = 0;
    for (int i = 0; i < allHitbtcTrades.size(); i++) {
        HitbtcTrade hitbtcTrade = allHitbtcTrades.get(i);
        Date timestamp = hitbtcTrade.getTimestamp();
        BigDecimal price = hitbtcTrade.getPrice();
        BigDecimal amount = hitbtcTrade.getQuantity();
        String tid = hitbtcTrade.getId();
        long longTradeId = tid == null ? 0 : Long.parseLong(tid);
        if (longTradeId > lastTradeId) {
            lastTradeId = longTradeId;
        }
        OrderType orderType = adaptSide(hitbtcTrade.getSide());
        Trade trade = new Trade.Builder().type(orderType).originalAmount(amount).currencyPair(currencyPair).price(price).timestamp(timestamp).id(tid).build();
        trades.add(trade);
    }
    return new Trades(trades, lastTradeId, Trades.TradeSortType.SortByTimestamp);
}
Also used : HitbtcUserTrade(org.knowm.xchange.hitbtc.v2.dto.HitbtcUserTrade) HitbtcTrade(org.knowm.xchange.hitbtc.v2.dto.HitbtcTrade) UserTrade(org.knowm.xchange.dto.trade.UserTrade) HitbtcOwnTrade(org.knowm.xchange.hitbtc.v2.dto.HitbtcOwnTrade) Trade(org.knowm.xchange.dto.marketdata.Trade) OrderType(org.knowm.xchange.dto.Order.OrderType) UserTrades(org.knowm.xchange.dto.trade.UserTrades) Trades(org.knowm.xchange.dto.marketdata.Trades) ArrayList(java.util.ArrayList) HitbtcTrade(org.knowm.xchange.hitbtc.v2.dto.HitbtcTrade) Date(java.util.Date) BigDecimal(java.math.BigDecimal)

Aggregations

Trade (org.knowm.xchange.dto.marketdata.Trade)95 Trades (org.knowm.xchange.dto.marketdata.Trades)58 UserTrade (org.knowm.xchange.dto.trade.UserTrade)49 ArrayList (java.util.ArrayList)42 Date (java.util.Date)38 BigDecimal (java.math.BigDecimal)30 UserTrades (org.knowm.xchange.dto.trade.UserTrades)29 OrderType (org.knowm.xchange.dto.Order.OrderType)25 Test (org.junit.Test)21 CurrencyPair (org.knowm.xchange.currency.CurrencyPair)15 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)11 Exchange (org.knowm.xchange.Exchange)8 InputStream (java.io.InputStream)7 Order (org.knowm.xchange.dto.Order)7 OrderBook (org.knowm.xchange.dto.marketdata.OrderBook)7 Ticker (org.knowm.xchange.dto.marketdata.Ticker)7 LimitOrder (org.knowm.xchange.dto.trade.LimitOrder)7 JsonNode (com.fasterxml.jackson.databind.JsonNode)5 StreamingObjectMapperHelper (info.bitrich.xchangestream.service.netty.StreamingObjectMapperHelper)5 Observable (io.reactivex.Observable)5