private void setupCommandCallbacks ( ) { commandCallbacks = new HashMap <> ( ) ; commandCallbacks . put ( "info" , new DoNothingCommandCallback ( ) ) ; // TODO: hb is not ping:pong final ConnectionHeartbeatCallback pong = new ConnectionHeartbeatCallback ( ) ; pong . onHeartbeatEvent ( l -> this . updateConnectionHeartbeat ( ) ) ; commandCallbacks . put ( "pong" , pong ) ; final SubscribedCallback subscribed = new SubscribedCallback ( ) ; subscribed . onSubscribedEvent ( ( channelId , symbol ) -> { synchronized ( channelIdToHandlerMap ) { final ChannelCallbackHandler channelCallbackHandler = createChannelCallbackHandler ( channelId , symbol ) ; channelIdToHandlerMap . put ( channelId , channelCallbackHandler ) ; channelIdToHandlerMap . notifyAll ( ) ; } logger . debug ( "subscribed: {}" , symbol ) ; callbackRegistry . acceptSubscribeChannelEvent ( symbol ) ; } ) ; commandCallbacks . put ( "subscribed" , subscribed ) ; final UnsubscribedCallback unsubscribed = new UnsubscribedCallback ( ) ; unsubscribed . onUnsubscribedChannelEvent ( channelId -> { ChannelCallbackHandler removed ; synchronized ( channelIdToHandlerMap ) { removed = channelIdToHandlerMap . remove ( channelId ) ; channelIdToHandlerMap . notifyAll ( ) ; } if ( removed != null ) { callbackRegistry . acceptUnsubscribeChannelEvent ( removed . getSymbol ( ) ) ; logger . debug ( "unsubscribed: {}" , removed . getSymbol ( ) ) ; } } ) ; commandCallbacks . put ( "unsubscribed" , unsubscribed ) ; final AuthCallback auth = new AuthCallback ( ) ; auth . onAuthenticationSuccessEvent ( permissions -> { logger . info ( "authentication succeeded for key {}" , configuration . getApiKey ( ) ) ; final BitfinexAccountSymbol symbol = BitfinexSymbols . account ( permissions , configuration . getApiKey ( ) ) ; final AccountInfoHandler handler = new AccountInfoHandler ( ACCCOUNT_INFO_CHANNEL , symbol ) ; handler . onHeartbeatEvent ( timestamp -> this . updateConnectionHeartbeat ( ) ) ; handler . onPositionsEvent ( callbackRegistry :: acceptMyPositionEvent ) ; handler . onWalletsEvent ( callbackRegistry :: acceptMyWalletEvent ) ; handler . onSubmittedOrderEvent ( callbackRegistry :: acceptMySubmittedOrderEvent ) ; handler . onTradeEvent ( callbackRegistry :: acceptMyTradeEvent ) ; handler . onOrderNotification ( callbackRegistry :: acceptMyOrderNotification ) ; channelIdToHandlerMap . put ( 0 , handler ) ; callbackRegistry . acceptAuthenticationSuccessEvent ( symbol ) ; callbackRegistry . acceptConnectionStateChange ( BitfinexConnectionStateEnum . AUTHENTICATION_SUCCESS ) ; } ) ; auth . onAuthenticationFailedEvent ( permissions -> { logger . info ( "authentication failed for key {}" , configuration . getApiKey ( ) ) ; final BitfinexAccountSymbol symbol = BitfinexSymbols . account ( permissions , configuration . getApiKey ( ) ) ; callbackRegistry . acceptAuthenticationFailedEvent ( symbol ) ; callbackRegistry . acceptConnectionStateChange ( BitfinexConnectionStateEnum . AUTHENTICATION_FAILED ) ; } ) ; commandCallbacks . put ( "auth" , auth ) ; final ConfCallback conf = new ConfCallback ( ) ; conf . onConnectionFeatureEvent ( connectionFeatureManager :: setActiveConnectionFeatures ) ; commandCallbacks . put ( "conf" , conf ) ; commandCallbacks . put ( "error" , new ErrorCallback ( ) ) ; }
Setup the command callbacks