use of org.knowm.xchange.bitfinex.v1.dto.trade.BitfinexTradeResponse in project XChange by knowm.
the class BitfinexAdapters method adaptTradeHistory.
public static UserTrades adaptTradeHistory(BitfinexTradeResponse[] trades, String symbol) {
List<UserTrade> pastTrades = new ArrayList<>(trades.length);
CurrencyPair currencyPair = adaptCurrencyPair(symbol);
for (BitfinexTradeResponse trade : trades) {
OrderType orderType = trade.getType().equalsIgnoreCase("buy") ? OrderType.BID : OrderType.ASK;
Date timestamp = convertBigDecimalTimestampToDate(trade.getTimestamp());
final BigDecimal fee = trade.getFeeAmount() == null ? null : trade.getFeeAmount().negate();
pastTrades.add(new UserTrade.Builder().type(orderType).originalAmount(trade.getAmount()).currencyPair(currencyPair).price(trade.getPrice()).timestamp(timestamp).id(trade.getTradeId()).orderId(trade.getOrderId()).feeAmount(fee).feeCurrency(Currency.getInstance(trade.getFeeCurrency())).build());
}
return new UserTrades(pastTrades, TradeSortType.SortByTimestamp);
}
use of org.knowm.xchange.bitfinex.v1.dto.trade.BitfinexTradeResponse in project XChange by knowm.
the class BitfinexAdaptersTest method testAdaptTradeHistory.
@Test
public void testAdaptTradeHistory() {
BitfinexTradeResponse[] responses = initTradeResponses();
Trades trades = BitfinexAdapters.adaptTradeHistory(responses, SYMBOL);
assertEquals(trades.getTrades().size(), responses.length);
for (int i = 0; i < responses.length; i++) {
Trade trade = trades.getTrades().get(i);
long expectedTimestampMillis = responses[i].getTimestamp().multiply(new BigDecimal(1000L)).longValue();
Order.OrderType expectedOrderType = responses[i].getType().equalsIgnoreCase("buy") ? OrderType.BID : OrderType.ASK;
assertEquals(responses[i].getPrice(), trade.getPrice());
assertEquals(responses[i].getAmount(), trade.getOriginalAmount());
assertEquals(BitfinexAdapters.adaptCurrencyPair(SYMBOL), trade.getCurrencyPair());
assertEquals(expectedTimestampMillis, trade.getTimestamp().getTime());
assertEquals(expectedOrderType, trade.getType());
assertEquals(responses[i].getTradeId(), trade.getId());
}
}
use of org.knowm.xchange.bitfinex.v1.dto.trade.BitfinexTradeResponse in project XChange by knowm.
the class BitfinexAdaptersTest method initTradeResponses.
/**
* Create 60 {@link BitfinexTradeResponse}s. The values increase as array index does. The
* timestamps increase by 1 second + 1 minute + 1 hour + 1 day in order to test the correct
* handling of the given timestamp.
*
* @return The generated responses.
*/
private BitfinexTradeResponse[] initTradeResponses() {
BitfinexTradeResponse[] responses = new BitfinexTradeResponse[60];
int tradeId = 2000;
int orderId = 1000;
for (int i = 0; i < responses.length; i++) {
BigDecimal price = new BigDecimal(350L + i);
BigDecimal amount = new BigDecimal(1L + i);
BigDecimal timestamp = new BigDecimal("1414658239.41373654").add(new BigDecimal(i * (1 + 60 + 60 * 60 + 60 * 60 * 24)));
String type = i % 2 == 0 ? "buy" : "sell";
String tradeIdString = String.valueOf(tradeId++);
String orderIdString = String.valueOf(orderId++);
BigDecimal feeAmount = new BigDecimal(0L);
String feeCurrency = "USD";
responses[i] = new BitfinexTradeResponse(price, amount, timestamp, MARKET, type, tradeIdString, orderIdString, feeAmount, feeCurrency);
}
return responses;
}
Aggregations