Search in sources :

Example 6 with BitfinexStreamSymbol

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);
}
Also used : BitfinexStreamSymbol(com.github.jnidzwetzki.bitfinex.v2.entity.symbol.BitfinexStreamSymbol)

Example 7 with BitfinexStreamSymbol

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);
}
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 8 with BitfinexStreamSymbol

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);
    }
}
Also used : APIException(com.github.jnidzwetzki.bitfinex.v2.entity.APIException) BitfinexStreamSymbol(com.github.jnidzwetzki.bitfinex.v2.entity.symbol.BitfinexStreamSymbol)

Example 9 with BitfinexStreamSymbol

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);
    }
}
Also used : BitfinexExecutedTradeSymbol(com.github.jnidzwetzki.bitfinex.v2.entity.symbol.BitfinexExecutedTradeSymbol) APIException(com.github.jnidzwetzki.bitfinex.v2.entity.APIException) JSONArray(org.json.JSONArray) JSONException(org.json.JSONException)

Example 10 with BitfinexStreamSymbol

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);
    }
}
Also used : APIException(com.github.jnidzwetzki.bitfinex.v2.entity.APIException) OrderbookConfiguration(com.github.jnidzwetzki.bitfinex.v2.entity.OrderbookConfiguration) JSONArray(org.json.JSONArray) JSONException(org.json.JSONException)

Aggregations

JSONArray (org.json.JSONArray)5 APIException (com.github.jnidzwetzki.bitfinex.v2.entity.APIException)4 BitfinexStreamSymbol (com.github.jnidzwetzki.bitfinex.v2.entity.symbol.BitfinexStreamSymbol)4 OrderbookConfiguration (com.github.jnidzwetzki.bitfinex.v2.entity.OrderbookConfiguration)3 RawOrderbookConfiguration (com.github.jnidzwetzki.bitfinex.v2.entity.RawOrderbookConfiguration)3 BitfinexCandlestickSymbol (com.github.jnidzwetzki.bitfinex.v2.entity.symbol.BitfinexCandlestickSymbol)3 BitfinexExecutedTradeSymbol (com.github.jnidzwetzki.bitfinex.v2.entity.symbol.BitfinexExecutedTradeSymbol)3 BitfinexTickerSymbol (com.github.jnidzwetzki.bitfinex.v2.entity.symbol.BitfinexTickerSymbol)3 JSONException (org.json.JSONException)3 BitfinexTick (com.github.jnidzwetzki.bitfinex.v2.entity.BitfinexTick)2 CandlestickHandler (com.github.jnidzwetzki.bitfinex.v2.callback.channel.CandlestickHandler)1 ChannelCallbackHandler (com.github.jnidzwetzki.bitfinex.v2.callback.channel.ChannelCallbackHandler)1 ExecutedTradeHandler (com.github.jnidzwetzki.bitfinex.v2.callback.channel.ExecutedTradeHandler)1 OrderbookHandler (com.github.jnidzwetzki.bitfinex.v2.callback.channel.OrderbookHandler)1 RawOrderbookHandler (com.github.jnidzwetzki.bitfinex.v2.callback.channel.RawOrderbookHandler)1 TickHandler (com.github.jnidzwetzki.bitfinex.v2.callback.channel.TickHandler)1 SubscribeCandlesCommand (com.github.jnidzwetzki.bitfinex.v2.commands.SubscribeCandlesCommand)1 SubscribeOrderbookCommand (com.github.jnidzwetzki.bitfinex.v2.commands.SubscribeOrderbookCommand)1 SubscribeRawOrderbookCommand (com.github.jnidzwetzki.bitfinex.v2.commands.SubscribeRawOrderbookCommand)1 SubscribeTickerCommand (com.github.jnidzwetzki.bitfinex.v2.commands.SubscribeTickerCommand)1