use of org.knowm.xchange.bitstamp.dto.marketdata.BitstampTransaction in project XChange by knowm.
the class BitstampAdapters method adaptTrades.
/**
* Adapts a Transaction[] to a Trades Object
*
* @param transactions The Bitstamp transactions
* @param currencyPair (e.g. BTC/USD)
* @return The XChange Trades
*/
public static Trades adaptTrades(BitstampTransaction[] transactions, CurrencyPair currencyPair) {
List<Trade> trades = new ArrayList<>();
long lastTradeId = 0;
for (BitstampTransaction tx : transactions) {
final long tradeId = tx.getTid();
if (tradeId > lastTradeId) {
lastTradeId = tradeId;
}
trades.add(adaptTrade(tx, currencyPair, 1000));
}
return new Trades(trades, lastTradeId, TradeSortType.SortByID);
}
use of org.knowm.xchange.bitstamp.dto.marketdata.BitstampTransaction in project XChange by knowm.
the class BitstampAdapterTest method testTradesAdapter.
@Test
public void testTradesAdapter() throws IOException {
// Read in the JSON from the example resources
InputStream is = BitstampAdapterTest.class.getResourceAsStream("/org/knowm/xchange/bitstamp/dto/marketdata/example-trades-data.json");
// Use Jackson to parse it
ObjectMapper mapper = new ObjectMapper();
BitstampTransaction[] transactions = mapper.readValue(is, BitstampTransaction[].class);
Trades trades = BitstampAdapters.adaptTrades(transactions, CurrencyPair.BTC_USD);
assertThat(trades.getTrades().size()).isEqualTo(125);
assertThat(trades.getlastID()).isEqualTo(122260);
// verify all fields filled
assertThat(trades.getTrades().get(0).getId()).isEqualTo("121984");
assertThat(trades.getTrades().get(0).getPrice().toString()).isEqualTo("13.14");
assertThat(trades.getTrades().get(0).getType()).isEqualTo(OrderType.BID);
assertThat(trades.getTrades().get(0).getOriginalAmount()).isEqualTo(new BigDecimal("10.11643836"));
assertThat(trades.getTrades().get(0).getCurrencyPair()).isEqualTo(CurrencyPair.BTC_USD);
}
use of org.knowm.xchange.bitstamp.dto.marketdata.BitstampTransaction in project XChange by knowm.
the class BitstampAdapterTest method testTradeAdapter.
@Test
public void testTradeAdapter() throws IOException {
// Read in the JSON from the example resources
InputStream is = BitstampAdapterTest.class.getResourceAsStream("/org/knowm/xchange/bitstamp/dto/marketdata/example-trades-data.json");
// Use Jackson to parse it
ObjectMapper mapper = new ObjectMapper();
BitstampTransaction[] transactions = mapper.readValue(is, BitstampTransaction[].class);
Trade trade = BitstampAdapters.adaptTrade(transactions[3], CurrencyPair.BTC_USD, 1000);
// verify all fields filled
assertThat(trade.getPrice().toString()).isEqualTo("13.14");
assertThat(trade.getType()).isEqualTo(OrderType.BID);
assertThat(trade.getOriginalAmount()).isEqualTo(new BigDecimal("23.66362253"));
assertThat(trade.getCurrencyPair()).isEqualTo(CurrencyPair.BTC_USD);
}
Aggregations