Search in sources :

Example 6 with OrderbookConfiguration

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

the class OrderbookManager method unsubscribeOrderbook.

/**
 * Unsubscribe a orderbook
 * @param currencyPair
 * @param orderBookPrecision
 * @param orderBookFrequency
 * @param pricePoints
 */
public void unsubscribeOrderbook(final OrderbookConfiguration orderbookConfiguration) {
    final int channel = bitfinexApiBroker.getChannelForSymbol(orderbookConfiguration);
    if (channel == -1) {
        throw new IllegalArgumentException("Unknown symbol: " + orderbookConfiguration);
    }
    final UnsubscribeChannelCommand command = new UnsubscribeChannelCommand(channel);
    bitfinexApiBroker.sendCommand(command);
    bitfinexApiBroker.removeChannelForSymbol(orderbookConfiguration);
}
Also used : UnsubscribeChannelCommand(com.github.jnidzwetzki.bitfinex.v2.commands.UnsubscribeChannelCommand)

Example 7 with OrderbookConfiguration

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

the class OrderbookManager method subscribeOrderbook.

/**
 * Subscribe a orderbook
 * @param currencyPair
 * @param orderBookPrecision
 * @param orderBookFrequency
 * @param pricePoints
 */
public void subscribeOrderbook(final OrderbookConfiguration orderbookConfiguration) {
    final SubscribeOrderbookCommand subscribeOrderbookCommand = new SubscribeOrderbookCommand(orderbookConfiguration);
    bitfinexApiBroker.sendCommand(subscribeOrderbookCommand);
}
Also used : SubscribeOrderbookCommand(com.github.jnidzwetzki.bitfinex.v2.commands.SubscribeOrderbookCommand)

Example 8 with OrderbookConfiguration

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

the class BitfinexApiBroker method resubscribeChannels.

/**
 * Resubscribe the old ticker
 * @throws InterruptedException
 * @throws APIException
 */
private void resubscribeChannels() throws InterruptedException, APIException {
    final Map<Integer, BitfinexStreamSymbol> oldChannelIdSymbolMap = new HashMap<>();
    synchronized (channelIdSymbolMap) {
        oldChannelIdSymbolMap.putAll(channelIdSymbolMap);
        channelIdSymbolMap.clear();
        channelIdSymbolMap.notifyAll();
    }
    // Resubscribe channels
    for (BitfinexStreamSymbol symbol : oldChannelIdSymbolMap.values()) {
        if (symbol instanceof BitfinexTickerSymbol) {
            sendCommand(new SubscribeTickerCommand((BitfinexTickerSymbol) symbol));
        } else if (symbol instanceof BitfinexExecutedTradeSymbol) {
            sendCommand(new SubscribeTradesCommand((BitfinexExecutedTradeSymbol) symbol));
        } else if (symbol instanceof BitfinexCandlestickSymbol) {
            sendCommand(new SubscribeCandlesCommand((BitfinexCandlestickSymbol) symbol));
        } else if (symbol instanceof OrderbookConfiguration) {
            sendCommand(new SubscribeOrderbookCommand((OrderbookConfiguration) symbol));
        } else if (symbol instanceof RawOrderbookConfiguration) {
            sendCommand(new SubscribeRawOrderbookCommand((RawOrderbookConfiguration) symbol));
        } else {
            logger.error("Unknown stream symbol: {}", symbol);
        }
    }
    waitForChannelResubscription(oldChannelIdSymbolMap);
}
Also used : BitfinexExecutedTradeSymbol(com.github.jnidzwetzki.bitfinex.v2.entity.symbol.BitfinexExecutedTradeSymbol) HashMap(java.util.HashMap) SubscribeOrderbookCommand(com.github.jnidzwetzki.bitfinex.v2.commands.SubscribeOrderbookCommand) RawOrderbookConfiguration(com.github.jnidzwetzki.bitfinex.v2.entity.RawOrderbookConfiguration) OrderbookConfiguration(com.github.jnidzwetzki.bitfinex.v2.entity.OrderbookConfiguration) SubscribeTradesCommand(com.github.jnidzwetzki.bitfinex.v2.commands.SubscribeTradesCommand) BitfinexTickerSymbol(com.github.jnidzwetzki.bitfinex.v2.entity.symbol.BitfinexTickerSymbol) SubscribeCandlesCommand(com.github.jnidzwetzki.bitfinex.v2.commands.SubscribeCandlesCommand) SubscribeTickerCommand(com.github.jnidzwetzki.bitfinex.v2.commands.SubscribeTickerCommand) RawOrderbookConfiguration(com.github.jnidzwetzki.bitfinex.v2.entity.RawOrderbookConfiguration) BitfinexCandlestickSymbol(com.github.jnidzwetzki.bitfinex.v2.entity.symbol.BitfinexCandlestickSymbol) BitfinexStreamSymbol(com.github.jnidzwetzki.bitfinex.v2.entity.symbol.BitfinexStreamSymbol) SubscribeRawOrderbookCommand(com.github.jnidzwetzki.bitfinex.v2.commands.SubscribeRawOrderbookCommand)

