Files
OpenBB/discordbot/reaction_helper.py
teh_coderer 445ec3256c Discordbot/expiry reactions (#1114)
* added load extension for options menu

* options menu: oi, iv, unusual options

* Update opt_menu.py

* Update unu.py

if no num requested set default to 10

* Update opt_menu.py

+ !oi ticker expiry request added without inputting date format. accepts 0-9 up to 10 weeks
+ added option volume plot (works same as oi)

* Create vol.py

* Create reaction_helper.py

* Cleaned up, added historical options

Cleaned up
+ added historical options data
+ added expiry reaction helper function

* Create hist.py

* cleanup

* added min/max strike price

* cleanup

* cleanup, added min/max strike price

* Update opt_menu.py

* added yfinance if no tradier token

* Update vol.py

* Update opt_menu.py

* Create oi_tradier.py

* Update oi.py

* Update opt_menu.py

* Update oi.py

* Update opt_menu.py

* Update oi.py

* Update iv.py

* Update unu.py

* Update oi_tradier.py

* Update hist.py

* Update opt_menu.py

* Update reaction_helper.py

* Create options_menu.py

* Update run_discordbot.py

* Update vol.py

* Rename discordbot/options_menu.py to discordbot/stocks/options/options_menu.py

* Delete opt_menu.py

* Update oi.py

+ min strike/max strike

* Delete oi_tradier.py

* Update options_menu.py

* Update hist.py

* Update vol.py

* Update oi.py

* Update options_menu.py

* Update options_menu.py

* Update options_menu.py

* Linting/Pre-Commit Fixes

* linting

* Linting

* linting

* pylint fixes

* Update iv.py

* Update options_menu.py

* Update reaction_helper.py

* Improved Code

- removed 148 lines same function

* Update run_discordbot.py

* Update reaction_helper.py

* Updated Options Menu

+ reaction expiry lookup
+ added unu, iv, oi, vol ,hist

* mypy fix

* msg delete delay

* Update options_menu.py

* fix

seems bot doesn't like when last emoji is empty.
added an X when strike c/p empty

* Update opt_cmd.py

* Update options_menu.py

* better handling

* Update options_menu.py

* Update opt_cmd.py

* fix stocks.opt indention

* hist.py token/error handling

* Update hist.py

* Update options_menu.py

* Update hist.py
2022-01-01 17:26:42 +00:00

127 lines
4.1 KiB
Python
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import asyncio
import discord
from gamestonk_terminal.config_terminal import TRADIER_TOKEN
from gamestonk_terminal.stocks.options import tradier_model, yfinance_model
from discordbot.run_discordbot import gst_bot
import discordbot.config_discordbot as cfg
async def expiry_dates_reaction(ctx, ticker, expiry, func_cmd, call_arg: tuple = None):
if TRADIER_TOKEN == "REPLACE_ME":
dates = yfinance_model.option_expirations(ticker)
else:
dates = tradier_model.option_expirations(ticker)
index_dates = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
if expiry is not None:
try:
if expiry not in dates:
exp = int(expiry.replace("-", ""))
if (expiry not in dates) and (exp not in index_dates):
raise Exception("Enter a valid expiration date.")
if expiry in dates:
if call_arg is None:
await func_cmd(ctx, ticker, expiry)
else:
await func_cmd(ctx, ticker, expiry, *call_arg)
return
if exp in index_dates:
expiry = dates[int(expiry)]
if call_arg is None:
await func_cmd(ctx, ticker, expiry)
else:
await func_cmd(ctx, ticker, expiry, *call_arg)
return
except Exception as e:
embed = discord.Embed(
title="ERROR Options: Expiry Date",
colour=cfg.COLOR,
description=e,
)
embed.set_author(
name=cfg.AUTHOR_NAME,
icon_url=cfg.AUTHOR_ICON_URL,
)
await ctx.send(embed=embed, delete_after=10.0)
return
if not dates:
embed = discord.Embed(
title="ERROR Options",
colour=cfg.COLOR,
description="Enter a valid stock ticker",
)
embed.set_author(
name=cfg.AUTHOR_NAME,
icon_url=cfg.AUTHOR_ICON_URL,
)
await ctx.send(embed=embed, delete_after=10.0)
return
text = (
"```0️⃣ " + dates[0] + "\n"
"1️⃣ " + dates[1] + "\n"
"2️⃣ " + dates[2] + "\n"
"3️⃣ " + dates[3] + "\n"
"4️⃣ " + dates[4] + "\n"
"5️⃣ " + dates[5] + "\n"
"6️⃣ " + dates[6] + "\n"
"7️⃣ " + dates[7] + "\n"
"8️⃣ " + dates[8] + "\n"
"9️⃣ " + dates[9] + "```"
)
title = " " + ticker.upper() + " Options: Expiry Date"
embed = discord.Embed(title=title, description=text, colour=cfg.COLOR)
embed.set_author(
name=cfg.AUTHOR_NAME,
icon_url=cfg.AUTHOR_ICON_URL,
)
msg = await ctx.send(embed=embed, delete_after=15.0)
emoji_list = ["0️⃣", "1️⃣", "2️⃣", "3️⃣", "4️⃣", "5️⃣", "6️⃣", "7️⃣", "8️⃣", "9️⃣"]
for emoji in emoji_list:
await msg.add_reaction(emoji)
def check(reaction, user):
return user == ctx.message.author and str(reaction.emoji) in emoji_list
try:
reaction, _ = await gst_bot.wait_for(
"reaction_add", timeout=cfg.MENU_TIMEOUT, check=check
)
for N in range(0, 10):
if reaction.emoji == emoji_list[N]:
if cfg.DEBUG:
print(f"Reaction selected: {N}")
expiry = dates[N]
if call_arg is None:
await func_cmd(ctx, ticker, expiry)
else:
await func_cmd(ctx, ticker, expiry, *call_arg)
for emoji in emoji_list:
await msg.remove_reaction(emoji, ctx.bot.user)
except asyncio.TimeoutError:
for emoji in emoji_list:
await msg.remove_reaction(emoji, ctx.bot.user)
embed = discord.Embed(
description="Error timeout - you snooze you lose! 😋",
colour=cfg.COLOR,
title="TIMEOUT " + ticker.upper() + " Options: Expiry Date",
)
embed.set_author(
name=cfg.AUTHOR_NAME,
icon_url=cfg.AUTHOR_ICON_URL,
)
await ctx.send(embed=embed, delete_after=10.0)