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);
}
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());
}
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());
}
Aggregations