Message Boards Message Boards

1
|
17532 Views
|
11 Replies
|
5 Total Likes
View groups...
Share
Share this post:

TD Ameritrade API

Posted 4 years ago

Does anyone have experience developing a wrapper or client in Mathematica for interfacing with an asynchronous REST API that also requires token authentication? In particular, I want to communicate with the TD Ameritrade API which would allow for the reception of real time streaming financial data of every sort and also execute trades. I'd like to use Mathematica for real time analysis of the incoming data. I have looked at the Wolfram documentation on external API's but there are not any real world examples only lists of functions which is of no help at all.

POSTED BY: Kerry Litvin
11 Replies

Hi Kerry There was this Community post some years ago about how to access a TD-Ameritrade account use URLFetch, which has now been superseded by URLRead and URLExecute. See https://community.wolfram.com/groups/-/m/t/512676

Michael

POSTED BY: Michael Kelly

Hi Kerry,

I am working on this also. The first step is to obtain the your token from TD, which is quite an involved process.

I tried many guides, but this one is by far the best. https://www.reddit.com/r/algotrading/comments/c81vzq/td_ameritrade_api_access_2019_guide/

I have this working in Mathamatica now. It is a bit complicated as the TD token needs to be refreshed every 30 minutes. Here is the notebook. https://www.wolframcloud.com/obj/62db899d-0697-48f6-bca0-ac4b51e8bb79

Would love some feedback from people with better Mathmatica knowledge on improvements.

Regards Josh

POSTED BY: Josh Cameron

Josh:

Please post when you have a solution.

I skimmed through the reddit link you provided. It is good that it lead you to a solution path. However, that quick look tells me that there is something a bit convoluted (but if it works? it works!). The parts that are of concern is going to another site just to get a URL Decode or Encode.

Keep us posted

Hans

POSTED BY: Hans Michel

I was in communication with someone in Europe associated with Wolfram Research's external API team. He provided the following tips:

What you need basically is URLRead. What kind of token authorization? If it's just a token parameter, add that to your HTTPRequest. If it's OAuth, just SecuredAuthenticationKey. Currently supports OAuth 1.0a but will soon be updated to support OAuth 2.0

Kerry Litvin From what I see in the TD Ameritrade documentation, here are the steps you need to follow to authenticate (https://developer.tdameritrade.com/content/simple-auth-local-apps). For that, you basically just need to build your request using HTTPRequest and executing the actual request with URLRead. Something like URLRead[HTTPRequest[<|...|>]]

Once you have that part ready, you can use the APIs here https://developer.tdameritrade.com/apis

The API you need depends on the type of data you want to extract.

Regarding the documentation, my team is working on expanding the documentation to add more examples (including OAuth 2.0 workflows). However, please note that the documentation pages, while they tend to have useful examples and use cases (Applications section), they are not meant to be tutorials. We do have tutorials and workflows for that.

In any case, I'm taking note of your feedback to have that into consideration when updating the docs.

Also, we are working on new functionalities that will allow users to easily connect to external APIs following a guided process.

POSTED BY: Kerry Litvin

Additionally TD provided the following little bit of information:

A callback URL is something you assign to your application during the application registration process. If your application is local to your computer, you can use a locally hosted callback URL like https://127.0.0.1:8080.

POSTED BY: Kerry Litvin

Also there are several very good videos on YouTube describing detailed TD API interface wrappers developed in Python including links to Git Hub where the complete code can be downloaded. I suppose if we could simply use Mathematica to make the calls to the TD API via the provided Python code that may be a workaround.

This fellow's channel has very good information using Python:

https://youtu.be/P5YanfJFlNs

As does this channel:

https://youtu.be/qJ94sSyPGBw

POSTED BY: Kerry Litvin

Also there are several very good videos on YouTube describing detailed TD API interface wrappers developed in Python including links to Git Hub where the complete code can be downloaded. I suppose if we could simply use Mathematica to make the calls to the TD API via the provided Python code that may be a workaround.

This fellow's channel has very good information using Python:

https://youtu.be/P5YanfJFlNs

As does this channel:

https://youtu.be/qJ94sSyPGBw

POSTED BY: Kerry Litvin

Josh, any relation to Ross Cameron of Warrior Trading and YouTube fame? I think he has the most views of anyone on YouTube discussing day trading.

https://youtu.be/txWaMpSzHhM

Here is the link to the TD API site for developers:

https://developer.tdameritrade.com/apis

POSTED BY: Kerry Litvin

One other note. The Tasty Works / Tasty Trade platform is owned and was/is developed by the original people from Think or Swim (Tom Sosnoff and company) which was sold to TD several years ago. They will be providing an API to the Tasty Works platform in the coming weeks which is supposed to be much more user friendly than the TD API. Additionally, since Tasty Works was developed by the same TOS development team and professional traders they knew of all the shortcoming in TOS and have worked to modernize and update every shortcoming and have made the trade execution orders of magnitude faster in Tasty Works than on TD's TOS platform. It is my understanding that since the time TD bought out TOS there has been little if any real modernization of the platform. In fact, with Charles Schwabb's purchase of TD's retail trading business there is little hope for any substantial upgrades to TOS in the immediate future. In short, Tasty Works is essentially a completely overhauled version of TOS both on the front end user interface and the back end execution technologies. I am told that Tasty Works trades are executed via a high frequency trading firm. Something to consider if you are not completely committed to TD and TOS.

https://tastyworks.com/

https://www.tastytrade.com/

POSTED BY: Kerry Litvin

Hi Guys,

I have attached the TD wrapper. It could be improved a lot, but it will give you a great flavor of what you can do. I would think of it mainly as a good way of testing out a proof of concept, rather than something you could trade with at this point.

https://www.wolframcloud.com/obj/62db899d-0697-48f6-bca0-ac4b51e8bb79

My thinking is this is a good way of seeing what you can actually do with live market data in the Mathematica. My plan is to try and write some option pricing code, and see if I can come up with anything useful.

Anyway, good luck. Happy to help people if you get stuck, and would love other to add improvements so we can all use the cleanest code possible.

Thanks

Josh

POSTED BY: Josh Cameron
Posted 2 years ago

Josh, I tried that link you posted but it says http 403, not authorized. Is that link still good?
Thx

Bart

POSTED BY: Bart J
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract