mirror of
https://github.com/OpenBB-finance/OpenBB.git
synced 2026-10-29 05:21:48 +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>
53 lines
1.6 KiB
Python
53 lines
1.6 KiB
Python
import pandas as pd
|
|
from matplotlib import pyplot as plt
|
|
|
|
import bots.config_discordbot as cfg
|
|
from bots.config_discordbot import logger
|
|
from bots.helpers import image_border
|
|
from gamestonk_terminal.config_plot import PLOT_DPI
|
|
from gamestonk_terminal.helper_funcs import plot_autoscale
|
|
from gamestonk_terminal.stocks.government import quiverquant_model
|
|
|
|
|
|
def contracts_command(
|
|
ticker: str = "", past_transaction_days: int = 10, raw: bool = False
|
|
):
|
|
"""Displays contracts associated with tickers [quiverquant.com]"""
|
|
# Debug user input
|
|
if cfg.DEBUG:
|
|
logger.debug("gov-contracts %s %s %s", ticker, past_transaction_days, raw)
|
|
|
|
if ticker == "":
|
|
raise Exception("A ticker is required")
|
|
|
|
# Retrieve Data
|
|
df_contracts = quiverquant_model.get_government_trading("contracts", ticker)
|
|
|
|
if df_contracts.empty:
|
|
raise Exception("No government contracts found")
|
|
|
|
# Output Data
|
|
df_contracts["Date"] = pd.to_datetime(df_contracts["Date"]).dt.date
|
|
|
|
df_contracts = df_contracts[
|
|
df_contracts["Date"].isin(df_contracts["Date"].unique()[:past_transaction_days])
|
|
]
|
|
|
|
df_contracts.drop_duplicates(inplace=True)
|
|
|
|
fig, ax = plt.subplots(figsize=plot_autoscale(), dpi=PLOT_DPI)
|
|
|
|
df_contracts.groupby("Date").sum().div(1000).plot(kind="bar", rot=0, ax=ax)
|
|
ax.set_ylabel("Amount ($1k)")
|
|
ax.set_title(f"Sum of latest government contracts to {ticker}")
|
|
fig.tight_layout()
|
|
|
|
plt.savefig("gov_contracts.png")
|
|
imagefile = "gov_contracts.png"
|
|
|
|
imagefile = image_border(imagefile)
|
|
return {
|
|
"title": f"Stocks: [quiverquant.com] Contracts by {ticker}",
|
|
"imagefile": imagefile,
|
|
}
|