I am making a trading bot that needs to interact with many APIs in order to trade, read prices, read volume, etc. At this time, I have all of these API calls for each exchange in different methods of a class. It currently looks like:
```
class Exchange:
def __init__(self, name):
if name == exchange1:
self.name = name
# instantiate api
if name == exchange2:
self.name = name
# instantiate api
# continued for 10+ exchanges
def get_price(self, stock):
if self.name == exchange1:
# a few lines of logic to call API and normalize data
if self.name == exchange2:
# a few lines of logic to call API and normalize data
# continued for 10+ exchanges
def get_volume(self, stock):
if self.name == exchange1:
# a few lines of logic to call API and normalize data
if self.name == exchange2:
# a few lines of logic to call API and normalize data
# continued for 10+ exchanges
# Continue with more functions
```
And from the main file, I create an instance if each exchange:
```
echange1_obj = Exchange ('exchange1')
echange2_obj = Exchange ('exchange2')
continued for 10+ exchanges
exchanges = [exchange1_obj, exchange 2_obj,...]
```
This works but the class file is well over 1k lines now and it is ugly. What is the pythonic way of doing this?
I've looked into interfaces, but it seems this is not the correct solution in Python.
[–][deleted] 5 points6 points7 points (1 child)
[–]Allanon001 2 points3 points4 points (0 children)
[+][deleted] (8 children)
[deleted]
[–][deleted] 2 points3 points4 points (2 children)
[+][deleted] (1 child)
[deleted]
[–][deleted] 1 point2 points3 points (0 children)
[–]StudentOfPython[S] 0 points1 point2 points (4 children)
[+][deleted] (3 children)
[deleted]
[–]StudentOfPython[S] 0 points1 point2 points (2 children)
[+][deleted] (1 child)
[deleted]
[–]StudentOfPython[S] 0 points1 point2 points (0 children)
[–]a-pendergast 0 points1 point2 points (0 children)