Search in sources :

Example 1 with BitfinexTradeResponse

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);
}
Also used : UserTrades(org.knowm.xchange.dto.trade.UserTrades) OrderType(org.knowm.xchange.dto.Order.OrderType) BitfinexOrderType(org.knowm.xchange.bitfinex.v1.BitfinexOrderType) ArrayList(java.util.ArrayList) UserTrade(org.knowm.xchange.dto.trade.UserTrade) BitfinexTradeResponse(org.knowm.xchange.bitfinex.v1.dto.trade.BitfinexTradeResponse) Date(java.util.Date) BigDecimal(java.math.BigDecimal) CurrencyPair(org.knowm.xchange.currency.CurrencyPair)

Example 2 with BitfinexTradeResponse

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());
    }
}
Also used : Order(org.knowm.xchange.dto.Order) LimitOrder(org.knowm.xchange.dto.trade.LimitOrder) Trade(org.knowm.xchange.dto.marketdata.Trade) Trades(org.knowm.xchange.dto.marketdata.Trades) OrderType(org.knowm.xchange.dto.Order.OrderType) BitfinexTradeResponse(org.knowm.xchange.bitfinex.v1.dto.trade.BitfinexTradeResponse) 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)

Example 3 with BitfinexTradeResponse

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

Aggregations

BigDecimal (java.math.BigDecimal)3 BitfinexTradeResponse (org.knowm.xchange.bitfinex.v1.dto.trade.BitfinexTradeResponse)3 OrderType (org.knowm.xchange.dto.Order.OrderType)2 ArrayList (java.util.ArrayList)1 Date (java.util.Date)1 Test (org.junit.Test)1 BitfinexOrderType (org.knowm.xchange.bitfinex.v1.BitfinexOrderType)1 BitfinexFeesJSONTest (org.knowm.xchange.bitfinex.v1.dto.account.BitfinexFeesJSONTest)1 BitfinexWalletJSONTest (org.knowm.xchange.bitfinex.v1.dto.account.BitfinexWalletJSONTest)1 CurrencyPair (org.knowm.xchange.currency.CurrencyPair)1 Order (org.knowm.xchange.dto.Order)1 Trade (org.knowm.xchange.dto.marketdata.Trade)1 Trades (org.knowm.xchange.dto.marketdata.Trades)1 LimitOrder (org.knowm.xchange.dto.trade.LimitOrder)1 UserTrade (org.knowm.xchange.dto.trade.UserTrade)1 UserTrades (org.knowm.xchange.dto.trade.UserTrades)1