use of org.knowm.xchange.dto.marketdata.Trade in project XChange by knowm.
the class BitsoAdapters method adaptTrades.
/**
* Adapts a Transaction[] to a Trades Object
*
* @param transactions The Bitso transactions
* @param currencyPair (e.g. BTC/MXN)
* @return The XChange Trades
*/
public static Trades adaptTrades(BitsoTransaction[] transactions, CurrencyPair currencyPair) {
List<Trade> trades = new ArrayList<>();
long lastTradeId = 0;
for (BitsoTransaction tx : transactions) {
Order.OrderType type;
switch(tx.getSide()) {
case "buy":
type = Order.OrderType.ASK;
break;
case "sell":
type = Order.OrderType.BID;
break;
default:
type = null;
}
final long tradeId = tx.getTid();
if (tradeId > lastTradeId) {
lastTradeId = tradeId;
}
trades.add(new Trade.Builder().type(type).originalAmount(tx.getAmount()).currencyPair(currencyPair).price(tx.getPrice()).timestamp(DateUtils.fromMillisUtc(tx.getDate() * 1000L)).id(String.valueOf(tradeId)).build());
}
return new Trades(trades, lastTradeId, TradeSortType.SortByID);
}
use of org.knowm.xchange.dto.marketdata.Trade 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.dto.marketdata.Trade 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);
}
use of org.knowm.xchange.dto.marketdata.Trade in project XChange by knowm.
the class CoinfloorPublicTradesIntegration method fetchTransactionTest.
@Test
public void fetchTransactionTest() throws IOException {
Exchange exchange = ExchangeFactory.INSTANCE.createExchange(CoinfloorExchange.class);
MarketDataService service = exchange.getMarketDataService();
Trades trades = service.getTrades(CurrencyPair.BTC_GBP, CoinfloorInterval.HOUR);
assertThat(trades.getTrades()).isNotEmpty();
int tradeCount = trades.getTrades().size();
Trade mostRecentTrade = trades.getTrades().get(tradeCount - 1);
assertThat(mostRecentTrade.getPrice()).isGreaterThan(BigDecimal.ZERO);
assertThat(mostRecentTrade.getOriginalAmount()).isGreaterThan(BigDecimal.ZERO);
assertThat(trades.getlastID()).isEqualTo(Long.parseLong(mostRecentTrade.getId()));
}
use of org.knowm.xchange.dto.marketdata.Trade in project XChange by knowm.
the class CoingiAdapters method adaptTrade.
/**
* Adapts a Transaction to a Trade Object
*
* @param tx The Coingi transaction
* @param currencyPair (e.g. BTC/USD)
* @param timeScale polled order books provide a timestamp in seconds, stream in ms
* @return The XChange Trade
*/
public static Trade adaptTrade(CoingiUserTransaction tx, CurrencyPair currencyPair, int timeScale) {
OrderType orderType = tx.getType() == 0 ? OrderType.BID : OrderType.ASK;
final String tradeId = tx.getId();
Date date = DateUtils.fromMillisUtc(tx.getTimestamp() * // polled order books provide a timestamp in seconds, stream in ms
timeScale);
return new Trade.Builder().type(orderType).originalAmount(tx.getBaseAmount()).currencyPair(currencyPair).price(tx.getPrice()).timestamp(date).id(tradeId).build();
}
Aggregations