use of com.github.jnidzwetzki.bitfinex.v2.entity.symbol.BitfinexTickerSymbol 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.BitfinexTickerSymbol 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.BitfinexTickerSymbol 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);
}
use of com.github.jnidzwetzki.bitfinex.v2.entity.symbol.BitfinexTickerSymbol 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);
}
use of com.github.jnidzwetzki.bitfinex.v2.entity.symbol.BitfinexTickerSymbol in project crypto-bot by jnidzwetzki.
the class DonchianBot method registerTicker.
/**
* Register the ticker
* @throws InterruptedException
* @throws APIException
*/
protected void registerTicker() throws InterruptedException, APIException {
logger.info("Register ticker");
for (final BitfinexCurrencyPair currency : tradedCurrencies) {
// Subscribe ticket on all connections (needed for wallet in USD conversion)
for (final BitfinexApiBroker bitfinexApiBroker : apiBrokerList) {
final BitfinexTickerSymbol symbol = new BitfinexTickerSymbol(currency);
bitfinexApiBroker.getQuoteManager().subscribeTicker(symbol);
logger.info("Wait for ticker");
while (!bitfinexApiBroker.isTickerActive(symbol)) {
Thread.sleep(100);
}
}
// Use only one connection for merging
tickMerger.put(currency, new BarMerger(currency, TIMEFRAME, (s, t) -> barDoneCallback(s, t)));
final BitfinexTickerSymbol symbol = new BitfinexTickerSymbol(currency);
apiBrokerList.get(0).getQuoteManager().registerTickCallback(symbol, (s, c) -> handleBarCallback(s, c));
}
}
Aggregations