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?
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 thekeys
parameter. If that's the case, then you may have to send an array of requests - anUNSUBS
followed by aSUBS
to the remaining symbols.