2

Using the TD Ameritrade API Page, my C# app successfully logs in and subscribes to get a data stream for several symbols using a small field list.

Now I add a second subscription with a different field list that might contain some of the same symbols.

I parse the data responses, sending the updates to the appropriate places in my app. Fine.

Now to unsubscribe one of those data requests, I am trying this. For example if first asked for "SMCI,INFN,TSM" and the second asked for "AMD,SMCI,INFN" and I am unsubscribing the second list:

TDRequestQuote quoteRequest = new TDRequestQuote
{
    service = "QUOTE",
    command = "UNSUBS",
    requestid = pID.ToString(),
    account = _TDUser.accounts[0].accountId,
    source = _TDUser.streamerInfo.appId,
    parameters = new TDRequestQuoteParameters
    {
        keys = sSymbolList
    }
};
string sEndRequestQuote = JsonConvert.SerializeObject(quoteRequest, Formatting.None, new JsonSerializerSettings { NullValueHandling = NullValueHandling.Ignore });
_WebSocket.Send(sEndRequestQuote); //A WebSocketSharp.WebSocket

I get the following message after two heartbeat notifications:

{"notify":[{"service":"ADMIN","timestamp":1628966081898,"content":{"code":30,"msg":"Stop streaming due to empty subscription"}}]}

Then the whole web socket closes.

But the symbol "TSM" should be active!

The API shows no examples of using the command, "UNSUBS".

How do you successfully unsubscribe one data request and leave the others active?

John Kurtz
  • 775
  • 8
  • 16
  • FYI, the fields have to be requested in field number order also. So if you request them in the order "0,3,1,2" (Symbol, Last Price, Bid Price, Ask Price), you will only ever get Symbol and Last Price. If you request the fields in order, you will get data for those fields. – John Kurtz Aug 30 '21 at 22:25

1 Answers1

0

As you noted, the API documentation doesn't explain the behavior of UNSUBS. It could be that the command unsubscribes you from all symbols, regardless of the keys parameter. If that's the case, then you may have to send an array of requests - an UNSUBS followed by a SUBS to the remaining symbols.

Spencer Bench
  • 647
  • 4
  • 7
  • Hi Spencer, that is close to the direction that I took last week... I keep a dictionary with each KeyValuePair being an ID of the request and an object holding Symbols & Fields for that request. When I open a new watch list, I add that set to the dictionary and simply request a new SUBS for the superset of all symbols and the union of the fields. If I close a window of a watch list, I simply remove that entry from the dictionary and rebuild the superset and perform a SUBS request for the remaining items. It seems to work. They did not finish that document so any inefficiency is their onus. – John Kurtz Aug 26 '21 at 12:43
  • @JohnKurtz Yup. A large successful company like TD Ameritrade really has no excuse for poor documentation like this. – Spencer Bench Aug 26 '21 at 18:28