38 lines
986 B
Python
38 lines
986 B
Python
from tabulate import tabulate
|
|
from decimal import Decimal
|
|
import yfi as y
|
|
|
|
|
|
def generate_table(stonks):
|
|
table_data = []
|
|
total = 0
|
|
for ticker in stonks.keys():
|
|
price = y.get_current_price(ticker)
|
|
shares_count = stonks[ticker]
|
|
table_data.append(
|
|
[ticker, shares_count, round(Decimal(price) * Decimal(stonks[ticker]), 2)]
|
|
)
|
|
total += Decimal(price) * Decimal(stonks[ticker])
|
|
|
|
table_data.append(["Total", "", round(total, 2)])
|
|
|
|
return str(
|
|
tabulate(table_data, ["Ticker", "Shares", "Value ($)"], tablefmt="pretty")
|
|
)
|
|
|
|
|
|
def watchlist_table(watchlist):
|
|
|
|
table_data = []
|
|
header = ["Ticker", "Current Price ($)", "Estimated Price ($)"]
|
|
|
|
for stonk in watchlist.keys():
|
|
table_data.append(
|
|
[
|
|
stonk,
|
|
y.get_current_price(stonk),
|
|
watchlist[stonk],
|
|
]
|
|
)
|
|
|
|
return str(tabulate(table_data, header, tablefmt="pretty"))
|