Search in sources :

Example 1 with AuthCallbackHandler

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

the class CommandsCallbackTest method testAuthCommandCallback1.

/**
 * Test the auth callback
 * @throws APIException
 */
@Test
public void testAuthCommandCallback1() throws APIException {
    final String authCallback = "{\"event\":\"auth\",\"status\":\"OK\",\"chanId\":0,\"userId\":1015301,\"auth_id\":\"d5c6a71c-6164-40dd-b57a-92fb59d42975\",\"caps\":{\"orders\":{\"read\":1,\"write\":1},\"account\":{\"read\":1,\"write\":0},\"funding\":{\"read\":1,\"write\":1},\"history\":{\"read\":1,\"write\":0},\"wallets\":{\"read\":1,\"write\":1},\"withdraw\":{\"read\":0,\"write\":0},\"positions\":{\"read\":1,\"write\":1}}}";
    final BitfinexApiBroker bitfinexApiBroker = new BitfinexApiBroker();
    final JSONObject jsonObject = new JSONObject(authCallback);
    final AuthCallbackHandler authCallbackHandler = new AuthCallbackHandler();
    Assert.assertFalse(bitfinexApiBroker.isAuthenticated());
    Assert.assertEquals(ConnectionCapabilities.NO_CAPABILITIES, bitfinexApiBroker.getCapabilities());
    authCallbackHandler.handleChannelData(bitfinexApiBroker, jsonObject);
    Assert.assertTrue(bitfinexApiBroker.isAuthenticated());
    final ConnectionCapabilities capabilities = bitfinexApiBroker.getCapabilities();
    Assert.assertTrue(capabilities.isHavingOrdersReadCapability());
    Assert.assertTrue(capabilities.isHavingOrdersWriteCapability());
    Assert.assertTrue(capabilities.isHavingAccountReadCapability());
    Assert.assertFalse(capabilities.isHavingAccountWriteCapability());
    Assert.assertTrue(capabilities.isHavingFundingReadCapability());
    Assert.assertTrue(capabilities.isHavingFundingWriteCapability());
    Assert.assertTrue(capabilities.isHavingHistoryReadCapability());
    Assert.assertFalse(capabilities.isHavingHistoryWriteCapability());
    Assert.assertTrue(capabilities.isHavingWalletsReadCapability());
    Assert.assertTrue(capabilities.isHavingWalletsWriteCapability());
    Assert.assertFalse(capabilities.isHavingWithdrawReadCapability());
    Assert.assertFalse(capabilities.isHavingWithdrawWriteCapability());
    Assert.assertTrue(capabilities.isHavingPositionReadCapability());
    Assert.assertTrue(capabilities.isHavingPositionWriteCapability());
    Assert.assertTrue(capabilities.toString().length() > 10);
}
Also used : BitfinexApiBroker(com.github.jnidzwetzki.bitfinex.v2.BitfinexApiBroker) JSONObject(org.json.JSONObject) ConnectionCapabilities(com.github.jnidzwetzki.bitfinex.v2.entity.ConnectionCapabilities) AuthCallbackHandler(com.github.jnidzwetzki.bitfinex.v2.callback.command.AuthCallbackHandler) Test(org.junit.Test)

Example 2 with AuthCallbackHandler

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

the class CommandsCallbackTest method testAuthCommandCallback2.

/**
 * Test the auth callback
 * @throws APIException
 */
@Test
public void testAuthCommandCallback2() throws APIException {
    final String authCallback = "{\"event\":\"auth\",\"status\":\"FAILED\",\"chanId\":0,}";
    final BitfinexApiBroker bitfinexApiBroker = Mockito.spy(BitfinexApiBroker.class);
    final JSONObject jsonObject = new JSONObject(authCallback);
    final AuthCallbackHandler authCallbackHandler = new AuthCallbackHandler();
    Assert.assertFalse(bitfinexApiBroker.isAuthenticated());
    authCallbackHandler.handleChannelData(bitfinexApiBroker, jsonObject);
    Assert.assertFalse(bitfinexApiBroker.isAuthenticated());
}
Also used : BitfinexApiBroker(com.github.jnidzwetzki.bitfinex.v2.BitfinexApiBroker) JSONObject(org.json.JSONObject) AuthCallbackHandler(com.github.jnidzwetzki.bitfinex.v2.callback.command.AuthCallbackHandler) Test(org.junit.Test)

Example 3 with AuthCallbackHandler

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

AuthCallbackHandler (com.github.jnidzwetzki.bitfinex.v2.callback.command.AuthCallbackHandler)3 BitfinexApiBroker (com.github.jnidzwetzki.bitfinex.v2.BitfinexApiBroker)2 JSONObject (org.json.JSONObject)2 Test (org.junit.Test)2 ConnectionHeartbeatCallback (com.github.jnidzwetzki.bitfinex.v2.callback.command.ConnectionHeartbeatCallback)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 ConnectionCapabilities (com.github.jnidzwetzki.bitfinex.v2.entity.ConnectionCapabilities)1