Files
OpenBB/openbb_terminal/common/behavioural_analysis/stocktwits_view.py
jose-donato 40cfe8148d Interactive tables using react (#4386)
* feat: experimenting tables with react

* feat: adding new interactive tables

* feat: adding more table features

* small changes

* update

* Update backend.py

* Update backend.py

* fix: dark mode?

* feat: lot of table improvements

* fix: my b

* fix: load only when prod

* feat: naive detect links and dates

* handle index and column names

* increased min width

* codespell

* mypy, pylint

* fix: added new chart, export, etc

* testing

* updates

* fix : add PLOT_OPEN_EXPORT,  USE_INTERACTIVE_DF to user dataclass

* bump pywry version, readd removed `plots_backend().start()`

* req files

* Update unit-test.yml

* Update unit-test.yml

* Update unit-test.yml

* updates

* fixing some date things

* update table

* fix formatting with timezones

* fixing some long prints and tables

* Mickey Mouse

Co-authored-by: teh_coderer <tehcoderer@users.noreply.github.com>
Co-authored-by: jose-donato <jose-donato@users.noreply.github.com>

* fix: ?!?!?

* adding limit arg to all print_rich_table

* tests

* lint

* simple by Default on interactive charts

* playing with some css (thks jose)

* Fix #4426

* Edit some structure

* fix sdk generation

* Update backend.py

* fa menu tested and working

* fix #4460

* fix #4460 drop indices

* update tests

* update tests

* Update helper_funcs.py

* tests

* Update unit-test.yml

* Update etf.ipynb

---------

Co-authored-by: teh_coderer <me@tehcoderer.com>
Co-authored-by: andrewkenreich <andrew.kenreich@gmail.com>
Co-authored-by: teh_coderer <tehcoderer@users.noreply.github.com>
Co-authored-by: jose-donato <jose-donato@users.noreply.github.com>
Co-authored-by: James Maslek <jmaslek11@gmail.com>
2023-03-13 17:50:48 +00:00

102 lines
2.8 KiB
Python

"""Stocktwits View"""
__docformat__ = "numpy"
import logging
import pandas as pd
from openbb_terminal.common.behavioural_analysis import stocktwits_model
from openbb_terminal.decorators import log_start_end
from openbb_terminal.helper_funcs import print_rich_table
from openbb_terminal.rich_config import console
logger = logging.getLogger(__name__)
@log_start_end(log=logger)
def display_bullbear(symbol: str):
"""
Print bullbear sentiment based on last 30 messages on the board.
Also prints the watchlist_count. [Source: Stocktwits]
Parameters
----------
symbol: str
Stock ticker symbol
"""
watchlist_count, n_cases, n_bull, n_bear = stocktwits_model.get_bullbear(symbol)
console.print(f"[yellow]Watchlist count[/yellow]: {watchlist_count}")
if n_cases > 0:
console.print(f"\nLast {n_cases} sentiment messages:")
console.print(f"[green]Bullish:[/green] {round(100*n_bull/n_cases, 2)}%")
console.print(f"[red]Bearish:[/red] {round(100*n_bear/n_cases, 2)}%")
else:
console.print("No messages found")
@log_start_end(log=logger)
def display_messages(symbol: str, limit: int = 30):
"""Prints up to 30 of the last messages on the board. [Source: Stocktwits].
Parameters
----------
symbol: str
Stock ticker symbol
limit: int
Number of messages to get
"""
messages = stocktwits_model.get_messages(symbol, limit)
if not messages.empty:
print_rich_table(
messages,
headers=["MESSAGES"],
show_index=False,
title="Last Messages on Board",
)
else:
console.print("No messages found in Stocktwits stream")
@log_start_end(log=logger)
def display_trending():
"""Show trensing stocks on stocktwits."""
df_trending = stocktwits_model.get_trending()
print_rich_table(
df_trending,
headers=list(df_trending.columns),
show_index=False,
title="Trending Stocks",
)
@log_start_end(log=logger)
def display_stalker(user: str, limit: int = 10):
"""Show last posts for given user.
Parameters
----------
user : str
Stocktwits username
limit : int, optional
Number of messages to show, by default 10
"""
messages = stocktwits_model.get_stalker(user, limit)
df_messages = pd.DataFrame.from_dict(messages)
df_messages["created_at"] = pd.to_datetime(df_messages["created_at"])
df_messages = pd.DataFrame(df_messages, columns=["created_at", "id", "body", "url"])
# We look for a date name in the column to assume its a date on frontend side for filtering etc
df_messages.rename(columns={"created_at": "created_at_date"}, inplace=True)
df_messages = df_messages.drop(["id", "url"], axis=1)
print_rich_table(
df_messages,
show_index=False,
limit=limit,
)