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);
}
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);
}
Aggregations