use of com.github.jnidzwetzki.bitfinex.v2.entity.symbol.BitfinexCandlestickSymbol 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);
}
use of com.github.jnidzwetzki.bitfinex.v2.entity.symbol.BitfinexCandlestickSymbol 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);
}
}
use of com.github.jnidzwetzki.bitfinex.v2.entity.symbol.BitfinexCandlestickSymbol 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);
}
use of com.github.jnidzwetzki.bitfinex.v2.entity.symbol.BitfinexCandlestickSymbol 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);
}
}
use of com.github.jnidzwetzki.bitfinex.v2.entity.symbol.BitfinexCandlestickSymbol in project bitfinex-v2-wss-api-java by jnidzwetzki.
the class QuoteManager method unsubscribeCandles.
/**
* Unsubscribe the candles
* @param currencyPair
* @param timeframe
*/
public void unsubscribeCandles(final BitfinexCandlestickSymbol symbol) {
final int channel = bitfinexApiBroker.getChannelForSymbol(symbol);
if (channel == -1) {
throw new IllegalArgumentException("Unknown symbol: " + symbol);
}
final UnsubscribeChannelCommand command = new UnsubscribeChannelCommand(channel);
bitfinexApiBroker.sendCommand(command);
bitfinexApiBroker.removeChannelForSymbol(symbol);
}
Aggregations