mirror of
https://github.com/OpenBB-finance/OpenBB.git
synced 2026-11-07 09:52:13 +00:00
* 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>
80 lines
2.4 KiB
Python
80 lines
2.4 KiB
Python
import disnake
|
|
import pandas as pd
|
|
|
|
import bots.config_discordbot as cfg
|
|
from bots.config_discordbot import logger
|
|
from bots.menus.menu import Menu
|
|
from gamestonk_terminal.stocks.government import quiverquant_model
|
|
|
|
|
|
def lastcontracts_command(past_transactions_days: int = 2, num: int = 20):
|
|
"""Displays last government contracts [quiverquant.com]"""
|
|
|
|
# Debug user input
|
|
if cfg.DEBUG:
|
|
logger.debug("gov lastcontracts %s %s", past_transactions_days, num)
|
|
|
|
df_contracts = quiverquant_model.get_government_trading("contracts")
|
|
|
|
if df_contracts.empty:
|
|
logger.debug("No government contracts found")
|
|
raise Exception("No government contracts found")
|
|
|
|
df_contracts.sort_values("Date", ascending=False)
|
|
|
|
df_contracts["Date"] = pd.to_datetime(df_contracts["Date"])
|
|
df_contracts["Date"] = df_contracts["Date"].dt.date
|
|
|
|
df_contracts.drop_duplicates(inplace=True)
|
|
df_contracts = df_contracts[
|
|
df_contracts["Date"].isin(
|
|
df_contracts["Date"].unique()[:past_transactions_days]
|
|
)
|
|
]
|
|
|
|
df_contracts = df_contracts[["Date", "Ticker", "Amount", "Agency"]][:num]
|
|
choices = [
|
|
disnake.SelectOption(label="Overview", value="0", emoji="🟢"),
|
|
]
|
|
title = "Stocks: [quiverquant.com] Top buy government trading"
|
|
initial_str = "Overview"
|
|
i = 1
|
|
for col_name in df_contracts["Ticker"].values:
|
|
menu = f"\nPage {i}: {col_name}"
|
|
initial_str += f"\nPage {i}: {col_name}"
|
|
choices.append(
|
|
disnake.SelectOption(label=menu, value=f"{i}", emoji="🟢"),
|
|
)
|
|
i += 1
|
|
|
|
embeds = []
|
|
df_contracts = df_contracts.T
|
|
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_contracts.columns.values:
|
|
description = "```" + df_contracts[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,
|
|
}
|