API Trading w/ Thinkorswim

Join useThinkScript to post your question to a community of 21,000+ developers and traders.

As an aside, if you want to have exposure to HFTs without all the massive headaches that come with running APIs etc, you can just trade VIRT and read their public docs.

Before jumping into the deep end of this stuff, googling RenTec's results in recent market turmoil is interesting as well.
 
I am the creator of this program, and let me tell you, if you are not familiar with programming, then you should not attempt to implement this until you have a good foundation in programming. This is an intermediate to advanced level program.

That being said, I can at least advise you on database creation for your cluster.

When you create a cluster in Mongo using the GUI, you need to click on the cluster name within your projects. Once in your cluster, there is a button that says Create Database. Click that, give your database a name, and insert some data just to temporarily fill it, and your good.
Well, even though Im not experienced in coding I can learn. Nonetheless, if its carelessness you are worried about, then you dont have to worry because I am an experienced trader. (not that you would be worried). I just want to be able to implement this and try it out. Im sure I can adjust some things here and there. Ill ask for help if need be.

Are you basically saying the code you provided requires additional code input to complete? If so, thats fine. I just want to be able to get something going that I can come back to and build upon, If that makes any sense.
 
Well, even though Im not experienced in coding I can learn. Nonetheless, if its carelessness you are worried about, then you dont have to worry because I am an experienced trader. (not that you would be worried). I just want to be able to implement this and try it out. Im sure I can adjust some things here and there. Ill ask for help if need be.

Are you basically saying the code you provided requires additional code input to complete? If so, thats fine. I just want to be able to get something going that I can come back to and build upon, If that makes any sense.
It's more of a plug and play type of program. The code is already written. You just have to handle the third party API's and configure them to your personal settings. If you follow the docs in the repo, they will guide you in the right direction. It's quite complex of a program, and only makes sense to the one who wrote it. That being said, don't hesitate to ask me questions throughout.
 
It's more of a plug and play type of program. The code is already written. You just have to handle the third party API's and configure them to your personal settings. If you follow the docs in the repo, they will guide you in the right direction. It's quite complex of a program, and only makes sense to the one who wrote it. That being said, don't hesitate to ask me questions throughout.
Thats perfect. If the structure is there I can fill in the rest. I appreciate you taking some time to answer my questions thank you. And thanks again for sharing your code with the community. :)
 
@kimber_da @TreyThomas673 - this is awesome, nice work.

one issue i found was that the sim_trader runTrader has conditions to check if side is BUY or SELL, but not checking for BUY_TO_OPEN or SELL_TO_CLOSE.

And one question. As far as i can tell, this is designed for a user to have only one Asset_Type, EQUITY or OPTION. So if i want to trade both Asset_Type I can not unless I use two separate TD accounts, and create two users, is it correct?
 
kimber_da,

Do you have a video that will explain how to use your trading bot? That would help me and maybe some others too.

Thanks.
 
@kimber_da @TreyThomas673 - this is awesome, nice work.

one issue i found was that the sim_trader runTrader has conditions to check if side is BUY or SELL, but not checking for BUY_TO_OPEN or SELL_TO_CLOSE.

And one question. As far as i can tell, this is designed for a user to have only one Asset_Type, EQUITY or OPTION. So if i want to trade both Asset_Type I can not unless I use two separate TD accounts, and create two users, is it correct?
The sim trader has not been set up to trade options due to the fact that it is difficult to get accurate results "paper" trading options.

As for your second question, you are only allowed one asset type per account. You are obviously welcome to tweak the code to allow for this.
 
https://github.com/TreyThomas93/python-trading-bot-with-thinkorswim

I created this program for auto trading through TDAmeritrades API, using scanners and alerts from the Thinkorswim platform.

Hope this helps.
@TreyThomas673 Can you share your success thus far using this code for auto trade? I wanted to use this to trigger auto trade based on a study condition similar to conditional trades (1st trgs seq), but do it on GTC_EXT hours on all my watchlist that have buy signal based on a specific study/studies.. I would love to pick your brain on this..
 
