diff --git a/sentiment/sen_menu.py b/sentiment/sen_menu.py index 58072e135bf..f63216ff844 100644 --- a/sentiment/sen_menu.py +++ b/sentiment/sen_menu.py @@ -21,6 +21,7 @@ def print_sentiment(): print("") print("Stocktwits:") print(" sentiment estimate quick sentiment from last 30 messages on board") + print(" messages output up to the 30 last messages on the board") print("") return @@ -33,7 +34,7 @@ def sen_menu(s_ticker): sen_parser = argparse.ArgumentParser(prog='discovery', add_help=False) sen_parser.add_argument('cmd', choices=['help', 'q', 'quit', 'watchlist', 'spac', 'spac_c', 'wsb', 'popular', - 'sentiment']) + 'sentiment', 'messages']) print_sentiment() @@ -81,6 +82,9 @@ def sen_menu(s_ticker): elif ns_known_args.cmd == 'sentiment': stocktwits_api.sentiment(l_args, s_ticker) + elif ns_known_args.cmd == 'messages': + stocktwits_api.messages(l_args, s_ticker) + # ------------------------------------------------------------------------------------------------------------ else: print("Command not recognized!") \ No newline at end of file diff --git a/sentiment/stocktwits_api.py b/sentiment/stocktwits_api.py index 4a96d21e16f..94b5b9b741b 100644 --- a/sentiment/stocktwits_api.py +++ b/sentiment/stocktwits_api.py @@ -1,6 +1,7 @@ import argparse import requests import pandas as pd +from stock_market_helper_funcs import * # ------------------------------------------------------------------------------------------------------------------- def sentiment(l_args, s_ticker): @@ -41,3 +42,34 @@ def sentiment(l_args, s_ticker): except: print("") + +# ------------------------------------------------------------------------------------------------------------------- +def messages(l_args, s_ticker): + parser = argparse.ArgumentParser(prog='messages', + description="""Gather last 30 messages on the board [stocktwits] """) + + parser.add_argument('-t', "--ticker", action="store", dest="s_ticker", type=str, default=s_ticker, help='Ticker to get board messages') + parser.add_argument('-l', "--limit", action="store", dest="n_lim", type=check_positive, default=30, help='Limit messages shown') + + try: + (ns_parser, l_unknown_args) = parser.parse_known_args(l_args) + + if l_unknown_args: + print(f"The following args couldn't be interpreted: {l_unknown_args}\n") + return + + result = requests.get(f"https://api.stocktwits.com/api/2/streams/symbol/{ns_parser.s_ticker}.json") + if result.status_code == 200: + for idx, message in enumerate(result.json()['messages']): + print("------------------------------------------------------------------------------------------") + print(message['body']) + if idx > ns_parser.n_lim-1: + break + else: + print("Invalid symbol") + + print("") + + except: + print("") + diff --git a/stock_market_cli.py b/stock_market_cli.py index c58643e3002..913942636f3 100644 --- a/stock_market_cli.py +++ b/stock_market_cli.py @@ -300,7 +300,7 @@ def main(): # SENTIMENT MARKET elif ns_known_args.opt == 'sen': - b_quit = sm.sen_menu() + b_quit = sm.sen_menu(s_ticker) if b_quit: print("Hope you made money today. Good bye my lover, good bye my friend.\n")