Search in sources :

Example 1 with BitstampTransaction

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);
}
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) BitstampTransaction(org.knowm.xchange.bitstamp.dto.marketdata.BitstampTransaction)

Example 2 with BitstampTransaction

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);
}
Also used : UserTrades(org.knowm.xchange.dto.trade.UserTrades) Trades(org.knowm.xchange.dto.marketdata.Trades) InputStream(java.io.InputStream) BitstampTransaction(org.knowm.xchange.bitstamp.dto.marketdata.BitstampTransaction) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) BigDecimal(java.math.BigDecimal) Test(org.junit.Test)

Example 3 with BitstampTransaction

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);
}
Also used : Trade(org.knowm.xchange.dto.marketdata.Trade) InputStream(java.io.InputStream) BitstampTransaction(org.knowm.xchange.bitstamp.dto.marketdata.BitstampTransaction) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) BigDecimal(java.math.BigDecimal) Test(org.junit.Test)

Aggregations

BitstampTransaction (org.knowm.xchange.bitstamp.dto.marketdata.BitstampTransaction)3 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)2 InputStream (java.io.InputStream)2 BigDecimal (java.math.BigDecimal)2 Test (org.junit.Test)2 Trade (org.knowm.xchange.dto.marketdata.Trade)2 Trades (org.knowm.xchange.dto.marketdata.Trades)2 UserTrades (org.knowm.xchange.dto.trade.UserTrades)2 ArrayList (java.util.ArrayList)1 UserTrade (org.knowm.xchange.dto.trade.UserTrade)1