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();
}
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);
}
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();
}
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;
}
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);
}
Aggregations