Skip to content

Authenticating

guillaumedebavelaere edited this page Oct 16, 2017 · 1 revision

Once a broker is linked via OAuth, it needs to be authenticated to perform actions on behalf of the user. Successfully authenticating will result in a session (that will time out after 15 minutes of inactivity). Obtain a session by calling authenticate:

linkedBroker.authenticate(new TradeItCallbackWithSecurityQuestionImpl<List<TradeItLinkedBrokerAccountParcelable>>() {
    @Override
    public void onSuccess(final List<TradeItLinkedBrokerAccountParcelable> accounts) {
        // The linked broker is successfully authenticated and the accounts associated with that broker login are populated on the linked broker object (and returned to the callback)
    });
    
    @Override
    public void onSecurityQuestion(TradeItSecurityQuestion securityQuestion) {
        // Sometimes there is a security question the user need to answer before being authenticated
        
        // Prompt the user for an answer and submit the answer like this
        this.submitSecurityAnswer("my answer"); // then one of the three callbacks will be called (onSuccess, onSecurityQuestion, onError)
        
        //or to cancel the security question
        this.cancelSecurityQuestion();
    }

        @Override
        public void onError(TradeItErrorResult error) {
            // an error occured
        }
    }
);

Use the linked broker accounts to perform actions on behalf of the user:

List<TradeItLinkedBrokerAccount> accounts = linkedBroker.getAccounts();
accounts.get(0).refreshPositions(...);
Clone this wiki locally