Search in sources :

Example 1 with SubscribeTradesCommand

use of com.github.jnidzwetzki.bitfinex.v2.commands.SubscribeTradesCommand 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 2 with SubscribeTradesCommand

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

the class CommandsTest method testCommandsJSON.

/**
 * Call all commands and check for excepion
 * @throws CommandException
 */
@Test
public void testCommandsJSON() throws CommandException {
    final BitfinexOrder order = BitfinexOrderBuilder.create(BitfinexCurrencyPair.BCH_USD, BitfinexOrderType.EXCHANGE_STOP, 2).build();
    final BitfinexCandlestickSymbol candleSymbol = new BitfinexCandlestickSymbol(BitfinexCurrencyPair.BCH_USD, Timeframe.HOUR_1);
    final OrderbookConfiguration orderbookConfiguration = new OrderbookConfiguration(BitfinexCurrencyPair.BCH_USD, OrderBookPrecision.P0, OrderBookFrequency.F0, 50);
    final RawOrderbookConfiguration rawOrderbookConfiguration = new RawOrderbookConfiguration(BitfinexCurrencyPair.BAT_BTC);
    final List<AbstractAPICommand> commands = Arrays.asList(new AuthCommand(), new CancelOrderCommand(123), new CancelOrderGroupCommand(1), new OrderCommand(order), new PingCommand(), new SubscribeCandlesCommand(candleSymbol), new SubscribeTickerCommand(new BitfinexTickerSymbol(BitfinexCurrencyPair.BCH_USD)), new SubscribeTradesCommand(new BitfinexExecutedTradeSymbol(BitfinexCurrencyPair.BAT_BTC)), new SubscribeOrderbookCommand(orderbookConfiguration), new SubscribeRawOrderbookCommand(rawOrderbookConfiguration), new UnsubscribeChannelCommand(12));
    final BitfinexApiBroker bitfinexApiBroker = buildMockedBitfinexConnection();
    for (final AbstractAPICommand command : commands) {
        final String commandValue = command.getCommand(bitfinexApiBroker);
        Assert.assertNotNull(commandValue);
        Assert.assertTrue(commandValue.length() > 10);
    }
}
Also used : BitfinexExecutedTradeSymbol(com.github.jnidzwetzki.bitfinex.v2.entity.symbol.BitfinexExecutedTradeSymbol) CancelOrderCommand(com.github.jnidzwetzki.bitfinex.v2.commands.CancelOrderCommand) OrderCommand(com.github.jnidzwetzki.bitfinex.v2.commands.OrderCommand) SubscribeOrderbookCommand(com.github.jnidzwetzki.bitfinex.v2.commands.SubscribeOrderbookCommand) CancelOrderGroupCommand(com.github.jnidzwetzki.bitfinex.v2.commands.CancelOrderGroupCommand) OrderbookConfiguration(com.github.jnidzwetzki.bitfinex.v2.entity.OrderbookConfiguration) RawOrderbookConfiguration(com.github.jnidzwetzki.bitfinex.v2.entity.RawOrderbookConfiguration) UnsubscribeChannelCommand(com.github.jnidzwetzki.bitfinex.v2.commands.UnsubscribeChannelCommand) SubscribeTradesCommand(com.github.jnidzwetzki.bitfinex.v2.commands.SubscribeTradesCommand) BitfinexTickerSymbol(com.github.jnidzwetzki.bitfinex.v2.entity.symbol.BitfinexTickerSymbol) AbstractAPICommand(com.github.jnidzwetzki.bitfinex.v2.commands.AbstractAPICommand) CancelOrderCommand(com.github.jnidzwetzki.bitfinex.v2.commands.CancelOrderCommand) PingCommand(com.github.jnidzwetzki.bitfinex.v2.commands.PingCommand) SubscribeCandlesCommand(com.github.jnidzwetzki.bitfinex.v2.commands.SubscribeCandlesCommand) RawOrderbookConfiguration(com.github.jnidzwetzki.bitfinex.v2.entity.RawOrderbookConfiguration) SubscribeTickerCommand(com.github.jnidzwetzki.bitfinex.v2.commands.SubscribeTickerCommand) BitfinexApiBroker(com.github.jnidzwetzki.bitfinex.v2.BitfinexApiBroker) BitfinexCandlestickSymbol(com.github.jnidzwetzki.bitfinex.v2.entity.symbol.BitfinexCandlestickSymbol) BitfinexOrder(com.github.jnidzwetzki.bitfinex.v2.entity.BitfinexOrder) AuthCommand(com.github.jnidzwetzki.bitfinex.v2.commands.AuthCommand) SubscribeRawOrderbookCommand(com.github.jnidzwetzki.bitfinex.v2.commands.SubscribeRawOrderbookCommand) Test(org.junit.Test)

