Search in sources :

Example 6 with Trade

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

the class CoingiAdapters method adaptTrade.

public static Trade adaptTrade(org.knowm.xchange.coingi.dto.marketdata.CoingiTransaction tx, CurrencyPair currencyPair, int timeScale) {
    OrderType orderType = tx.getType() == 0 ? OrderType.BID : OrderType.ASK;
    final String tradeId = tx.getId();
    Date date = new Date(tx.getTimestamp());
    return new Trade.Builder().type(orderType).originalAmount(tx.getAmount()).currencyPair(currencyPair).price(tx.getPrice()).timestamp(date).id(tradeId).build();
}
Also used : UserTrade(org.knowm.xchange.dto.trade.UserTrade) Trade(org.knowm.xchange.dto.marketdata.Trade) OrderType(org.knowm.xchange.dto.Order.OrderType) Date(java.util.Date)

Example 7 with Trade

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

the class LatokenAdapters method adaptTrades.

public static Trades adaptTrades(Exchange exchange, LatokenTrades latokenTrades) {
    CurrencyPair pair = adaptCurrencyPair(exchange, latokenTrades.getSymbol());
    List<Trade> trades = latokenTrades.getTrades().stream().map(latokenTrade -> adaptTrade(latokenTrade, pair)).collect(Collectors.toList());
    return new Trades(trades, TradeSortType.SortByTimestamp);
}
Also used : LatokenOrderbook(org.knowm.xchange.latoken.dto.marketdata.LatokenOrderbook) OrderType(org.knowm.xchange.dto.Order.OrderType) LatokenBalance(org.knowm.xchange.latoken.dto.account.LatokenBalance) LatokenUserTrade(org.knowm.xchange.latoken.dto.trade.LatokenUserTrade) Exchange(org.knowm.xchange.Exchange) OrderBook(org.knowm.xchange.dto.marketdata.OrderBook) Balance(org.knowm.xchange.dto.account.Balance) TradeSortType(org.knowm.xchange.dto.marketdata.Trades.TradeSortType) BigDecimal(java.math.BigDecimal) CurrencyPairMetaData(org.knowm.xchange.dto.meta.CurrencyPairMetaData) LatokenCurrency(org.knowm.xchange.latoken.dto.exchangeinfo.LatokenCurrency) LatokenTrades(org.knowm.xchange.latoken.dto.marketdata.LatokenTrades) LatokenPair(org.knowm.xchange.latoken.dto.exchangeinfo.LatokenPair) OpenOrders(org.knowm.xchange.dto.trade.OpenOrders) RoundingMode(java.math.RoundingMode) LimitOrder(org.knowm.xchange.dto.trade.LimitOrder) OrderStatus(org.knowm.xchange.dto.Order.OrderStatus) Ticker(org.knowm.xchange.dto.marketdata.Ticker) LatokenOrder(org.knowm.xchange.latoken.dto.trade.LatokenOrder) LatokenOrderSide(org.knowm.xchange.latoken.dto.trade.LatokenOrderSide) UserTrades(org.knowm.xchange.dto.trade.UserTrades) UserTrade(org.knowm.xchange.dto.trade.UserTrade) LatokenOrderStatus(org.knowm.xchange.latoken.dto.trade.LatokenOrderStatus) LatokenTicker(org.knowm.xchange.latoken.dto.marketdata.LatokenTicker) Collectors(java.util.stream.Collectors) Trades(org.knowm.xchange.dto.marketdata.Trades) ExchangeException(org.knowm.xchange.exceptions.ExchangeException) LatokenTrade(org.knowm.xchange.latoken.dto.marketdata.LatokenTrade) List(java.util.List) Currency(org.knowm.xchange.currency.Currency) Optional(java.util.Optional) Trade(org.knowm.xchange.dto.marketdata.Trade) CurrencyPair(org.knowm.xchange.currency.CurrencyPair) LatokenUserTrades(org.knowm.xchange.latoken.dto.trade.LatokenUserTrades) LatokenUserTrade(org.knowm.xchange.latoken.dto.trade.LatokenUserTrade) UserTrade(org.knowm.xchange.dto.trade.UserTrade) LatokenTrade(org.knowm.xchange.latoken.dto.marketdata.LatokenTrade) Trade(org.knowm.xchange.dto.marketdata.Trade) LatokenTrades(org.knowm.xchange.latoken.dto.marketdata.LatokenTrades) UserTrades(org.knowm.xchange.dto.trade.UserTrades) Trades(org.knowm.xchange.dto.marketdata.Trades) LatokenUserTrades(org.knowm.xchange.latoken.dto.trade.LatokenUserTrades) CurrencyPair(org.knowm.xchange.currency.CurrencyPair)

Example 8 with Trade

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

the class CoinmateStreamingMarketDataServiceTest method testGetTrades.

