diff --git a/stock_market_cli.py b/stock_market_cli.py index 1b3ac59aec7..344f3728b57 100644 --- a/stock_market_cli.py +++ b/stock_market_cli.py @@ -113,7 +113,7 @@ def main(): main_parser = argparse.ArgumentParser(prog='stock_market_bot', add_help=False) # Add list of arguments that the main parser accepts - main_parser.add_argument('cmd', choices=['quit', 'help', 'gainers' ,'view', 'load', 'clear', + main_parser.add_argument('cmd', choices=['quit', 'help', 'gainers', 'sectors', 'view', 'load', 'clear', 'sma', 'ema', 'macd', 'vwap', 'stoch', 'rsi', 'adx', 'cci', 'aroon', 'bbands', 'ad', 'obv', 'ratings']) @@ -143,6 +143,11 @@ def main(): smm.gainers(l_args) continue + # --------------------------------------------------- GAINERS -------------------------------------------------- + if ns_known_args.cmd == 'sectors': + smm.sectors(l_args) + continue + # --------------------------------------------------- CLEAR ---------------------------------------------------- elif ns_known_args.cmd == 'clear': print("Clearing stock ticker to be used for analysis") diff --git a/stock_market_helper_funcs.py b/stock_market_helper_funcs.py index c1c4c2b3d91..656a93e6ca4 100644 --- a/stock_market_helper_funcs.py +++ b/stock_market_helper_funcs.py @@ -126,3 +126,15 @@ def b_is_stock_market_open(): # Otherwise, Stock Market is open! return True + +# ----------------------------------------------------------------------------------------------------------------------- +def long_number_format(s_num): + if s_num.lstrip("-").isdigit(): + n_num = int(s_num) + magnitude = 0 + while abs(n_num) >= 1000: + magnitude += 1 + n_num /= 1000.0 + # add more suffixes if you need them + return '%.2f%s' % (n_num, ['', ' K', ' M', ' G', ' T', ' P'][magnitude]) + return s_num \ No newline at end of file diff --git a/stock_market_menu.py b/stock_market_menu.py index 36f61ad085d..2c6636958ef 100644 --- a/stock_market_menu.py +++ b/stock_market_menu.py @@ -1,10 +1,33 @@ import argparse +from alpha_vantage.sectorperformance import SectorPerformances from alpha_vantage.timeseries import TimeSeries import re import config_bot as cfg import pandas as pd from stock_market_helper_funcs import * +# ---------------------------------------------------- SECTORS ---------------------------------------------------- +def sectors(l_args): + parser = argparse.ArgumentParser(prog='sectors', description='Plot sectors performance') + + try: + (ns_parser, l_unknown_args) = parser.parse_known_args(l_args) + except SystemExit: + print("") + return + + if l_unknown_args: + print(f"The following args couldn't be interpreted: {l_unknown_args}") + + sp = SectorPerformances(key=cfg.API_KEY_ALPHAVANTAGE, output_format='pandas') + df_sectors, d_meta_data = sp.get_sector() + df_sectorsf['Rank A: Real-Time Performance'].plot(kind='bar') + plt.title('Real Time Performance (%) per Sector') + plt.tight_layout() + plt.grid() + plt.show() + print("") + # ---------------------------------------------------- GAINERS ---------------------------------------------------- def gainers(l_args):