use of org.knowm.xchange.bitfinex.v1.dto.marketdata.BitfinexLevel in project XChange by knowm.
the class BitfinexAdapters method adaptOrders.
public static OrdersContainer adaptOrders(BitfinexLevel[] bitfinexLevels, CurrencyPair currencyPair, OrderType orderType) {
BigDecimal maxTimestamp = new BigDecimal(Long.MIN_VALUE);
List<LimitOrder> limitOrders = new ArrayList<>(bitfinexLevels.length);
for (BitfinexLevel bitfinexLevel : bitfinexLevels) {
if (bitfinexLevel.getTimestamp().compareTo(maxTimestamp) > 0) {
maxTimestamp = bitfinexLevel.getTimestamp();
}
Date timestamp = convertBigDecimalTimestampToDate(bitfinexLevel.getTimestamp());
limitOrders.add(adaptOrder(bitfinexLevel.getAmount(), bitfinexLevel.getPrice(), currencyPair, orderType, timestamp));
}
long maxTimestampInMillis = maxTimestamp.multiply(new BigDecimal(1000L)).longValue();
return new OrdersContainer(maxTimestampInMillis, limitOrders);
}
use of org.knowm.xchange.bitfinex.v1.dto.marketdata.BitfinexLevel in project XChange by knowm.
the class BitfinexAdaptersTest method initLevels.
/**
* Create 60 {@link BitfinexLevel}s. The values increase as the 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 BitfinexLevel[] initLevels() {
BitfinexLevel[] responses = new BitfinexLevel[60];
for (int i = 0; i < responses.length; i++) {
BigDecimal price = new BigDecimal(350L + i);
BigDecimal timestamp = new BigDecimal("1414669893.823615468").add(new BigDecimal(i * (1 + 60 + 60 * 60 + 60 * 60 * 24)));
BigDecimal amount = new BigDecimal(1L + i);
responses[i] = new BitfinexLevel(price, amount, timestamp);
}
return responses;
}
use of org.knowm.xchange.bitfinex.v1.dto.marketdata.BitfinexLevel in project XChange by knowm.
the class BitfinexAdaptersTest method testAdaptOrdersToOrdersContainer.
@Test
public void testAdaptOrdersToOrdersContainer() {
BitfinexLevel[] levels = initLevels();
BitfinexAdapters.OrdersContainer container = BitfinexAdapters.adaptOrders(levels, CurrencyPair.BTC_USD, OrderType.BID);
BitfinexLevel lastLevel = levels[levels.length - 1];
assertEquals(lastLevel.getTimestamp().multiply(new BigDecimal(1000L)).longValue(), container.getTimestamp());
assertEquals(container.getLimitOrders().size(), levels.length);
for (int i = 0; i < levels.length; i++) {
LimitOrder order = container.getLimitOrders().get(i);
long expectedTimestampMillis = levels[i].getTimestamp().multiply(new BigDecimal(1000L)).longValue();
assertEquals(levels[i].getAmount(), order.getOriginalAmount());
assertEquals(expectedTimestampMillis, order.getTimestamp().getTime());
assertEquals(levels[i].getPrice(), order.getLimitPrice());
}
}
Aggregations