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);
}
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);
}
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);
}
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);
}
}
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);
}
Aggregations