API Trading w/ Thinkorswim

First of all: PLEASE PLEASE PLEASE be careful with automated trading. It is not for everyone and takes a lot of work to keep running and to make money. Don't jump into this without experience trading manually. Depending on your strategy, your may run out of day trades pretty quickly and should probably should have a cash account. Use this art your own risk with the understanding that if you use it the consequences are on you.

Attached is a link to a git repo for those that want to utilize and automated trading bot through TOS. My partner and I made the program and strategies and when I say my partner and I, I mean he did 99.999% of the work. I think I have mainly just been there for moral (and demoralized) support.

We both thought we would share this with the community that has helped us with some successful strategies.

I will say this: If you have questions, I will forward them to my partner because all I know about coding is that I can't put white out on the screen when I make a mistake.

Other than that I politely ask two things:

1: If you make the code better, please "fork" it in github so we can make it better for all of us. Also, I don't know what fork means.

2: My partner (who is like Rain Man with a laptop) has worked upwords of a 1000 hours on this program. If you could donate a dollar or two to him on buymecoffee at the bottom of the github, I know he would appreciate it. I don't get, want, or deserve any of the money.

Without further ado:

https://github.com/TreyThomas93/python-trading-bot-with-thinkorswim
 
Last edited:
@kimber_da Could you please edit your first post to include a warning about the extreme risks of automated trading... We are getting a lot of new members signing up who could potentially get in way over their heads should they try automated trading... While it may be a great concept, automated trading is nothing to play with if you don't fully understand the risks as well as the code involved... Better safe than sorry... 💡

Edited to add: After fully reviewing the GitHub documentation it would probably be well beyond most traders ability to implement this system anyway... I've been doing IT work for 30+ years, working in too many programming languages (including low level assembly language) and environments to count, and probably wouldn't invest the time and effort required myself... Adding in overhead of monthly expenses would push even more members out of the realm... Neat concept just the same... A lot of thought and effort has gone into this... Just a bit on the geeky side...
 
Last edited:
@kimber_da I like it. I've seen other respositories leveraging the TD API, but this is the first version I've seen that attempts to leverage the user-side of ThinkOrSwim. (There are reports that TD had a prior platform that allowed full automation, so this feature is intentionally missing from ThinkOrSwim, as best as I can tell.)
 
Thank you so much for sharing this with us. I have a question and I apologize if this sounds extremely basic but, how do I create another "Database" with in the cluster? Im very excited to see what this does and analyze it for myself whether it works in my trading that or not. I know there is something to learn :). I am an experienced trader. Nonetheless, I am not a coder. I understand some of the functions and am open to learning how to code. For now, I just need that basic info. Maybe there is something Im not seeing. Thanks for taking a second to answer my post.
 
Thank you so much for sharing this with us. I have a question and I apologize if this sounds extremely basic but, how do I create another "Database" with in the cluster? Im very excited to see what this does and analyze it for myself whether it works in my trading that or not. I know there is something to learn :). I am an experienced trader. Nonetheless, I am not a coder. I understand some of the functions and am open to learning how to code. For now, I just need that basic info. Maybe there is something Im not seeing. Thanks for taking a second to answer my post.
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.
 
Thank you so much for sharing this with us. I have a question and I apologize if this sounds extremely basic but, how do I create another "Database" with in the cluster? Im very excited to see what this does and analyze it for myself whether it works in my trading that or not. I know there is something to learn :). I am an experienced trader. Nonetheless, I am not a coder. I understand some of the functions and am open to learning how to code. For now, I just need that basic info. Maybe there is something Im not seeing. Thanks for taking a second to answer my post.
I will ask my partner and see what he says. Like I said, I know next to nothing about code.
 
I have banged my head against the wall with TD Ameritrade API for a while. It works most of the time, but reliability is not perfect.

What I don't like the most is that they don't allow trades for Futures.
 
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.
 

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

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

87k+ Posts
449 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