Last edited:
@TreyThomas673 Can you share your success thus far using this code for auto trade? I wanted to use this to trigger auto trade based on a study condition similar to conditional trades (1st trgs seq), but do it on GTC_EXT hours on all my watchlist that have buy signal based on a specific study/studies.. I would love to pick your brain on this..
The results here are simulated results using the strategies developed through Thinkorswim. What makes these simulated is that these buy and sell every alert triggered and received from TOS. Unlike live trading, which limits you based on buying power. So basically you are paper trading through the program. As for live trading results, since November 2020, the program has made close to $450. This is obviously subject to be different per user based on how successful the users strategies are. My program is a mere vessel to trade through using those strategy based alerts. The past several months have been mainly debugging and enhancing the program to where it is at currently.

As for the watchlists/scanners with GTC_EXT hours, the program runs on a while loop every 5 seconds, so it will trade after hours if thats what you are wondering. Like I said, most of the customization can be done through TOS.
 
Thanks for sharing. Members probably know, but just want to post a reminder nevertheless, TD API's do not work on paper trading.
This is indeed interesting stuff. It might be possible, for those wishing to paper trade, to set up the code to use ToS Strategies, the same email setup as the original code, but route trade orders through Alpaca, for example, which has a paper trade API. Not saying this is a good idea, and if the code polls your positions via ToS it wouldn't work... but it could offer a paper trading method without having to create data pipelines and indicators in python.

-mashume
 
1. Am looking for the scanner name format, you specified. how it is formed at ToS client side ?
2. say, i have a study with certain alert in it. how do i send that alert to gmail account. (alert to gmail setup i understand.)
am looking for info on how to setup a scanner with my study ?

looks i need to create a scanner with a name you specified with tag SELL as one scanner, BUY as another scanner ?

Can you help me in understanding how to create the scanner , with the name format you have, and is it one scanner per strategy ?



or how does the scanner run everytime and send alert to gmail periodically ?
 
Last edited:
Also, which strategy we can get better buy and sell signal alerted ? any pointers on which one to use ?

There could be plenty out there,
But as advanced/seasoned traders you guys might have some favorite ones, or some might be already discussed in this forum..
 
Pretty neat program. How difficult would it be to implement MySQL DB instead of MongoDB? Any recommendations on the code?
 
I will ask my partner and see what he says. Like I said, I know next to nothing about code.
If you wanted to learn, Python is one of the easier languages to learn. I would recommend using either PyCharm or Visual Studio Code as an IDE. PyCharm has pretty much everything you need "out of the box" while VSC necessitates installing some free plugins. There are some good courses on Udemy for learning Python, but it will take an investment of time. Once you get your head around one language, subsequent languages are easier to pick up in my experience.
 
This looks awesome Trey. This is one of the first python specific walkthrus I’ve seen for ToS. Im definitely more familiar coding in thinkscript and backtesting strategies on ToS but what you’re doing is exactly what I’m trying to implement in my trading plan.

I’m going to play around the code and see if I can code my strategy in it. Thanks for sharing! Are you exploring other strategies? Are you actively working on this in any space? Discord/Twitter/etc?
 

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

87k+ Posts
504 Online
Create Post

Similar threads

Similar threads

The Market Trading Game Changer

Join 2,500+ subscribers inside the useThinkScript VIP Membership Club
  • Exclusive indicators
  • Proven strategies & setups
  • Private Discord community
  • ‘Buy The Dip’ signal alerts
  • Exclusive members-only content
  • Add-ons and resources
  • 1 full year of unlimited support

Frequently Asked Questions

What is useThinkScript?

useThinkScript is the #1 community of stock market investors using indicators and other tools to power their trading strategies. Traders of all skill levels use our forums to learn about scripting and indicators, help each other, and discover new ways to gain an edge in the markets.

How do I get started?

We get it. Our forum can be intimidating, if not overwhelming. With thousands of topics, tens of thousands of posts, our community has created an incredibly deep knowledge base for stock traders. No one can ever exhaust every resource provided on our site.

If you are new, or just looking for guidance, here are some helpful links to get you started.

What are the benefits of VIP Membership?
VIP members get exclusive access to these proven and tested premium indicators: Buy the Dip, Advanced Market Moves 2.0, Take Profit, and Volatility Trading Range. In addition, VIP members get access to over 50 VIP-only custom indicators, add-ons, and strategies, private VIP-only forums, private Discord channel to discuss trades and strategies in real-time, customer support, trade alerts, and much more. Learn all about VIP membership here.
How can I access the premium indicators?
To access the premium indicators, which are plug and play ready, sign up for VIP membership here.
Back
Top