use of com.github.jnidzwetzki.bitfinex.v2.entity.symbol.BitfinexStreamSymbol in project bitfinex-v2-wss-api-java by jnidzwetzki.
the class UnsubscribedCallback method handleChannelData.
@Override
public void handleChannelData(final BitfinexApiBroker bitfinexApiBroker, final JSONObject jsonObject) throws APIException {
final int channelId = jsonObject.getInt("chanId");
final BitfinexStreamSymbol symbol = bitfinexApiBroker.getFromChannelSymbolMap(channelId);
logger.info("Channel {} ({}) is unsubscribed", channelId, symbol);
bitfinexApiBroker.removeChannel(channelId);
}
use of com.github.jnidzwetzki.bitfinex.v2.entity.symbol.BitfinexStreamSymbol 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.symbol.BitfinexStreamSymbol in project bitfinex-v2-wss-api-java by jnidzwetzki.
the class BitfinexApiBroker method handleChannelData.
/**
* Handle normal channel data
* @param jsonArray
* @param channel
* @throws APIException
*/
private void handleChannelData(final JSONArray jsonArray) {
final int channel = jsonArray.getInt(0);
final BitfinexStreamSymbol channelSymbol = getFromChannelSymbolMap(channel);
if (channelSymbol == null) {
logger.error("Unable to determine symbol for channel {}", channel);
logger.error("Data is {}", jsonArray);
return;
}
try {
if (jsonArray.get(1) instanceof String) {
handleChannelDataString(jsonArray, channelSymbol);
} else {
handleChannelDataArray(jsonArray, channelSymbol);
}
} catch (APIException e) {
logger.error("Got exception while handling callback", e);
}
}
use of com.github.jnidzwetzki.bitfinex.v2.entity.symbol.BitfinexStreamSymbol in project bitfinex-v2-wss-api-java by jnidzwetzki.
the class ExecutedTradeHandler method handleChannelData.
@Override
public void handleChannelData(final BitfinexApiBroker bitfinexApiBroker, final BitfinexStreamSymbol channelSymbol, final JSONArray jsonArray) throws APIException {
final BitfinexExecutedTradeSymbol configuration = (BitfinexExecutedTradeSymbol) channelSymbol;
try {
// Snapshots contain multiple executes entries, updates only one
if (jsonArray.get(0) instanceof JSONArray) {
for (int pos = 0; pos < jsonArray.length(); pos++) {
final JSONArray parts = jsonArray.getJSONArray(pos);
handleEntry(bitfinexApiBroker, configuration, parts);
}
} else {
handleEntry(bitfinexApiBroker, configuration, jsonArray);
}
} catch (JSONException e) {
throw new APIException(e);
}
}
use of com.github.jnidzwetzki.bitfinex.v2.entity.symbol.BitfinexStreamSymbol in project bitfinex-v2-wss-api-java by jnidzwetzki.
the class OrderbookHandler method handleChannelData.
@Override
public void handleChannelData(final BitfinexApiBroker bitfinexApiBroker, final BitfinexStreamSymbol channelSymbol, final JSONArray jsonArray) throws APIException {
final OrderbookConfiguration configuration = (OrderbookConfiguration) channelSymbol;
// Example: [13182,1,-0.1]
try {
// Snapshots contain multiple Orderbook entries, updates only one
if (jsonArray.get(0) instanceof JSONArray) {
for (int pos = 0; pos < jsonArray.length(); pos++) {
final JSONArray parts = jsonArray.getJSONArray(pos);
handleEntry(bitfinexApiBroker, configuration, parts);
}
} else {
handleEntry(bitfinexApiBroker, configuration, jsonArray);
}
} catch (JSONException e) {
throw new APIException(e);
}
}
Aggregations