diff options
author | uvok | 2025-04-16 20:10:12 +0200 |
---|---|---|
committer | uvok | 2025-04-16 20:10:12 +0200 |
commit | bca911192e77120daf74903d51fcd03eaaa3f4a0 (patch) | |
tree | b5d0b84ae7af29263fe6fc62730de0bd39133726 /kraken.py | |
parent | 1dc68f9c6aa2a84fa1eccb9255310eeeca53c812 (diff) |
Separate ledger read functions
Diffstat (limited to 'kraken.py')
-rw-r--r-- | kraken.py | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/kraken.py b/kraken.py new file mode 100644 index 0000000..c420d89 --- /dev/null +++ b/kraken.py @@ -0,0 +1,22 @@ +import csv +from decimal import Decimal +from typing import List +from ledger_action import LedgerAction + + +def parse_row(row: dict[str,str]) -> LedgerAction: + date = row["time"].split(" ")[0] + return LedgerAction( + type=row["type"], + asset=row["asset"], + amount=Decimal(row["amount"]), + fee=Decimal(row.get("fee", "0")), + refid=row.get("refid", ""), + date=date, + ) + + +def read_ledger(csv_path: str) -> List[LedgerAction]: + with open(csv_path, "r") as file: + reader = csv.DictReader(file) + return list(map(parse_row, reader)) |