Browse Source

feat: base app

pull/14/head
QuentinN42 11 months ago
parent
commit
cde3d7888e
Signed by: number42 GPG Key ID: 2CD7D563712B3A50
  1. 3
      auto_trading/__init__.py
  2. 52
      auto_trading/interfaces.py
  3. 30
      auto_trading/main.py

3
auto_trading/__init__.py

@ -0,0 +1,3 @@
"""
Auto trading python bot.
"""

52
auto_trading/interfaces.py

@ -0,0 +1,52 @@
"""
Define basic interfaces for trading strategies.
"""
from abc import ABC, abstractmethod
class Portfolio(ABC):
"""How may of each money do I have ?"""
@abstractmethod
def content(self) -> dict:
"""return the content in each currency"""
@abstractmethod
def widraw(self, amount: int, currency: str) -> None:
"""Withdraw money from the portfolio"""
@abstractmethod
def deposit(self, amount: int, currency: str) -> None:
"""Deposit money into the portfolio"""
@abstractmethod
def convert(self, amount: int, currency: str, to_currency: str) -> None:
"""Convert money from one currency to another"""
class Strategy(ABC):
"""When do I buy and how many ?"""
@abstractmethod
def run(self, result: dict, ptf: Portfolio) -> None:
"""Run the strategy"""
class Broker(ABC):
"""Return the data"""
@abstractmethod
def __bool__(self):
"""Return True if the broker has data to retrive"""
@abstractmethod
def next(self):
"""Return the next data to process"""
class Predictor(ABC):
"""What is the future ?"""
@abstractmethod
def predict(self, data: dict) -> dict:
"""Return the prediction"""

30
auto_trading/main.py

@ -0,0 +1,30 @@
"""
One script to rule them all, One script to find them,
One script to bring them all and in the darkness bind them
"""
from .interfaces import Portfolio, Strategy, Broker, Predictor
class Bot:
"""the main class"""
def __init__(self, ptf: Portfolio, strategy: Strategy, broker: Broker, predictor: Predictor):
"""initialize the bot"""
self.ptf = ptf
self.strategy = strategy
self.broker = broker
self.predictor = predictor
def run(self):
"""run the bot"""
while self.broker:
self.run_once()
def run_once(self):
"""run the bot once"""
self.strategy.run(self.predictor.predict(self.broker.next()), self.ptf)
def print_results(self):
"""print the results"""
for k,v in self.ptf.content().items():
print(f"{k}: {v}")
Loading…
Cancel
Save