Building your own trading bot is a ton of fun. Retrieving historical data, identifying and calculating stock indicators, then creating a risk managed strategy is not just enjoyable - it can also be incredibly profitable!
However, trading bot development can seem a pretty intimidating. There's a lot to consider. Things like:
- Retrieval of financial market data
- Calculation of technical indicators
- Conversion of an idea into strategy
If you're wondering how on earth to even begin building your own trading bot, then you're going to love this new series from TradeOxy!
What You'll Learn Through My Blog
I'm going to show you everything you need to build your own trading bot from scratch, including:
- Your own completely customizable development environment, including the worlds most popular technical indicators, and cutting-edge AI from ChatGPT
- The ability to retrieve historical stock data on over 10,000 US based stocks
- The power to calculate stock technical indicators on any stock you retrieve
- The insight to manage your risk
The premium episodes expand this amazing knowledge base to include:
- A whole host of technical indicators
- Advanced risk management
- Advanced strategy building
What You'll Have by the End of this Episode
By the end of this episode, you'll have built your very own development environment. You'll have a development environment that includes:
- GitHub Copilot. An Artificial Intelligence ChatGPT 4 based code assistant
- TA Lib Library. One of the worlds most popular technical analysis libraries, TA Lib
- Recommended Add-ons. Helpful add-ons that will drastically improve your development process
On top of these incredible features, you'll have also built a development environment that is:
- Multi-platform. No matter what operating system you use, you can follow this guide
- Web based. Even if you only have a web browser, you can follow this guide
- Always Up to Date. Your development environment will always be up-to-date
- Provides scaleable compute capacity. The ability to scale up and scale down your compute resources as needed
- Uses the latest security practices. Any secrets information you provide will be protected by some of the worlds latest security practices.
GitHub. All the code for this episode, and for this series, can be found on my GitHub repo. Click the button below to access it.
Helpful Help from TradeOxy
TradeOxy's mission is to democratize algorithmic trading, and that mission extends to my blog.
If at any point you get stuck in this series, then reach out to us on our Discord chat. I and my team will be more than happy to help out (just make sure it's about our content).
Why Do I Need a Development Environment?
There are three critical keys you need to consider when building your own trading bot:
Combined, these keys ensure that your trading bot:
- "Just works" - i.e. once you've developed your strategy, it works on live data in the same way you tested it
- Scales at the same pace as your insights and ideas - i.e. it's easy to add new ideas and concepts as your knowledge, experience and confidence grows
- Keeps your secret data secret
Characteristics of an Effective Development Environment
An effective development environment lays the foundations for these keys. It allows you to:
- Capture and store your code so that it's always accessible to you and only you (unless you deliberately share it)
- Set up an environment you enjoy working in, with features that actually work
- Incorporate your own tools so that you can add new and (hopefully) profitable ways of analyzing the market
With that in mind, let's do it!
Dev Environment Foundational Resources: Visual Studio Code, GitHub, and GitHub Codespaces
The development environment I'll be showing you starts with three pretty amazing tools. I'll quickly outline them for you below.
What is VS Code?
Visual Studio Code, also known as VS Code, is an Integrated Development Environment or IDE. In plain language, this means that it's a place (environment) where you can develop your code.
There's a number of different IDE's that exist, however, I've settled on VS Code as my primary IDE. We use it extensively in TradeOxy for our development work, and we're constantly discovering more and more amazing features. For our purposes in this episode, there's five reasons we'll be using this:
- Free. VS Code is entirely free for personal AND commercial use. Most of the add-ons (which I talk about in a moment) are also free.
- Open Source. You can inspect the entire code base for VS Code if you so desire.
- Runs Everywhere. I'm constantly amazed by the sheer ubiquity of VS Code. It doesn't matter if I'm using my Mac, Windows machine, Raspberry Pi, or if I just have a web browser, VS Code runs the same, looks the same, and does the same thing. It's truly remarkable.
- Lightweight. VS Code is the opposite of a resource hog, especially for a code editing environment. Compared to other IDE's I've used, VS Code is like comparing the weight of a feather to that of a brick.
- Add-Ons Everywhere. This is probably my favorite feature of VS Code. You can get extensions for almost anything, including themes, debuggers, code linting, language support and more. It honestly feels like anything I want to add I can find.
- Integrates incredibly well with the rest of our tech stack. VS Code integrates really well with the rest of our tech stack. You won't have to spend hours solving annoying configuration problems. Instead, you can just get to work.
How do I access VS Code?
If you're planning to install VS Code on your system, rather than using the web version, then follow this link to get your operating system specific executable.
Alternatively, you can just click here and get exactly the same experience through your web browser. No installation required.
What is GitHub?
With a powerful IDE at our disposal, our next challenge is to save our code.
To do this, we'll be using GitHub. GitHub is what's known as an online software development platform. Tens of millions of developers, all around the world, use GitHub to store, manage, test, and collaborate on software projects. It's an amazing piece of kit, and we use it extensively at TradeOxy. Here's a link to my personal GitHub profile if you want to check it out and give me a star.
How do I get GitHub?
GitHub has a generous free tier. You can sign up for it for free.
Go ahead and do that now using this link.
What Is GitHub Codespaces?
GitHub Codespaces will change your (development) life. It takes the concepts from VS Code and GitHub and puts them into something amazing.
GitHub Codespaces allows us to develop a completely templated development environment that will work from anywhere we have access to the internet. Instead of having to go through the process of setting up an IDE, adding all our tooling, then adding GitHub, then cloning the repository every time we go anywhere, we can do it once, then access it from anywhere.
This is particularly helpful when we start talking about adding TA Lib to our trading bot!
At the time of writing, you can get all of these features for up to 60 hours per month free. That is more than enough time to complete this episode, then build your own trading bot!
However, that's not all. By the way, these are my own words - I don't get any subsidies to talk about this amazing product.
- GitHub integration. GitHub Codespaces also completely integrates with your GitHub. In this tutorial, we'll be setting it up so that as you develop your code, it is saved directly to your GitHub. You'll never lose your code again.
- VS Code Integration. GitHub Codespaces is built on top of the VS Code online editor I mentioned previously. This means that any feature that you find in VS Code is available on GitHub Codespaces.
Go ahead and sign up for it now using this link.
Create a Dev Environment in Five Steps
Let me show you how easy it is to create your trading bot development environment.
- Step 1: Go to your GitHub, navigate to "Repositories" and click "New"
- Step 2: Fill in the details (make sure you name it something cool). If you want everyone to see your code, set it to Public otherwise select Private. Once you're done, press "Create Repository"
- Step 3: Once GitHub has created a repository, press the button that says "Code". In the drop down that appears, select "Codespaces" then "Create Codespace on main"
- Step 4: Once your Codespace has started up, add a new file called "app.py" and add a line "print("Hello World")". Press play on your editor.
- Step 5: Add in whatever extensions you like. Check out the bottom of this article for a list of my favourites.
How cool is that! In less than 10 minutes, you've got a dev environment up and running!
Take Your Trading Bot Dev Environment to the Next Level with Technical Analysis
Let's talk about technical analysis.
In the world of trading bots, technical analysis is considered fundamental. The ability for your trading bot to perform technical analysis is one of the most common requirements you can have. Over the years, many of my readers and viewers have asked for guides on how to do this, so I'm just going to include it right now, upfront.
What is TA Lib?
When it comes to the technical analysis of trading data, TA Lib is considered the gold standard. The good news is that it is free, used extensively throughout the world, and has over 150 technical analysis indicators you can choose from.
What Technical Indicators does TA Lib Support?
As the gold standard of technical analysis, TA Lib has a comprehensive variety of indicators. The key groupings include:
- Candlestick chart patterns
- Momentum indicators
- Trend indicators
- Volatility indicators
- Volume indicators
You can also use technical indicators data and TA Lib functions together to create your own indicators.
A full list of all the ta functions can be found here.
How can I add TA Lib to my Trading Bot Dev Environment?
The bad news for TA Lib is that it is normally extremely annoying to try and get working in your dev environment. In fact, I had so many requests from my audience to show them how to do it, I made a video on YouTube about it. Since the day I created it, it has consistently been my number 1 watched video every month.
Today I'm going to show you how to defeat TA Lib and integrate it into your trading bot development environment forever. So long, most watched YouTube video!
- In your code space root directory, create a file called requirements.txt
- Add a line to requirements.txt called TA-Lib
- In your code space, create a folder called .devcontainer
- In .devcontainer, create a file called Dockerfile (if you get a prompt about restarting your container, ignore this for now)
- Again in .devcontainer, create another file called devcontainer.json
Here's what your file structure should look like now:
Now, update your
Dockerfile with this code:
Next, update your
devcontainer.json with this text:
Once that's done, head to your VS Code command bar and select "Restart Container".
That's it. All of the functions supported by TA Lib are now yours to use!
AI ChatGPT and Your Dev Environment: Together At Last
Let's add one of the most exciting development tools on the market right now - GitHub CoPilot.
GitHub CoPilot will:
- Save you a ton of time, with many developers claiming a 50-60% time reduction in their development
- Provide you in-line code suggestions that are relevant AND align with your coding style
- Answer questions in the context of your code
It's by no means perfect, but in the 10 months I've been using it, it's been a game changer.
What is GitHub CoPilot?
GitHub CoPilot is a coding specific implementation of the powerful ChatGPT series that kicked off in late 2022. As a long time GitHub user, I got invited to join in the preview, and it's one of the few times I've seen a product actually match its hype.
GitHub CoPilot is actually comprised of two separate components:
- The in-line code suggester called CoPilot
- Chat based help system called GitHub CoPilot Chat
Why is GitHub CoPilot and GitHub CoPilot Chat So Useful?
Since the day I first used it, I've found CoPilot incredibly useful. In particular, I love the way it contextualizes its suggestions and help functions to match:
- The context of my code
- The style of my coding
CoPilot Chat takes this to the next level by allowing me to ask questions about things I might be researching from a code perspective. It's amazing to watch the chat deliver answers to the question, then say "based on your code, here's how you could implement this". Even when it gets the answers wrong, the suggestions often help me solve whatever it is that I'm doing.
Finally, CoPilot is significantly more accurate than the standard ChatGPT prompt. I don't know why that is, however, it is definitely true!
How can I add GitHub CoPilot and GitHub CoPilot Chat to my Dev Environment?
The cool thing about CoPilot and CoPilot Chat is that they're incredibly easy to add to the dev environment we've created. At the time of writing, they're also offered as a free 30 day trial for personal use.
Here's what you need to do:
- Head to this link, have a read, and sign up.
- Go to your GitHub Codespaces environment, navigate to the extensions, and search for the GitHub Copilot extension
- Add the Copilot extension (and Copilot chat if you'd like it)
Thats it. All done.
A Few Other Fun and Useful VS Code Extensions that will Level Up your Dev Environment
I'll finish up the episode by giving you a list of helpful tools you can add to your VS Code environment that may help you develop faster or better. Keep in mind that this dev environment is yours, so there's no need to follow my list. These are just tools that I use every day.
- CoPilot Theme - I just like that color scheme
- Docker- helps me format Dockerfiles
- autopep8- helps me keep my code well formatted
- Resource Monitor - shows me what resources my IDE is consuming
Drop a note in the comments if you've got other fav's!
Congratulations on building your very own dev environment! You've got everything we need to start building trading bots, so check out the rest of my blog to see what awesome functionality you can add next!
About Me and About Us
TradeOxy is a trading assistance website I've cofounded with Mitsi, and we're on a mission to democratize algorithmic trading. Sign up today if that mission resonates with you!