-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtransaction.py
54 lines (45 loc) · 1.36 KB
/
transaction.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
from enum import Enum
from datetime import datetime
class Currency(Enum):
EUR = 'EUR'
USD = 'USD'
GBP = 'GBP'
class Money:
def __init__(self, amount: float, currency: Currency) -> None:
self.amount = amount
self.currency = currency
def __repr__(self) -> str:
return "{amount:.2f} {currency}".format(
amount=self.amount,
currency=self.currency.name,
)
class Direction(Enum):
BUY = 'BUY'
SELL = 'SELL'
class Transaction:
def __init__(
self,
date: int, # unixtime for transaction date
index: str, # index
amount: int, # amount
price: Money, # transaction amount
direction: Direction # buy/sell
) -> None:
self.date = date
self.index = index
self.amount = amount
self.price = price
self.direction = direction
def __repr__(self) -> str:
return "[{dt}] {direction} {amount} {index} @ {price}".format(
dt=datetime.utcfromtimestamp(self.date).strftime('%Y-%m-%d'),
direction=self.direction.name,
amount=self.amount,
index=self.index,
price=self.price,
)
class Portfolio:
def __init__(self):
pass
def add_transactions(transaction: Transaction) -> None:
pass