Search in sources :

Example 1 with ConnectionHeartbeatCallback

use of com.github.jnidzwetzki.bitfinex.v2.callback.command.ConnectionHeartbeatCallback in project bitfinex-v2-wss-api-java by jnidzwetzki.

the class CommandsCallbackTest method testConnectionHeartbeat.

/**
 * Test the pong callback
 * @throws APIException
 */
@Test
public void testConnectionHeartbeat() throws APIException {
    final String jsonString = "{\"event\":\"pong\",\"ts\":1515023251265}";
    final JSONObject jsonObject = new JSONObject(jsonString);
    final BitfinexApiBroker bitfinexApiBroker = new BitfinexApiBroker();
    final long oldHeartbeat = bitfinexApiBroker.getLastHeatbeat().get();
    final ConnectionHeartbeatCallback connectionHeartbeatCallback = new ConnectionHeartbeatCallback();
    connectionHeartbeatCallback.handleChannelData(bitfinexApiBroker, jsonObject);
    final long newHeartbeat = bitfinexApiBroker.getLastHeatbeat().get();
    Assert.assertTrue(oldHeartbeat < newHeartbeat);
}
Also used : BitfinexApiBroker(com.github.jnidzwetzki.bitfinex.v2.BitfinexApiBroker) JSONObject(org.json.JSONObject) ConnectionHeartbeatCallback(com.github.jnidzwetzki.bitfinex.v2.callback.command.ConnectionHeartbeatCallback) Test(org.junit.Test)

Example 2 with ConnectionHeartbeatCallback

use of com.github.jnidzwetzki.bitfinex.v2.callback.command.ConnectionHeartbeatCallback in project bitfinex-v2-wss-api-java by jnidzwetzki.

the class BitfinexApiBroker method setupCommandCallbacks.

/**
 * Setup the command callbacks
 */
private void setupCommandCallbacks() {
    commandCallbacks = new HashMap<>();
    commandCallbacks.put("info", new DoNothingCommandCallback());
    commandCallbacks.put("subscribed", new SubscribedCallback());
    commandCallbacks.put("pong", new ConnectionHeartbeatCallback());
    commandCallbacks.put("unsubscribed", new UnsubscribedCallback());
    commandCallbacks.put("auth", new AuthCallbackHandler());
}
Also used : SubscribedCallback(com.github.jnidzwetzki.bitfinex.v2.callback.command.SubscribedCallback) DoNothingCommandCallback(com.github.jnidzwetzki.bitfinex.v2.callback.command.DoNothingCommandCallback) ConnectionHeartbeatCallback(com.github.jnidzwetzki.bitfinex.v2.callback.command.ConnectionHeartbeatCallback) AuthCallbackHandler(com.github.jnidzwetzki.bitfinex.v2.callback.command.AuthCallbackHandler) UnsubscribedCallback(com.github.jnidzwetzki.bitfinex.v2.callback.command.UnsubscribedCallback)

Aggregations

ConnectionHeartbeatCallback (com.github.jnidzwetzki.bitfinex.v2.callback.command.ConnectionHeartbeatCallback)2 BitfinexApiBroker (com.github.jnidzwetzki.bitfinex.v2.BitfinexApiBroker)1 AuthCallbackHandler (com.github.jnidzwetzki.bitfinex.v2.callback.command.AuthCallbackHandler)1 DoNothingCommandCallback (com.github.jnidzwetzki.bitfinex.v2.callback.command.DoNothingCommandCallback)1 SubscribedCallback (com.github.jnidzwetzki.bitfinex.v2.callback.command.SubscribedCallback)1 UnsubscribedCallback (com.github.jnidzwetzki.bitfinex.v2.callback.command.UnsubscribedCallback)1 JSONObject (org.json.JSONObject)1 Test (org.junit.Test)1