Example 9 with OrderbookConfiguration

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

the class BitfinexApiBroker method handleChannelDataArray.

/**
 * Handle the channel data with has an array at first position
 * @param jsonArray
 * @param channelSymbol
 * @throws APIException
 */
private void handleChannelDataArray(final JSONArray jsonArray, final BitfinexStreamSymbol channelSymbol) throws APIException {
    final JSONArray subarray = jsonArray.getJSONArray(1);
    if (channelSymbol instanceof BitfinexCandlestickSymbol) {
        final ChannelCallbackHandler handler = new CandlestickHandler();
        handler.handleChannelData(this, channelSymbol, subarray);
    } else if (channelSymbol instanceof RawOrderbookConfiguration) {
        final RawOrderbookHandler handler = new RawOrderbookHandler();
        handler.handleChannelData(this, channelSymbol, subarray);
    } else if (channelSymbol instanceof OrderbookConfiguration) {
        final OrderbookHandler handler = new OrderbookHandler();
        handler.handleChannelData(this, channelSymbol, subarray);
    } else if (channelSymbol instanceof BitfinexTickerSymbol) {
        final ChannelCallbackHandler handler = new TickHandler();
        handler.handleChannelData(this, channelSymbol, subarray);
    } else if (channelSymbol instanceof BitfinexExecutedTradeSymbol) {
        final ChannelCallbackHandler handler = new ExecutedTradeHandler();
        handler.handleChannelData(this, channelSymbol, subarray);
    } else {
        logger.error("Unknown stream type: {}", channelSymbol);
    }
}
Also used : CandlestickHandler(com.github.jnidzwetzki.bitfinex.v2.callback.channel.CandlestickHandler) RawOrderbookHandler(com.github.jnidzwetzki.bitfinex.v2.callback.channel.RawOrderbookHandler) RawOrderbookConfiguration(com.github.jnidzwetzki.bitfinex.v2.entity.RawOrderbookConfiguration) BitfinexExecutedTradeSymbol(com.github.jnidzwetzki.bitfinex.v2.entity.symbol.BitfinexExecutedTradeSymbol) ChannelCallbackHandler(com.github.jnidzwetzki.bitfinex.v2.callback.channel.ChannelCallbackHandler) BitfinexCandlestickSymbol(com.github.jnidzwetzki.bitfinex.v2.entity.symbol.BitfinexCandlestickSymbol) RawOrderbookConfiguration(com.github.jnidzwetzki.bitfinex.v2.entity.RawOrderbookConfiguration) OrderbookConfiguration(com.github.jnidzwetzki.bitfinex.v2.entity.OrderbookConfiguration) JSONArray(org.json.JSONArray) RawOrderbookHandler(com.github.jnidzwetzki.bitfinex.v2.callback.channel.RawOrderbookHandler) OrderbookHandler(com.github.jnidzwetzki.bitfinex.v2.callback.channel.OrderbookHandler) ExecutedTradeHandler(com.github.jnidzwetzki.bitfinex.v2.callback.channel.ExecutedTradeHandler) BitfinexTickerSymbol(com.github.jnidzwetzki.bitfinex.v2.entity.symbol.BitfinexTickerSymbol) TickHandler(com.github.jnidzwetzki.bitfinex.v2.callback.channel.TickHandler)

