mirror of
https://github.com/OpenBB-finance/OpenBB.git
synced 2026-10-29 05:21:48 +00:00
* 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
122 lines
4.3 KiB
Python
122 lines
4.3 KiB
Python
import asyncio
|
||
import discord
|
||
|
||
import discordbot.config_discordbot as cfg
|
||
from discordbot.run_discordbot import gst_bot
|
||
|
||
from discordbot.stocks.options.calls import calls_command
|
||
from discordbot.stocks.options.expirations import expirations_command
|
||
from discordbot.stocks.options.hist import hist_command
|
||
from discordbot.stocks.options.iv import iv_command
|
||
from discordbot.stocks.options.oi import oi_command
|
||
from discordbot.stocks.options.puts import puts_command
|
||
from discordbot.stocks.options.unu import unu_command
|
||
from discordbot.stocks.options.vol import vol_command
|
||
|
||
# pylint: disable=R0912
|
||
|
||
|
||
async def opt_command(ctx, ticker="", expiration="", strike="", put=""):
|
||
"""Options Menu command"""
|
||
|
||
if cfg.DEBUG:
|
||
print(f"!stocks.opt {ticker} {expiration} {strike} {put}")
|
||
|
||
if ticker:
|
||
current = 1
|
||
hist = (
|
||
f"7️⃣ !stocks.opt.hist {ticker} (strike*) (c/p*) {expiration}\n\n* Required"
|
||
)
|
||
if strike and put:
|
||
hist = f"7️⃣ !stocks.opt.hist {ticker} {strike} {put} {expiration}"
|
||
current = 2
|
||
text = (
|
||
"```0️⃣ !stocks.opt.unu\n"
|
||
f"1️⃣ !stocks.opt.exp {ticker}\n"
|
||
f"2️⃣ !stocks.opt.iv {ticker}\n"
|
||
f"3️⃣ !stocks.opt.calls {ticker} {expiration} \n"
|
||
f"4️⃣ !stocks.opt.puts {ticker} {expiration} \n"
|
||
f"5️⃣ !stocks.opt.oi {ticker} {expiration} \n"
|
||
f"6️⃣ !stocks.opt.vol {ticker} {expiration} \n"
|
||
f"{hist}```"
|
||
)
|
||
|
||
if put == "p":
|
||
put = bool(True)
|
||
if put == "c":
|
||
put = bool(False)
|
||
|
||
title = "Stocks: Options Menu"
|
||
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=60.0)
|
||
|
||
if current == 1:
|
||
emoji_list = ["0️⃣", "1️⃣", "2️⃣", "3️⃣", "4️⃣", "5️⃣", "6️⃣"]
|
||
if current == 2:
|
||
emoji_list = ["0️⃣", "1️⃣", "2️⃣", "3️⃣", "4️⃣", "5️⃣", "6️⃣", "7️⃣"]
|
||
|
||
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
|
||
)
|
||
if reaction.emoji == "0️⃣":
|
||
if cfg.DEBUG:
|
||
print("Reaction selected: 0")
|
||
await unu_command(ctx)
|
||
elif reaction.emoji == "1️⃣":
|
||
if cfg.DEBUG:
|
||
print("Reaction selected: 1")
|
||
await expirations_command(ctx, ticker)
|
||
elif reaction.emoji == "2️⃣":
|
||
if cfg.DEBUG:
|
||
print("Reaction selected: 2")
|
||
await iv_command(ctx, ticker)
|
||
elif reaction.emoji == "3️⃣":
|
||
if cfg.DEBUG:
|
||
print("Reaction selected: 3")
|
||
await calls_command(ctx, ticker, expiration)
|
||
elif reaction.emoji == "4️⃣":
|
||
if cfg.DEBUG:
|
||
print("Reaction selected: 4")
|
||
await puts_command(ctx, ticker, expiration)
|
||
elif reaction.emoji == "5️⃣":
|
||
if cfg.DEBUG:
|
||
print("Reaction selected: 5")
|
||
await oi_command(ctx, ticker, expiration)
|
||
elif reaction.emoji == "6️⃣":
|
||
if cfg.DEBUG:
|
||
print("Reaction selected: 6")
|
||
await vol_command(ctx, ticker, expiration)
|
||
elif reaction.emoji == "7️⃣":
|
||
if cfg.DEBUG:
|
||
print("Reaction selected: 7")
|
||
strike = float(strike)
|
||
await hist_command(ctx, ticker, expiration, strike, put)
|
||
|
||
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)
|
||
if cfg.DEBUG:
|
||
embed = discord.Embed(
|
||
description="Error timeout - you snooze you lose! 😋",
|
||
colour=cfg.COLOR,
|
||
title="TIMEOUT Stocks: Options Menu",
|
||
).set_author(
|
||
name=cfg.AUTHOR_NAME,
|
||
icon_url=cfg.AUTHOR_ICON_URL,
|
||
)
|
||
await ctx.send(embed=embed, delete_after=30.0)
|