td-ameritrade-client icon indicating copy to clipboard operation
td-ameritrade-client copied to clipboard

Streaming API

Open bosohn opened this issue 5 years ago • 3 comments
trafficstars

Hi,

First of all, thanks for the package. It is simple to use and works great.

Can you add streaming API assuming TD supports streaming?

Streaming API allows

  • user to specify list of symbols and callback methods which can be called from another thread user can decide whether to use queue, messaging, etc. on callback
  • user can update the list of instruments, adding or removing to subscribed symbols
  • prefer to have real-time callback

Thanks for your consideration, Brian

bosohn avatar Jun 12 '20 21:06 bosohn

Yes, thanks for the library!

I was able to extend it to get the Streaming API to work and forward it to TWS API so I can do some paper trading. However, it seems like TD Ameritrade will not allow you to connect for longer than 1.5 days. It varies. I can sometimes maintain streaming for as long as 2.5 days but no more. I have code there that handles reconnections (e.g., when I kill my network connection) and works, but for some reason after 1.5 days or so, it won't work.

My guess is that this is a TD Ameritrade limitation. What is perplexing, however, is that if I stop my app and then restart it, I can start streaming again. My first thought was to make sure OkHttpClient, which HttpTdaClient also uses, clears any cache, cookies, etc. That still doesn't help. Assuming it's OkHttpClient, there must be a way to totally re-initialize it.

Has anyone run into this issue? Or have any ideas on totally re-initializing OkHttpClient like maybe reloading any system libraries?

man910 avatar Apr 14 '22 19:04 man910

Hi @ma would you be willing to show me your streaming code or do a pull request?

I would like to test it out, and then I can see if I also get kicked off after 1.5 days or so. Maybe it's just a "You" issue and not the rest of us (e.g. you're not as good of a stonk trader as we are, lol - just kidding).

Anyway, let me see the code and if we can figure out that it's a OKHttp issue, then there is a possibility we can change the OKHttp lib to use a newer version, because they aren't even really updating any longer the version that is used for this TDA Client.

Thanks!

studerw avatar Apr 14 '22 21:04 studerw

Sure, but it may be confusing / too much since a lot of it is to adapt the TDA request / response to TWS. If you still want it, I can attach it later. Otherwise, when I have time, I can strip it down to the bare bones.

man910 avatar Apr 15 '22 00:04 man910