Files
OpenBB/bots/stocks/dark_pool_shorts/shorted.py
Colin Delahunty fae93c67ad Refactor Bot (#1326)
* First commit

* Renamed to bot

* change from discordbot to bots imports

* refractor cmds

+ autocomplete helpers
+ updated dps plots/candle
+ quote cmd

* isort fix

* Update helpers.py

* Added first refactor

* Added commands and refactor

* Added description handler

* Through grains

* ta + image border helper

* Added indices

* merged

* Finished econ

* options refactor

* dark_pool_shorts, candle, quote done

* pagination/dropdown logic to helpers + fixes

* dd/disc/insider done + add image logic to helpers

* linting

* removed plt style

* Almost done with Gov

* fixing conflicts

* Finished gov (excpect ones mentioned)

* screener done

* Test bug refactor

* Store changes to switch

* Finished refactor

* Fixed error

* Delete ::40

* Fixed issue

* Fixed black

* finished

* fixes

Co-authored-by: teh_coderer <me@tehcoderer.com>
Co-authored-by: didierlopes.eth <dro.lopes@campus.fct.unl.pt>
2022-02-20 10:36:59 -05:00

82 lines
2.2 KiB
Python

import disnake
import bots.config_discordbot as cfg
from bots.config_discordbot import logger
from bots.menus.menu import Menu
from gamestonk_terminal.stocks.dark_pool_shorts import yahoofinance_model
def shorted_command(num: int = 10):
"""Show most shorted stocks [Yahoo Finance]"""
# Debug user input
if cfg.DEBUG:
logger.debug("dps-shorted %s", num)
# Check for argument
if num < 0:
raise Exception("Number has to be above 0")
# Retrieve data
df = yahoofinance_model.get_most_shorted().head(num)
# Debug user output
if cfg.DEBUG:
logger.debug(df.to_string())
# Output data
title = "Stocks: [Yahoo Finance] Most Shorted"
df.dropna(how="all", axis=1, inplace=True)
df = df.replace(float("NaN"), "")
future_column_name = df["Symbol"]
df = df.transpose()
df.columns = future_column_name
df.drop("Symbol")
embeds = []
choices = [
disnake.SelectOption(label="Overview", value="0", emoji="🟢"),
]
initial_str = "Overview"
i = 1
for col_name in df.columns.values:
menu = f"\nPage {i}: {col_name}"
initial_str += f"\nPage {i}: {col_name}"
if i < 19:
choices.append(
disnake.SelectOption(label=menu, value=f"{i}", emoji="🟢"),
)
if i == 20:
choices.append(
disnake.SelectOption(label="Max Reached", value=f"{i}", emoji="🟢"),
)
i += 1
reports = [f"{initial_str}"]
embeds.append(
disnake.Embed(
title=title,
description=initial_str,
colour=cfg.COLOR,
).set_author(
name=cfg.AUTHOR_NAME,
icon_url=cfg.AUTHOR_ICON_URL,
)
)
for column in df.columns.values:
description = "```" + df[column].fillna("").to_string() + "```"
embeds.append(
disnake.Embed(description=description, colour=cfg.COLOR,).set_author(
name=cfg.AUTHOR_NAME,
icon_url=cfg.AUTHOR_ICON_URL,
)
)
reports.append(f"{description}")
return {
"view": Menu,
"title": title,
"description": reports,
"embed": embeds,
"choices": choices,
}