use of com.github.jnidzwetzki.bitfinex.v2.BitfinexApiBroker in project bitfinex-v2-wss-api-java by jnidzwetzki.
the class ExecutedTradeHandler method handleEntry.
/**
* Handle a new executed trade entry
* @param bitfinexApiBroker
* @param symbol
* @param jsonArray
*/
private void handleEntry(final BitfinexApiBroker bitfinexApiBroker, final BitfinexExecutedTradeSymbol symbol, final JSONArray jsonArray) {
final ExecutedTrade executedTrade = new ExecutedTrade();
final long id = jsonArray.getNumber(0).longValue();
executedTrade.setId(id);
final long timestamp = jsonArray.getNumber(1).longValue();
executedTrade.setTimestamp(timestamp);
final BigDecimal amount = jsonArray.getBigDecimal(2);
executedTrade.setAmount(amount);
// Funding or Currency
if (jsonArray.optNumber(4) != null) {
final BigDecimal rate = jsonArray.getBigDecimal(3);
executedTrade.setRate(rate);
final int period = jsonArray.getNumber(4).intValue();
executedTrade.setPeriod(period);
} else {
final BigDecimal price = jsonArray.getBigDecimal(3);
executedTrade.setPrice(price);
}
bitfinexApiBroker.getQuoteManager().handleExecutedTradeEntry(symbol, executedTrade);
}
use of com.github.jnidzwetzki.bitfinex.v2.BitfinexApiBroker in project bitfinex-v2-wss-api-java by jnidzwetzki.
the class ExecutedTradeHandler method handleChannelData.
@Override
public void handleChannelData(final BitfinexApiBroker bitfinexApiBroker, final BitfinexStreamSymbol channelSymbol, final JSONArray jsonArray) throws APIException {
final BitfinexExecutedTradeSymbol configuration = (BitfinexExecutedTradeSymbol) channelSymbol;
try {
// Snapshots contain multiple executes entries, updates only one
if (jsonArray.get(0) instanceof JSONArray) {
for (int pos = 0; pos < jsonArray.length(); pos++) {
final JSONArray parts = jsonArray.getJSONArray(pos);
handleEntry(bitfinexApiBroker, configuration, parts);
}
} else {
handleEntry(bitfinexApiBroker, configuration, jsonArray);
}
} catch (JSONException e) {
throw new APIException(e);
}
}
use of com.github.jnidzwetzki.bitfinex.v2.BitfinexApiBroker in project bitfinex-v2-wss-api-java by jnidzwetzki.
the class OrderbookHandler method handleChannelData.
@Override
public void handleChannelData(final BitfinexApiBroker bitfinexApiBroker, final BitfinexStreamSymbol channelSymbol, final JSONArray jsonArray) throws APIException {
final OrderbookConfiguration configuration = (OrderbookConfiguration) channelSymbol;
// Example: [13182,1,-0.1]
try {
// Snapshots contain multiple Orderbook entries, updates only one
if (jsonArray.get(0) instanceof JSONArray) {
for (int pos = 0; pos < jsonArray.length(); pos++) {
final JSONArray parts = jsonArray.getJSONArray(pos);
handleEntry(bitfinexApiBroker, configuration, parts);
}
} else {
handleEntry(bitfinexApiBroker, configuration, jsonArray);
}
} catch (JSONException e) {
throw new APIException(e);
}
}
use of com.github.jnidzwetzki.bitfinex.v2.BitfinexApiBroker in project bitfinex-v2-wss-api-java by jnidzwetzki.
the class RawOrderbookHandler method handleEntry.
/**
* Handle a new orderbook entry
* @param bitfinexApiBroker
* @param configuration
* @param jsonArray
*/
private void handleEntry(final BitfinexApiBroker bitfinexApiBroker, final RawOrderbookConfiguration configuration, final JSONArray jsonArray) {
final long orderId = jsonArray.getNumber(0).longValue();
final BigDecimal price = jsonArray.getBigDecimal(1);
final BigDecimal amount = jsonArray.getBigDecimal(2);
final RawOrderbookEntry orderbookEntry = new RawOrderbookEntry(orderId, price, amount);
bitfinexApiBroker.getRawOrderbookManager().handleNewOrderbookEntry(configuration, orderbookEntry);
}
use of com.github.jnidzwetzki.bitfinex.v2.BitfinexApiBroker in project bitfinex-v2-wss-api-java by jnidzwetzki.
the class AuthCallbackHandler method authSuccessfully.
/**
* Auth was successfully
*
* @param bitfinexApiBroker
* @param jsonObject
* @param connectionReadyLatch
*/
private void authSuccessfully(final BitfinexApiBroker bitfinexApiBroker, final JSONObject jsonObject, final CountDownLatch connectionReadyLatch) {
bitfinexApiBroker.setAuthenticated(true);
final ConnectionCapabilities capabilities = new ConnectionCapabilities(jsonObject);
bitfinexApiBroker.setCapabilities(capabilities);
if (connectionReadyLatch != null) {
connectionReadyLatch.countDown();
}
}
Aggregations