Search in sources :

Example 26 with BitfinexApiBroker

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

the class RawOrderbookHandler method handleChannelData.

@Override
public void handleChannelData(final BitfinexApiBroker bitfinexApiBroker, final BitfinexStreamSymbol channelSymbol, final JSONArray jsonArray) throws APIException {
    final RawOrderbookConfiguration configuration = (RawOrderbookConfiguration) 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 : RawOrderbookConfiguration(com.github.jnidzwetzki.bitfinex.v2.entity.RawOrderbookConfiguration) APIException(com.github.jnidzwetzki.bitfinex.v2.entity.APIException) JSONArray(org.json.JSONArray) JSONException(org.json.JSONException)

Example 27 with BitfinexApiBroker

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

the class TickHandler method handleChannelData.

/**
 * Handle a tick callback
 * @param channel
 * @param subarray
 */
@Override
public void handleChannelData(final BitfinexApiBroker bitfinexApiBroker, final BitfinexStreamSymbol channelSymbol, final JSONArray jsonArray) throws APIException {
    final BitfinexTickerSymbol currencyPair = (BitfinexTickerSymbol) channelSymbol;
    // 0 = BID
    // 2 = ASK
    // 6 = Price
    final BigDecimal price = jsonArray.getBigDecimal(6);
    // Volume is set to 0, because the ticker contains only the daily volume
    final BitfinexTick tick = new BitfinexTick(System.currentTimeMillis(), price, price, price, price);
    bitfinexApiBroker.getQuoteManager().handleNewTick(currencyPair, tick);
}
Also used : BitfinexTick(com.github.jnidzwetzki.bitfinex.v2.entity.BitfinexTick) BitfinexTickerSymbol(com.github.jnidzwetzki.bitfinex.v2.entity.symbol.BitfinexTickerSymbol) BigDecimal(java.math.BigDecimal)

Example 28 with BitfinexApiBroker

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

the class SubscribedCallback method handleCandlesCallback.

/**
 * Handle the candles callback
 *
 * @param bitfinexApiBroker
 * @param jsonObject
 * @param channelId
 */
private void handleCandlesCallback(final BitfinexApiBroker bitfinexApiBroker, final JSONObject jsonObject, final int channelId) {
    final String key = jsonObject.getString("key");
    logger.info("Registering key {} on channel {}", key, channelId);
    final BitfinexCandlestickSymbol candleStickSymbol = BitfinexCandlestickSymbol.fromBitfinexString(key);
    bitfinexApiBroker.addToChannelSymbolMap(channelId, candleStickSymbol);
}
Also used : BitfinexCandlestickSymbol(com.github.jnidzwetzki.bitfinex.v2.entity.symbol.BitfinexCandlestickSymbol)

Example 29 with BitfinexApiBroker

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

the class SubscribedCallback method handleTradesCallback.

/**
 * Handle the trades callback
 *
 * @param bitfinexApiBroker
 * @param jsonObject
 * @param channelId
 */
private void handleTradesCallback(final BitfinexApiBroker bitfinexApiBroker, final JSONObject jsonObject, final int channelId) {
    final String symbol2 = jsonObject.getString("symbol");
    final BitfinexExecutedTradeSymbol currencyPair = BitfinexExecutedTradeSymbol.fromBitfinexString(symbol2);
    logger.info("Registering symbol {} on channel {}", currencyPair, channelId);
    bitfinexApiBroker.addToChannelSymbolMap(channelId, currencyPair);
}
Also used : BitfinexExecutedTradeSymbol(com.github.jnidzwetzki.bitfinex.v2.entity.symbol.BitfinexExecutedTradeSymbol)

Example 30 with BitfinexApiBroker

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

the class SubscribedCallback method handleTickerCallback.

/**
 * Handle the ticker callback
 *
 * @param bitfinexApiBroker
 * @param jsonObject
 * @param channelId
 */
private void handleTickerCallback(final BitfinexApiBroker bitfinexApiBroker, final JSONObject jsonObject, final int channelId) {
    final String symbol = jsonObject.getString("symbol");
    final BitfinexTickerSymbol tickerSymbol = BitfinexTickerSymbol.fromBitfinexString(symbol);
    logger.info("Registering symbol {} on channel {}", tickerSymbol, channelId);
    bitfinexApiBroker.addToChannelSymbolMap(channelId, tickerSymbol);
}
Also used : BitfinexTickerSymbol(com.github.jnidzwetzki.bitfinex.v2.entity.symbol.BitfinexTickerSymbol)

Aggregations

BitfinexApiBroker (com.github.jnidzwetzki.bitfinex.v2.BitfinexApiBroker)46 Test (org.junit.Test)36 JSONArray (org.json.JSONArray)19 CountDownLatch (java.util.concurrent.CountDownLatch)18 APIException (com.github.jnidzwetzki.bitfinex.v2.entity.APIException)15 BitfinexCandlestickSymbol (com.github.jnidzwetzki.bitfinex.v2.entity.symbol.BitfinexCandlestickSymbol)15 BitfinexTickerSymbol (com.github.jnidzwetzki.bitfinex.v2.entity.symbol.BitfinexTickerSymbol)13 BitfinexCurrencyPair (com.github.jnidzwetzki.bitfinex.v2.entity.BitfinexCurrencyPair)12 QuoteManager (com.github.jnidzwetzki.bitfinex.v2.manager.QuoteManager)12 BitfinexTick (com.github.jnidzwetzki.bitfinex.v2.entity.BitfinexTick)11 BitfinexExecutedTradeSymbol (com.github.jnidzwetzki.bitfinex.v2.entity.symbol.BitfinexExecutedTradeSymbol)11 OrderbookConfiguration (com.github.jnidzwetzki.bitfinex.v2.entity.OrderbookConfiguration)9 RawOrderbookConfiguration (com.github.jnidzwetzki.bitfinex.v2.entity.RawOrderbookConfiguration)9 Timeframe (com.github.jnidzwetzki.bitfinex.v2.entity.Timeframe)9 OrderManager (com.github.jnidzwetzki.bitfinex.v2.manager.OrderManager)9 ExecutorService (java.util.concurrent.ExecutorService)9 ExecutedTrade (com.github.jnidzwetzki.bitfinex.v2.entity.ExecutedTrade)7 RawOrderbookEntry (com.github.jnidzwetzki.bitfinex.v2.entity.RawOrderbookEntry)7 Assert (org.junit.Assert)7 ExchangeOrder (com.github.jnidzwetzki.bitfinex.v2.entity.ExchangeOrder)6