Building a Customizable Trading Bot (Part 1)

Matheus Pessoa
2 min readAug 18, 2021

--

Using Python, Streamlit and a bit of Machine Learning

During my undergraduate thesis development, I realized the repository I used for testing trading strategies got a lot stars. So, why not transform that into an easy to customize web-app using streamlit?

On this first article I’ll discuss a little about the design choices I’ve made to ensure the bot would be easy to extend and maintain. First off we need to outline the basic responsibilities of each part of the system, and for that we need to determine what will the system actually do.

The system should connect to an exchange, fetch data for the desired asset, apply a trading strategy and make the buy or sell order based on that. With this in mind I’ve decided to implement this system using the Strategy and Bridge Design Patterns.

Which means the code will be split into 3 main classes, the Exchange, responsible for managing the connection and fetching data, the Strategy, which applies a trading strategy to that data and a Trading Bot which is responsible for making the orders and stopping if we lost or won too much.

And, for my first implementation of the Exchange interface class, I picked IQ Option which has a good (although unofficial) API.

So, Exchanges have a api method responsible for connecting to the exchange’s API, a balance method for checking the current account balance and a method to transform the asset candlestick data into a pandas Dataframe.

That covers the exchange implementation, next week I’ll explain the Strategy implementation. You can also check the full code at GitHub and give the web-app a try at Streamlit Share.

--

--

Matheus Pessoa

Rio de Janeiro Native | Software Engineer | Data Scientist