mirror of
https://github.com/OpenBB-finance/OpenBB.git
synced 2026-10-27 12:40:35 +00:00
Add trending stocks from stocktwits
This commit is contained in:
@@ -22,6 +22,7 @@ def print_sentiment():
|
||||
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(" trending trending stocks")
|
||||
print("")
|
||||
|
||||
return
|
||||
@@ -34,7 +35,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', 'messages'])
|
||||
'sentiment', 'messages', 'trending'])
|
||||
|
||||
print_sentiment()
|
||||
|
||||
@@ -85,6 +86,9 @@ def sen_menu(s_ticker):
|
||||
elif ns_known_args.cmd == 'messages':
|
||||
stocktwits_api.messages(l_args, s_ticker)
|
||||
|
||||
elif ns_known_args.cmd == 'trending':
|
||||
stocktwits_api.trending(l_args)
|
||||
|
||||
# ------------------------------------------------------------------------------------------------------------
|
||||
else:
|
||||
print("Command not recognized!")
|
||||
@@ -29,14 +29,12 @@ def sentiment(l_args, s_ticker):
|
||||
n_cases += 1
|
||||
n_bull += (message['entities']['sentiment']['basic'] == 'Bullish')
|
||||
n_bear += (message['entities']['sentiment']['basic'] == 'Bearish')
|
||||
|
||||
if n_cases > 0:
|
||||
print(f"\nOver {n_cases} sentiment messages:")
|
||||
print(f"Bullish {round(100*n_bull/n_cases, 2)}%")
|
||||
print(f"Bearish {round(100*n_bear/n_cases, 2)}%")
|
||||
else:
|
||||
print("Invalid symbol")
|
||||
|
||||
print("")
|
||||
|
||||
except:
|
||||
@@ -73,3 +71,33 @@ def messages(l_args, s_ticker):
|
||||
except:
|
||||
print("")
|
||||
|
||||
|
||||
# -------------------------------------------------------------------------------------------------------------------
|
||||
def trending(l_args):
|
||||
parser = argparse.ArgumentParser(prog='trending',
|
||||
description="""Stocks trending [stocktwits] """)
|
||||
|
||||
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/trending/symbols.json")
|
||||
if result.status_code == 200:
|
||||
l_symbols = list()
|
||||
for symbol in result.json()['symbols']:
|
||||
l_symbols.append([symbol['symbol'], symbol['watchlist_count'], symbol['title']])
|
||||
|
||||
pd.set_option('display.max_colwidth', -1)
|
||||
df_trending = pd.DataFrame(l_symbols, columns=['Ticker', 'Watchlist Count', 'Name'])
|
||||
print(df_trending.to_string(index=False))
|
||||
else:
|
||||
print("Error!")
|
||||
print("")
|
||||
|
||||
except:
|
||||
print("")
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user