Search in sources :

Example 11 with BitfinexTick

use of com.github.jnidzwetzki.bitfinex.v2.entity.BitfinexTick in project bitfinex-v2-wss-api-java by jnidzwetzki.

the class CandlestickHandler method handleChannelData.

/**
 * Handle a candlestick callback
 * @param channel
 * @param subarray
 */
@Override
public void handleChannelData(final BitfinexApiBroker bitfinexApiBroker, final BitfinexStreamSymbol channelSymbol, final JSONArray jsonArray) throws APIException {
    // channel symbol trade:1m:tLTCUSD
    final List<BitfinexTick> ticksBuffer = new ArrayList<>();
    // Snapshots contain multiple Bars, Updates only one
    if (jsonArray.get(0) instanceof JSONArray) {
        for (int pos = 0; pos < jsonArray.length(); pos++) {
            final JSONArray parts = jsonArray.getJSONArray(pos);
            parseCandlestick(ticksBuffer, parts);
        }
    } else {
        parseCandlestick(ticksBuffer, jsonArray);
    }
    // Use natural ordering
    ticksBuffer.sort(null);
    final BitfinexCandlestickSymbol candlestickSymbol = (BitfinexCandlestickSymbol) channelSymbol;
    bitfinexApiBroker.getQuoteManager().handleCandlestickList(candlestickSymbol, ticksBuffer);
}
Also used : BitfinexTick(com.github.jnidzwetzki.bitfinex.v2.entity.BitfinexTick) BitfinexCandlestickSymbol(com.github.jnidzwetzki.bitfinex.v2.entity.symbol.BitfinexCandlestickSymbol) ArrayList(java.util.ArrayList) JSONArray(org.json.JSONArray)

Example 12 with BitfinexTick

use of com.github.jnidzwetzki.bitfinex.v2.entity.BitfinexTick in project bitfinex-v2-wss-api-java by jnidzwetzki.

the class CandlestickHandler method parseCandlestick.

/**
 * Parse a candlestick from JSON result
 */
private void parseCandlestick(final List<BitfinexTick> ticksBuffer, final JSONArray parts) {
    // 0 = Timestamp, 1 = Open, 2 = Close, 3 = High, 4 = Low,  5 = Volume
    final long timestamp = parts.getLong(0);
    final BigDecimal open = parts.getBigDecimal(1);
    final BigDecimal close = parts.getBigDecimal(2);
    final BigDecimal high = parts.getBigDecimal(3);
    final BigDecimal low = parts.getBigDecimal(4);
    final BigDecimal volume = parts.getBigDecimal(5);
    final BitfinexTick tick = new BitfinexTick(timestamp, open, close, high, low, volume);
    ticksBuffer.add(tick);
}
Also used : BitfinexTick(com.github.jnidzwetzki.bitfinex.v2.entity.BitfinexTick) BigDecimal(java.math.BigDecimal)

Aggregations

BitfinexTick (com.github.jnidzwetzki.bitfinex.v2.entity.BitfinexTick)12 Test (org.junit.Test)7 BitfinexCurrencyPair (com.github.jnidzwetzki.bitfinex.v2.entity.BitfinexCurrencyPair)5 BitfinexCandlestickSymbol (com.github.jnidzwetzki.bitfinex.v2.entity.symbol.BitfinexCandlestickSymbol)5 BitfinexTickerSymbol (com.github.jnidzwetzki.bitfinex.v2.entity.symbol.BitfinexTickerSymbol)5 BitfinexApiBroker (com.github.jnidzwetzki.bitfinex.v2.BitfinexApiBroker)4 APIException (com.github.jnidzwetzki.bitfinex.v2.entity.APIException)4 Timeframe (com.github.jnidzwetzki.bitfinex.v2.entity.Timeframe)4 BigDecimal (java.math.BigDecimal)4 CountDownLatch (java.util.concurrent.CountDownLatch)4 BiConsumer (java.util.function.BiConsumer)4 ExecutedTrade (com.github.jnidzwetzki.bitfinex.v2.entity.ExecutedTrade)3 OrderBookFrequency (com.github.jnidzwetzki.bitfinex.v2.entity.OrderBookFrequency)3 OrderBookPrecision (com.github.jnidzwetzki.bitfinex.v2.entity.OrderBookPrecision)3 OrderbookConfiguration (com.github.jnidzwetzki.bitfinex.v2.entity.OrderbookConfiguration)3 OrderbookEntry (com.github.jnidzwetzki.bitfinex.v2.entity.OrderbookEntry)3 RawOrderbookConfiguration (com.github.jnidzwetzki.bitfinex.v2.entity.RawOrderbookConfiguration)3 RawOrderbookEntry (com.github.jnidzwetzki.bitfinex.v2.entity.RawOrderbookEntry)3 BitfinexExecutedTradeSymbol (com.github.jnidzwetzki.bitfinex.v2.entity.symbol.BitfinexExecutedTradeSymbol)3 OrderbookManager (com.github.jnidzwetzki.bitfinex.v2.manager.OrderbookManager)3