Search in sources :

Example 1 with CommandCallbackHandler

use of com.github.jnidzwetzki.bitfinex.v2.callback.command.CommandCallbackHandler 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");
        }
    }
}
Also used : JSONTokener(org.json.JSONTokener) APIException(com.github.jnidzwetzki.bitfinex.v2.entity.APIException) JSONObject(org.json.JSONObject) CommandCallbackHandler(com.github.jnidzwetzki.bitfinex.v2.callback.command.CommandCallbackHandler)

Aggregations

CommandCallbackHandler (com.github.jnidzwetzki.bitfinex.v2.callback.command.CommandCallbackHandler)1 APIException (com.github.jnidzwetzki.bitfinex.v2.entity.APIException)1 JSONObject (org.json.JSONObject)1 JSONTokener (org.json.JSONTokener)1