@Test
public void testGetTrades() throws Exception {
    ObjectMapper mapper = new ObjectMapper();
    String trade = new String(Files.readAllBytes(Paths.get(ClassLoader.getSystemResource("trades.json").toURI())));
    CoinmateStreamingService mockService = mock(CoinmateStreamingService.class);
    when(mockService.subscribeChannel(anyString())).thenReturn(Observable.just(mapper.readTree(trade)));
    CoinmateStreamingMarketDataService marketDataService = new CoinmateStreamingMarketDataService(mockService);
    Trade expected1 = new Trade.Builder().type(null).originalAmount(new BigDecimal("0.08233888")).currencyPair(CurrencyPair.BTC_CZK).price(new BigDecimal("855.29")).timestamp(new Date(1484863030522L)).type(Order.OrderType.BID).build();
    Trade expected2 = new Trade.Builder().type(null).originalAmount(new BigDecimal("0.00200428")).currencyPair(CurrencyPair.BTC_CZK).price(new BigDecimal("855.13")).timestamp(new Date(1484863028887L)).type(Order.OrderType.ASK).build();
    TestObserver<Trade> test = marketDataService.getTrades(CurrencyPair.BTC_CZK).test();
    test.assertValueAt(0, trade1 -> {
        assertThat(trade1.getId()).as("Id").isEqualTo(expected1.getId());
        assertThat(trade1.getCurrencyPair()).as("Currency pair").isEqualTo(expected1.getCurrencyPair());
        assertThat(trade1.getPrice()).as("Price").isEqualTo(expected1.getPrice());
        assertThat(trade1.getTimestamp()).as("Timestamp").isEqualTo(expected1.getTimestamp());
        assertThat(trade1.getOriginalAmount()).as("Amount").isEqualTo(expected1.getOriginalAmount());
        assertThat(trade1.getType()).as("Type").isEqualTo(expected1.getType());
        return true;
    });
    test.assertValueAt(1, trade1 -> {
        assertThat(trade1.getId()).as("Id").isEqualTo(expected2.getId());
        assertThat(trade1.getCurrencyPair()).as("Currency pair").isEqualTo(expected2.getCurrencyPair());
        assertThat(trade1.getPrice()).as("Price").isEqualTo(expected2.getPrice());
        assertThat(trade1.getTimestamp()).as("Timestamp").isEqualTo(expected2.getTimestamp());
        assertThat(trade1.getOriginalAmount()).as("Amount").isEqualTo(expected2.getOriginalAmount());
        assertThat(trade1.getType()).as("Type").isEqualTo(expected2.getType());
        return true;
    });
    test.assertNoErrors();
}
Also used : Trade(org.knowm.xchange.dto.marketdata.Trade) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) BigDecimal(java.math.BigDecimal) Date(java.util.Date) Test(org.junit.Test)

Example 9 with Trade

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

the class BitbayAdapters method adaptTrades.

/**
 * @param bitbayTrades
 * @param currencyPair
 * @return
 */
public static Trades adaptTrades(BitbayTrade[] bitbayTrades, CurrencyPair currencyPair) {
    List<Trade> tradeList = new ArrayList<>();
    for (BitbayTrade bitbayTrade : bitbayTrades) {
        Trade trade = new Trade.Builder().originalAmount(bitbayTrade.getAmount()).currencyPair(currencyPair).price(bitbayTrade.getPrice()).timestamp(new Date(bitbayTrade.getDate() * 1000)).id(bitbayTrade.getTid()).build();
        tradeList.add(trade);
    }
    Trades trades = new Trades(tradeList, Trades.TradeSortType.SortByTimestamp);
    return trades;
}
Also used : BitbayTrade(org.knowm.xchange.bitbay.dto.marketdata.BitbayTrade) UserTrade(org.knowm.xchange.dto.trade.UserTrade) Trade(org.knowm.xchange.dto.marketdata.Trade) BitbayTrade(org.knowm.xchange.bitbay.dto.marketdata.BitbayTrade) UserTrades(org.knowm.xchange.dto.trade.UserTrades) Trades(org.knowm.xchange.dto.marketdata.Trades) ArrayList(java.util.ArrayList) Date(java.util.Date)

Example 10 with Trade

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

the class CCEXAdapters method adaptTrades.

public static Trades adaptTrades(CCEXTrades cCEXTrades, CurrencyPair currencyPair) {
    List<Trade> trades = new ArrayList<>();
    List<CCEXTrade> cCEXTradestmp = cCEXTrades.getResult();
    for (CCEXTrade cCEXTrade : cCEXTradestmp) {
        trades.add(adaptCCEXPublicTrade(cCEXTrade, currencyPair));
    }
    return new Trades(trades, TradeSortType.SortByTimestamp);
}
Also used : CCEXTrade(org.knowm.xchange.ccex.dto.marketdata.CCEXTrade) UserTrade(org.knowm.xchange.dto.trade.UserTrade) Trade(org.knowm.xchange.dto.marketdata.Trade) CCEXTrade(org.knowm.xchange.ccex.dto.marketdata.CCEXTrade) Trades(org.knowm.xchange.dto.marketdata.Trades) CCEXTrades(org.knowm.xchange.ccex.dto.marketdata.CCEXTrades) ArrayList(java.util.ArrayList)

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