Browse Source

feat: in memory ptf

pull/14/head
QuentinN42 1 year ago
parent
commit
6afc4ce672
Signed by: number42 GPG Key ID: 2CD7D563712B3A50
  1. 2
      auto_trading/interfaces.py
  2. 0
      auto_trading/ptf/__init__.py
  3. 28
      auto_trading/ptf/in_memory.py

2
auto_trading/interfaces.py

@ -20,7 +20,7 @@ class Portfolio(ABC):
"""Deposit money into the portfolio"""
@abstractmethod
def convert(self, amount: int, currency: str, to_currency: str) -> None:
def convert(self, amount: int, to_amount: int, currency: str, to_currency: str) -> None:
"""Convert money from one currency to another"""

0
auto_trading/ptf/__init__.py

28
auto_trading/ptf/in_memory.py

@ -0,0 +1,28 @@
from ..interfaces import Portfolio
class InMemoryPortfolio(Portfolio):
"""Just store the value in memory."""
def __init__(self, currency: dict) -> None:
"""Define the ptf with some starting currency"""
self.currency = currency
def content(self) -> dict:
"""return the content in each currency"""
return self.currency
def widraw(self, amount: int, currency: str) -> None:
"""Withdraw money from the portfolio"""
if self.currency[currency] < amount:
raise ValueError("Not enough money")
self.currency[currency] -= amount
def deposit(self, amount: int, currency: str) -> None:
"""Deposit money into the portfolio"""
self.currency[currency] += amount
def convert(self, amount: int, to_amount: int, currency: str, to_currency: str) -> None:
"""Convert money from one currency to another"""
self.widraw(amount, currency)
self.deposit(to_amount, to_currency)
Loading…
Cancel
Save