Cannot Login to TD Ameritrade Streaming API

  angular, rxjs, typescript, websocket

I’m trying to use the LOGIN command for the TD Ameritrade streaming API but I am getting this response back:

{
"response": [{

    "service": "QUOTE",

    "requestid": "3",

    "command": "ADD",

    "timestamp": 1619988269641,

    "content": {

        "code": 21,

        "msg": "Bad command formatting"

    }

}]
}

I couldn’t find this error message in the documentation, so I think it has something to do with how ‘credential’ is sent over.
This is the request I am sending:

{
"requests": [{

    "service": "ADMIN",

    "command": "LOGIN",

    "requestid": 0,

    "account": credentials.userid,

    "source": credentials.appid,

    "parameters": {

        "credential": this.serializeAndEncode(credentials),

        "token": credentials.token,

        "version": "1.0"

    }

}]
}

The (masked) stringified credential:
userid%3XXX%26token%3DXXX%26company%3DAMER%26segment%3DAMER%26cddomain%3DXXX%26usergroup%3DACCT%26accesslevel%3DACCT%26authorized%3DY%26tokenTimeStampAsMs%3D1619988269000%26appid%3DXXX%26acl%3DXXX

I am using Rxjs webSocket to do this in an angular application.

var request = {
  "requests": [
    {
      "service": "ADMIN",
      "command": "LOGIN",
      "requestid": 0,
      "account": credentials.userid,
      "source": credentials.appid,
      "parameters": {
        "credential": this.serializeAndEncode(credentials),
        "token": credentials.token,
        "version": "1.0"
      }
    }]
};

console.log("[App] Logging In", request);
this.messages$.next(JSON.stringify(request));

Source: Angular Questions

One Reply to “Cannot Login to TD Ameritrade Streaming API”

  • Not sure if you figured this out or not but I was having the same problem.

    I got it to work but it was counter to the documentation. It says the urlencode the credential, however that’s the problem. It doesn’t accept a real urlencoded string. It wants:

    userid=1234&token=abc&company=AMER

    Don’t replace the = or &

    Odd but worked! Hope this help.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.