use of com.github.jnidzwetzki.bitfinex.v2.entity.APIException 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.APIException in project bitfinex-v2-wss-api-java by jnidzwetzki.
the class BitfinexApiBroker method executeAuthentification.
/**
* Execute the authentication and wait until the socket is ready
* @throws InterruptedException
* @throws APIException
*/
private void executeAuthentification() throws InterruptedException, APIException {
connectionReadyLatch = new CountDownLatch(CONNECTION_READY_EVENTS);
if (isAuthenticatedConnection()) {
sendCommand(new AuthCommand());
logger.info("Waiting for connection ready events");
connectionReadyLatch.await(10, TimeUnit.SECONDS);
if (!authenticated) {
throw new APIException("Unable to perform authentification, capabilities are: " + capabilities);
}
}
}
use of com.github.jnidzwetzki.bitfinex.v2.entity.APIException 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.APIException in project bitfinex-v2-wss-api-java by jnidzwetzki.
the class OrderHandler method handleOrderCallback.
/**
* Handle a single order callback
* @param bitfinexApiBroker
* @param orderArray
* @throws APIException
*/
private void handleOrderCallback(BitfinexApiBroker bitfinexApiBroker, final JSONArray order) throws APIException {
final ExchangeOrder exchangeOrder = new ExchangeOrder();
exchangeOrder.setApikey(bitfinexApiBroker.getApiKey());
exchangeOrder.setOrderId(order.getLong(0));
exchangeOrder.setGroupId(order.optInt(1, -1));
exchangeOrder.setCid(order.optLong(2, -1));
exchangeOrder.setSymbol(order.getString(3));
exchangeOrder.setCreated(order.getLong(4));
exchangeOrder.setUpdated(order.getLong(5));
exchangeOrder.setAmount(order.getBigDecimal(6));
exchangeOrder.setAmountAtCreation(order.getBigDecimal(7));
exchangeOrder.setOrderType(BitfinexOrderType.fromString(order.getString(8)));
final ExchangeOrderState orderState = ExchangeOrderState.fromString(order.getString(13));
exchangeOrder.setState(orderState);
exchangeOrder.setPrice(order.optBigDecimal(16, BigDecimal.valueOf(-1)));
exchangeOrder.setPriceAvg(order.optBigDecimal(17, BigDecimal.valueOf(-1)));
exchangeOrder.setPriceTrailing(order.optBigDecimal(18, BigDecimal.valueOf(-1)));
exchangeOrder.setPriceAuxLimit(order.optBigDecimal(19, BigDecimal.valueOf(-1)));
exchangeOrder.setNotify(order.getInt(23) == 1 ? true : false);
exchangeOrder.setHidden(order.getInt(24) == 1 ? true : false);
bitfinexApiBroker.getOrderManager().updateOrder(exchangeOrder);
}
use of com.github.jnidzwetzki.bitfinex.v2.entity.APIException in project bitfinex-v2-wss-api-java by jnidzwetzki.
the class TradeHandler method handleTradeCallback.
/**
* Handle a single trade callback
* @param bitfinexApiBroker
* @param orderArray
* @throws APIException
*/
private void handleTradeCallback(final BitfinexApiBroker bitfinexApiBroker, final JSONArray jsonTrade, final boolean executed) throws APIException {
final Trade trade = new Trade();
trade.setExecuted(executed);
trade.setApikey(bitfinexApiBroker.getApiKey());
trade.setId(jsonTrade.getLong(0));
trade.setCurrency(BitfinexCurrencyPair.fromSymbolString(jsonTrade.getString(1)));
trade.setMtsCreate(jsonTrade.getLong(2));
trade.setOrderId(jsonTrade.getLong(3));
trade.setExecAmount(jsonTrade.getBigDecimal(4));
trade.setExecPrice(jsonTrade.getBigDecimal(5));
final String orderTypeString = jsonTrade.optString(6, null);
if (orderTypeString != null) {
trade.setOrderType(BitfinexOrderType.fromString(orderTypeString));
}
trade.setOrderPrice(jsonTrade.optBigDecimal(7, BigDecimal.valueOf(-1)));
trade.setMaker(jsonTrade.getInt(8) == 1 ? true : false);
trade.setFee(jsonTrade.optBigDecimal(9, BigDecimal.valueOf(-1)));
trade.setFeeCurrency(jsonTrade.optString(10, ""));
bitfinexApiBroker.getTradeManager().updateTrade(trade);
}
Aggregations