Merge pull request #162 from DidierRLopes/some-fixes

Couple of fixes here and there
This commit is contained in:
DidierRLopes
2021-03-12 22:02:44 +00:00
committed by GitHub
7 changed files with 29 additions and 15 deletions

View File

@@ -167,11 +167,12 @@ These are the ones where a key is necessary:
* Quandl: https://www.quandl.com/tools/api
* Reddit: https://www.reddit.com/prefs/apps
* Twitter: https://developer.twitter.com
* Polygon: # https://polygon.io
* Financial Modeling Prep: https://financialmodelingprep.com/developer
When these are obtained, don't forget to update [config_terminal.py](/gamestonk_terminal/config_terminal.py).
Alternatively, you can also set them to the following environment variables: GT_API_KEY_ALPHAVANTAGE, GT_API_KEY_FINANCIALMODELINGPREP, GT_API_KEY_QUANDL, GT_API_REDDIT_CLIENT_ID, GT_API_REDDIT_CLIENT_SECRET, GT_API_REDDIT_USERNAME, GT_API_REDDIT_USER_AGENT, GT_API_REDDIT_PASSWORD, GT_API_TWITTER_KEY, GT_API_TWITTER_SECRET_KEY, GT_API_TWITTER_BEARER_TOKEN.
Alternatively, you can also set them to the following environment variables: GT_API_KEY_ALPHAVANTAGE, GT_API_KEY_FINANCIALMODELINGPREP, GT_API_KEY_QUANDL, GT_API_REDDIT_CLIENT_ID, GT_API_REDDIT_CLIENT_SECRET, GT_API_REDDIT_USERNAME, GT_API_REDDIT_USER_AGENT, GT_API_REDDIT_PASSWORD, GT_API_TWITTER_KEY, GT_API_TWITTER_SECRET_KEY, GT_API_TWITTER_BEARER_TOKEN, GT_API_POLYGON_KEY.
Example:
```

View File

@@ -10,13 +10,16 @@ from gamestonk_terminal.comparison_analysis import yahoo_finance_api as yf_api
def get_similar_companies(l_args, s_ticker):
""" Get similar companies. [Source: Polygon API] """
parser = argparse.ArgumentParser(
add_help=False,
prog="get",
description="""Get similar companies to compare with.""",
)
l_similar = []
try:
parse_known_args_and_warn(parser, l_args)
ns_parser = parse_known_args_and_warn(parser, l_args)
if not ns_parser:
return
result = requests.get(
f"https://api.polygon.io/v1/meta/symbols/{s_ticker}/company?&apiKey={cfg.API_POLYGON_KEY}"
@@ -35,6 +38,7 @@ def get_similar_companies(l_args, s_ticker):
def select_similar_companies(l_args):
""" Select similar companies, e.g. NIO,XPEV,LI"""
parser = argparse.ArgumentParser(
add_help=False,
prog="select",
description="""Select similar companies to compare with.""",
)
@@ -54,6 +58,9 @@ def select_similar_companies(l_args):
l_args.insert(0, "-s")
ns_parser = parse_known_args_and_warn(parser, l_args)
if not ns_parser:
return
print("")
return ns_parser.l_similar

View File

@@ -34,6 +34,7 @@ def check_one_of_ohlca(type_candles: str) -> str:
def historical(l_args, df_stock, s_ticker, s_start, s_interval, similar):
parser = argparse.ArgumentParser(
add_help=False,
prog="historical",
description="""Historical price comparison between similar companies [Source: Yahoo Finance]
""",
@@ -70,6 +71,8 @@ def historical(l_args, df_stock, s_ticker, s_start, s_interval, similar):
# Alpha Vantage only supports 5 calls per minute, we need another API to get intraday data
else:
ns_parser = parse_known_args_and_warn(parser, l_args)
if not ns_parser:
return
if ns_parser.l_similar:
similar = ns_parser.l_similar
@@ -112,6 +115,7 @@ def historical(l_args, df_stock, s_ticker, s_start, s_interval, similar):
def correlation(l_args, df_stock, s_ticker, s_start, s_interval, similar):
parser = argparse.ArgumentParser(
add_help=False,
prog="corr",
description=""" Correlation heatmap based on historical price comparison between similar
companies. [Source: Yahoo Finance]
@@ -149,6 +153,8 @@ def correlation(l_args, df_stock, s_ticker, s_start, s_interval, similar):
# Alpha Vantage only supports 5 calls per minute, we need another API to get intraday data
else:
ns_parser = parse_known_args_and_warn(parser, l_args)
if not ns_parser:
return
if ns_parser.l_similar:
similar = ns_parser.l_similar

View File

@@ -63,6 +63,7 @@ def income(l_args, s_ticker):
def balance(l_args, s_ticker):
parser = argparse.ArgumentParser(
add_help=False,
prog="balance",
description="""
Prints either yearly or quarterly assets from balance sheet of the company.
@@ -130,6 +131,7 @@ def balance(l_args, s_ticker):
def cash(l_args, s_ticker):
parser = argparse.ArgumentParser(
add_help=False,
prog="cash_flow",
description="""
Prints either yearly or quarterly cash flow operating activities of the company.

View File

@@ -300,10 +300,14 @@ def price_prediction_color(val: int, last_val: int) -> str:
def print_pretty_prediction(df_pred: pd.DataFrame, last_price: float):
print(f"Actual price: {Fore.YELLOW}{last_price:.2f} ${Style.RESET_ALL}\n")
print("Prediction:")
print(df_pred.apply(price_prediction_color, last_val=last_price).to_string())
if gtff.USE_COLOR:
print(f"Actual price: {Fore.YELLOW}{last_price:.2f} ${Style.RESET_ALL}\n")
print("Prediction:")
print(df_pred.apply(price_prediction_color, last_val=last_price).to_string())
else:
print(f"Actual price: {last_price:.2f} $\n")
print("Prediction:")
print(df_pred.to_string())
def check_ohlc(type_ohlc: str) -> str:

View File

@@ -7,7 +7,6 @@ from gamestonk_terminal.sentiment import google_api, reddit_api, stocktwits_api
from prompt_toolkit.completion import NestedCompleter
# -----------------------------------------------------------------------------------------------------------------------
def print_sentiment():
""" Print help """
@@ -45,7 +44,6 @@ def print_sentiment():
return
# ---------------------------------------------------- MENU ----------------------------------------------------
def sen_menu(s_ticker, s_start):
# Add list of arguments that the discovery parser accepts
@@ -105,7 +103,6 @@ def sen_menu(s_ticker, s_start):
# Abandon the program
return True
# ---------------------------------------------------- REDDIT ---------------------------------------------------
elif ns_known_args.cmd == "watchlist":
reddit_api.watchlist(l_args)
@@ -121,7 +118,6 @@ def sen_menu(s_ticker, s_start):
elif ns_known_args.cmd == "popular":
reddit_api.popular_tickers(l_args)
# ---------------------------------------------------- STOCKTWITS -----------------------------------------------
elif ns_known_args.cmd == "bullbear":
stocktwits_api.bullbear(l_args, s_ticker)
@@ -134,10 +130,9 @@ def sen_menu(s_ticker, s_start):
elif ns_known_args.cmd == "stalker":
stocktwits_api.stalker(l_args)
# ----------------------------------------------------- TWITTER -------------------------------------------------
elif ns_known_args.cmd == "infer":
if not gtff.ENABLE_PREDICT:
print("Predict is not enabled in config_terminal.py")
print("Predict is not enabled in feature_flags.py")
print("Twitter inference menu is disabled")
print("")
continue
@@ -181,7 +176,6 @@ def sen_menu(s_ticker, s_start):
twitter_api.sentiment(l_args, s_ticker)
# ----------------------------------------------------- GOOGLE ---------------------------------------------------
elif ns_known_args.cmd == "mentions":
google_api.mentions(l_args, s_ticker, s_start)
@@ -194,6 +188,5 @@ def sen_menu(s_ticker, s_start):
elif ns_known_args.cmd == "rise":
google_api.rise(l_args, s_ticker)
# ------------------------------------------------------------------------------------------------------------
else:
print("Command not recognized!")

View File

@@ -62,6 +62,7 @@ def main():
"ta",
"dd",
"pred",
"ca",
]
menu_parser.add_argument("opt", choices=choices)
completer = NestedCompleter.from_nested_dict({c: None for c in choices})
@@ -150,7 +151,7 @@ def main():
elif ns_known_args.opt == "pred":
if not gtff.ENABLE_PREDICT:
print("Predict is not enabled in config_terminal.py")
print("Predict is not enabled in feature_flags.py")
print("Prediction menu is disabled")
print("")
continue