Search in sources :

Example 1 with SubscribedCallback

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

the class CommandsCallbackTest method testSubscribeAndUnsubscribeCallback.

/**
 * Test the subscribed callback
 * @throws APIException
 */
@Test
public void testSubscribeAndUnsubscribeCallback() throws APIException {
    final String jsonString = "{\"event\":\"subscribed\",\"channel\":\"ticker\",\"chanId\":30,\"symbol\":\"tNEOUSD\",\"pair\":\"NEOUSD\"}";
    final JSONObject jsonObject = new JSONObject(jsonString);
    final BitfinexApiBroker bitfinexApiBroker = new BitfinexApiBroker();
    Assert.assertTrue(bitfinexApiBroker.getFromChannelSymbolMap(30) == null);
    final SubscribedCallback subscribedCallback = new SubscribedCallback();
    subscribedCallback.handleChannelData(bitfinexApiBroker, jsonObject);
    Assert.assertTrue(bitfinexApiBroker.getFromChannelSymbolMap(30) instanceof BitfinexTickerSymbol);
    final String unsubscribedJsonString = "{\"event\":\"unsubscribed\",\"status\":\"OK\",\"chanId\":30}";
    final JSONObject jsonUnsubscribedObject = new JSONObject(unsubscribedJsonString);
    final UnsubscribedCallback unsubscribedCallback = new UnsubscribedCallback();
    unsubscribedCallback.handleChannelData(bitfinexApiBroker, jsonUnsubscribedObject);
    Assert.assertTrue(bitfinexApiBroker.getFromChannelSymbolMap(30) == null);
}
Also used : BitfinexApiBroker(com.github.jnidzwetzki.bitfinex.v2.BitfinexApiBroker) JSONObject(org.json.JSONObject) SubscribedCallback(com.github.jnidzwetzki.bitfinex.v2.callback.command.SubscribedCallback) BitfinexTickerSymbol(com.github.jnidzwetzki.bitfinex.v2.entity.symbol.BitfinexTickerSymbol) UnsubscribedCallback(com.github.jnidzwetzki.bitfinex.v2.callback.command.UnsubscribedCallback) Test(org.junit.Test)

Example 2 with SubscribedCallback

use of com.github.jnidzwetzki.bitfinex.v2.callback.command.SubscribedCallback 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

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