-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathreport.py
More file actions
32 lines (22 loc) · 969 Bytes
/
report.py
File metadata and controls
32 lines (22 loc) · 969 Bytes
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
"""CSV reporting utilities for StockBot trade plans."""
from __future__ import annotations
import csv
from pathlib import Path
from typing import Sequence, Tuple
from config import REPORT_CSV_PATH
TradeRow = Tuple[str, float, float]
def write_csv(
sell_plan: Sequence[TradeRow],
buy_plan: Sequence[TradeRow],
path: Path = REPORT_CSV_PATH,
) -> None:
"""Persist the provided trade plan to ``path`` in CSV format."""
with Path(path).open("w", newline="", encoding="utf-8") as handle:
writer = csv.writer(handle)
writer.writerow(["Action", "Ticker", "Quantity", "Price", "Allocated Amount (€)"])
for ticker, quantity, price in sell_plan:
allocated = quantity * price
writer.writerow(["SELL", ticker, quantity, price, allocated])
for ticker, quantity, price in buy_plan:
allocated = quantity * price
writer.writerow(["BUY", ticker, quantity, price, allocated])