mirror of
https://github.com/OpenBB-finance/OpenBB.git
synced 2026-10-28 13:01:38 +00:00
Add messages from stocktwits in sentiment menu
This commit is contained in:
@@ -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!")
|
||||
@@ -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("")
|
||||
|
||||
|
||||
@@ -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")
|
||||
|
||||
Reference in New Issue
Block a user