3 changed files with 29 additions and 1 deletions
@ -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…
Reference in new issue