Example 10 with OrderbookConfiguration

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

the class OrderbookHandler method handleEntry.

/**
 * Handle a new orderbook entry
 * @param bitfinexApiBroker
 * @param configuration
 * @param jsonArray
 */
private void handleEntry(final BitfinexApiBroker bitfinexApiBroker, final OrderbookConfiguration configuration, final JSONArray jsonArray) {
    final BigDecimal price = jsonArray.getBigDecimal(0);
    final BigDecimal count = jsonArray.getBigDecimal(1);
    final BigDecimal amount = jsonArray.getBigDecimal(2);
    final OrderbookEntry orderbookEntry = new OrderbookEntry(price, count, amount);
    bitfinexApiBroker.getOrderbookManager().handleNewOrderbookEntry(configuration, orderbookEntry);
}
Also used : OrderbookEntry(com.github.jnidzwetzki.bitfinex.v2.entity.OrderbookEntry) BigDecimal(java.math.BigDecimal)

Aggregations

OrderbookConfiguration (com.github.jnidzwetzki.bitfinex.v2.entity.OrderbookConfiguration)9 RawOrderbookConfiguration (com.github.jnidzwetzki.bitfinex.v2.entity.RawOrderbookConfiguration)6 BitfinexCandlestickSymbol (com.github.jnidzwetzki.bitfinex.v2.entity.symbol.BitfinexCandlestickSymbol)5 BitfinexExecutedTradeSymbol (com.github.jnidzwetzki.bitfinex.v2.entity.symbol.BitfinexExecutedTradeSymbol)5 BitfinexTickerSymbol (com.github.jnidzwetzki.bitfinex.v2.entity.symbol.BitfinexTickerSymbol)5 Test (org.junit.Test)5 BitfinexApiBroker (com.github.jnidzwetzki.bitfinex.v2.BitfinexApiBroker)3 SubscribeOrderbookCommand (com.github.jnidzwetzki.bitfinex.v2.commands.SubscribeOrderbookCommand)3 SubscribeRawOrderbookCommand (com.github.jnidzwetzki.bitfinex.v2.commands.SubscribeRawOrderbookCommand)3 UnsubscribeChannelCommand (com.github.jnidzwetzki.bitfinex.v2.commands.UnsubscribeChannelCommand)3 APIException (com.github.jnidzwetzki.bitfinex.v2.entity.APIException)3 OrderbookEntry (com.github.jnidzwetzki.bitfinex.v2.entity.OrderbookEntry)3 SubscribeCandlesCommand (com.github.jnidzwetzki.bitfinex.v2.commands.SubscribeCandlesCommand)2 SubscribeTickerCommand (com.github.jnidzwetzki.bitfinex.v2.commands.SubscribeTickerCommand)2 SubscribeTradesCommand (com.github.jnidzwetzki.bitfinex.v2.commands.SubscribeTradesCommand)2 BitfinexCurrencyPair (com.github.jnidzwetzki.bitfinex.v2.entity.BitfinexCurrencyPair)2 BitfinexTick (com.github.jnidzwetzki.bitfinex.v2.entity.BitfinexTick)2 ExecutedTrade (com.github.jnidzwetzki.bitfinex.v2.entity.ExecutedTrade)2 OrderBookFrequency (com.github.jnidzwetzki.bitfinex.v2.entity.OrderBookFrequency)2 OrderBookPrecision (com.github.jnidzwetzki.bitfinex.v2.entity.OrderBookPrecision)2