In today’s blog, we will learn about two important principles of Python’s OOPs (Object-Oriented Programming) – Polymorphism and Abstraction – which are essential for building any modern algorithmic trading bot. Also, we will implement a real crypto trading strategy using Freqtrade that enables you to trade in the global market from any country like USA or Singapore.
Polymorphism – Same name, many forms
Method Overriding:
This is the process in which a child class overrides the method of its parent class. For example, if the parent class has a method called execute() and the child class also defines a method called execute(), then the child class’s version will run. This is Method Overriding.
This flexibility is useful in algorithmic trading when we have to create a new customized trading strategy inherited from the base strategy.
Method Overloading:
In languages like Java or C++, multiple methods can be created with the same name with different parameters. This is not directly possible in Python as it does not support concept method signatures.
But in Python, we can achieve this functionality with the help of default arguments or variable-length arguments. For example, we can create an area() method that returns the area of a circle when given one argument and the area of a rectangle when given two arguments.
Operator Overloading:
In Python, you can redefine predefined operators like +, -, *, etc. as per your class objects. For example, you can use the __add__() magic method to combine two strategies.
Abstraction – Show only necessary information

Abstraction means that you give the user only the information he needs and hide the rest of the complexity. For example, the user interface of a trading bot only shows the start(), stop() or status() functions but the backend has a lot of complex logic running. This practice helps you to create clean and scalable code.
Data Privacy and Getter-Setter Method in Python
Python is made for adults
In Python, unlike Java or C++, nothing is completely private. So even if an attribute is declared private, it can still be accessed. But this flexibility can also be seen as an advantage.
The designers of Python believe that developers are mature and should not be given unnecessary restrictions. Therefore, if a developer accesses a private variable, it is their responsibility, not Python’s.
Use of Getter and Setter Methods
We use getter and setter methods when we need to access and modify private data safely.
Getter Method:
This method allows us to safely access the value of a private variable. Suppose you have declared __threshold as private, then you can access it through getter method like this:
def get_threshold(self):
return self.__threshold
Setter Method:
This method is used to safely modify the value of private variable:
def set_threshold(self, new_threshold):
self.__threshold = new_threshold
Why is Getter-Setter necessary?
Suppose a developer accidentally changes threshold to a string, then it can cause error in calculation. Getter and Setter methods can handle that situation because you can add validation logic to it.
Hands-On Project – Freqtrade Strategy Implementation
Freqtrade is an open-source crypto trading bot developed in Python. It is used by quantitative traders to implement their strategies.
In this session you will:
- Create your own class
- Declare private attributes
- Manage them with a Getter-Setter method
- Define a trading strategy
- Integrate it into Freqtrade to create a functional bot
This hands-on project will give you a real-world experience of using your Python skills in trading automation.
- Importance of Python and OOP in Crypto Trading
Abstraction allows you to keep your trading logic secure - Polymorphism allows you to make strategies modular and dynamic
- Encapsulation allows you to control and validate data
- Integration with Freqtrade gives you instant entry to global markets
- Whether you are in the USA or Singapore, this knowledge is globally relevant to you.
Watch this Day 12 video tutorial
Day 12: Object-Oriented Programming Part – 4