stock-tracker-discord/table.py
socks 35fc806327 - Added delete command
- added watchlists
- added $pf2 and $wl2 to get image format table outputs
- moving yahoo finance commands to separate file
2021-02-14 18:57:18 +00:00

31 lines
919 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" ) )