Search in sources :

Example 1 with BitfinexLevel

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);
}
Also used : BitfinexLevel(org.knowm.xchange.bitfinex.v1.dto.marketdata.BitfinexLevel) ArrayList(java.util.ArrayList) LimitOrder(org.knowm.xchange.dto.trade.LimitOrder) BigDecimal(java.math.BigDecimal) Date(java.util.Date)

Example 2 with BitfinexLevel

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;
}
Also used : BitfinexLevel(org.knowm.xchange.bitfinex.v1.dto.marketdata.BitfinexLevel) BigDecimal(java.math.BigDecimal)

Example 3 with BitfinexLevel

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());
    }
}
Also used : BitfinexLevel(org.knowm.xchange.bitfinex.v1.dto.marketdata.BitfinexLevel) BitfinexAdapters(org.knowm.xchange.bitfinex.service.BitfinexAdapters) LimitOrder(org.knowm.xchange.dto.trade.LimitOrder) BigDecimal(java.math.BigDecimal) BitfinexFeesJSONTest(org.knowm.xchange.bitfinex.v1.dto.account.BitfinexFeesJSONTest) BitfinexWalletJSONTest(org.knowm.xchange.bitfinex.v1.dto.account.BitfinexWalletJSONTest) Test(org.junit.Test)

Aggregations

BigDecimal (java.math.BigDecimal)3 BitfinexLevel (org.knowm.xchange.bitfinex.v1.dto.marketdata.BitfinexLevel)3 LimitOrder (org.knowm.xchange.dto.trade.LimitOrder)2 ArrayList (java.util.ArrayList)1 Date (java.util.Date)1 Test (org.junit.Test)1 BitfinexAdapters (org.knowm.xchange.bitfinex.service.BitfinexAdapters)1 BitfinexFeesJSONTest (org.knowm.xchange.bitfinex.v1.dto.account.BitfinexFeesJSONTest)1 BitfinexWalletJSONTest (org.knowm.xchange.bitfinex.v1.dto.account.BitfinexWalletJSONTest)1