Example 3 with SubscribeTradesCommand

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

the class QuoteManager method subscribeExecutedTrades.

/**
 * Subscribe a executed trade channel
 * @param currencyPair
 * @param orderBookPrecision
 * @param orderBookFrequency
 * @param pricePoints
 */
public void subscribeExecutedTrades(final BitfinexExecutedTradeSymbol tradeSymbol) {
    final SubscribeTradesCommand subscribeOrderbookCommand = new SubscribeTradesCommand(tradeSymbol);
    bitfinexApiBroker.sendCommand(subscribeOrderbookCommand);
}
Also used : SubscribeTradesCommand(com.github.jnidzwetzki.bitfinex.v2.commands.SubscribeTradesCommand)

Aggregations

SubscribeTradesCommand (com.github.jnidzwetzki.bitfinex.v2.commands.SubscribeTradesCommand)3 SubscribeCandlesCommand (com.github.jnidzwetzki.bitfinex.v2.commands.SubscribeCandlesCommand)2 SubscribeOrderbookCommand (com.github.jnidzwetzki.bitfinex.v2.commands.SubscribeOrderbookCommand)2 SubscribeRawOrderbookCommand (com.github.jnidzwetzki.bitfinex.v2.commands.SubscribeRawOrderbookCommand)2 SubscribeTickerCommand (com.github.jnidzwetzki.bitfinex.v2.commands.SubscribeTickerCommand)2 OrderbookConfiguration (com.github.jnidzwetzki.bitfinex.v2.entity.OrderbookConfiguration)2 RawOrderbookConfiguration (com.github.jnidzwetzki.bitfinex.v2.entity.RawOrderbookConfiguration)2 BitfinexCandlestickSymbol (com.github.jnidzwetzki.bitfinex.v2.entity.symbol.BitfinexCandlestickSymbol)2 BitfinexExecutedTradeSymbol (com.github.jnidzwetzki.bitfinex.v2.entity.symbol.BitfinexExecutedTradeSymbol)2 BitfinexTickerSymbol (com.github.jnidzwetzki.bitfinex.v2.entity.symbol.BitfinexTickerSymbol)2 BitfinexApiBroker (com.github.jnidzwetzki.bitfinex.v2.BitfinexApiBroker)1 AbstractAPICommand (com.github.jnidzwetzki.bitfinex.v2.commands.AbstractAPICommand)1 AuthCommand (com.github.jnidzwetzki.bitfinex.v2.commands.AuthCommand)1 CancelOrderCommand (com.github.jnidzwetzki.bitfinex.v2.commands.CancelOrderCommand)1 CancelOrderGroupCommand (com.github.jnidzwetzki.bitfinex.v2.commands.CancelOrderGroupCommand)1 OrderCommand (com.github.jnidzwetzki.bitfinex.v2.commands.OrderCommand)1 PingCommand (com.github.jnidzwetzki.bitfinex.v2.commands.PingCommand)1 UnsubscribeChannelCommand (com.github.jnidzwetzki.bitfinex.v2.commands.UnsubscribeChannelCommand)1 BitfinexOrder (com.github.jnidzwetzki.bitfinex.v2.entity.BitfinexOrder)1 BitfinexStreamSymbol (com.github.jnidzwetzki.bitfinex.v2.entity.symbol.BitfinexStreamSymbol)1