use of com.github.jnidzwetzki.bitfinex.v2.entity.APIException in project bitfinex-v2-wss-api-java by jnidzwetzki.
the class WalletHandler method handleWalletcallback.
/**
* Handle the callback for a single wallet
* @param bitfinexApiBroker
* @param walletArray
* @throws APIException
*/
private void handleWalletcallback(final BitfinexApiBroker bitfinexApiBroker, final JSONArray walletArray) throws APIException {
final String walletType = walletArray.getString(0);
final String currency = walletArray.getString(1);
final BigDecimal balance = walletArray.getBigDecimal(2);
final BigDecimal unsettledInterest = walletArray.getBigDecimal(3);
final BigDecimal balanceAvailable = walletArray.optBigDecimal(4, BigDecimal.valueOf(-1));
final Wallet wallet = new Wallet(walletType, currency, balance, unsettledInterest, balanceAvailable);
final WalletManager walletManager = bitfinexApiBroker.getWalletManager();
final Table<String, String, Wallet> walletTable = walletManager.getWalletTable();
synchronized (walletTable) {
walletTable.put(walletType, currency, wallet);
walletTable.notifyAll();
}
}
use of com.github.jnidzwetzki.bitfinex.v2.entity.APIException in project bitfinex-v2-wss-api-java by jnidzwetzki.
the class CandlestickHandler method handleChannelData.
/**
* Handle a candlestick callback
* @param channel
* @param subarray
*/
@Override
public void handleChannelData(final BitfinexApiBroker bitfinexApiBroker, final BitfinexStreamSymbol channelSymbol, final JSONArray jsonArray) throws APIException {
// channel symbol trade:1m:tLTCUSD
final List<BitfinexTick> ticksBuffer = new ArrayList<>();
// Snapshots contain multiple Bars, Updates only one
if (jsonArray.get(0) instanceof JSONArray) {
for (int pos = 0; pos < jsonArray.length(); pos++) {
final JSONArray parts = jsonArray.getJSONArray(pos);
parseCandlestick(ticksBuffer, parts);
}
} else {
parseCandlestick(ticksBuffer, jsonArray);
}
// Use natural ordering
ticksBuffer.sort(null);
final BitfinexCandlestickSymbol candlestickSymbol = (BitfinexCandlestickSymbol) channelSymbol;
bitfinexApiBroker.getQuoteManager().handleCandlestickList(candlestickSymbol, ticksBuffer);
}
use of com.github.jnidzwetzki.bitfinex.v2.entity.APIException in project bitfinex-v2-wss-api-java by jnidzwetzki.
the class BitfinexApiBroker method handleCommandCallback.
/**
* Handle a command callback
*/
private void handleCommandCallback(final String message) {
logger.debug("Got {}", message);
// JSON callback
final JSONTokener tokener = new JSONTokener(message);
final JSONObject jsonObject = new JSONObject(tokener);
final String eventType = jsonObject.getString("event");
if (!commandCallbacks.containsKey(eventType)) {
logger.error("Unknown event: {}", message);
} else {
try {
final CommandCallbackHandler callback = commandCallbacks.get(eventType);
callback.handleChannelData(this, jsonObject);
} catch (APIException e) {
logger.error("Got an exception while handling callback");
}
}
}
use of com.github.jnidzwetzki.bitfinex.v2.entity.APIException in project bitfinex-v2-wss-api-java by jnidzwetzki.
the class BitfinexApiBroker method connect.
/**
* Open the connection
* @throws APIException
*/
public void connect() throws APIException {
try {
final URI bitfinexURI = new URI(BITFINEX_URI);
websocketEndpoint = new WebsocketClientEndpoint(bitfinexURI);
websocketEndpoint.addConsumer(apiCallback);
websocketEndpoint.connect();
updateConnectionHeartbeat();
executeAuthentification();
heartbeatThread = new Thread(new HeartbeatThread(this));
heartbeatThread.start();
} catch (Exception e) {
throw new APIException(e);
}
}
use of com.github.jnidzwetzki.bitfinex.v2.entity.APIException in project bitfinex-v2-wss-api-java by jnidzwetzki.
the class BitfinexApiBroker method handleChannelData.
/**
* Handle normal channel data
* @param jsonArray
* @param channel
* @throws APIException
*/
private void handleChannelData(final JSONArray jsonArray) {
final int channel = jsonArray.getInt(0);
final BitfinexStreamSymbol channelSymbol = getFromChannelSymbolMap(channel);
if (channelSymbol == null) {
logger.error("Unable to determine symbol for channel {}", channel);
logger.error("Data is {}", jsonArray);
return;
}
try {
if (jsonArray.get(1) instanceof String) {
handleChannelDataString(jsonArray, channelSymbol);
} else {
handleChannelDataArray(jsonArray, channelSymbol);
}
} catch (APIException e) {
logger.error("Got exception while handling callback", e);
}
}
Aggregations