mirror of
https://github.com/OpenBB-finance/OpenBB.git
synced 2026-10-30 14:02:06 +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 * 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
110 lines
2.9 KiB
Python
110 lines
2.9 KiB
Python
import discord
|
|
import numpy as np
|
|
import pandas as pd
|
|
import requests
|
|
from tabulate import tabulate
|
|
|
|
import discordbot.config_discordbot as cfg
|
|
from gamestonk_terminal.helper_funcs import get_user_agent
|
|
|
|
|
|
async def unu_command(ctx, num: int = None):
|
|
"""Unusual Options"""
|
|
try:
|
|
|
|
# Debug
|
|
if cfg.DEBUG:
|
|
print(f"!stocks.opt.unu {num}")
|
|
|
|
# Check for argument
|
|
if num is None:
|
|
num = 10
|
|
|
|
pages = np.arange(0, num // 20 + 1)
|
|
data_list = []
|
|
for page_num in pages:
|
|
|
|
r = requests.get(
|
|
f"https://app.fdscanner.com/api2/unusualvolume?p=0&page_size=20&page={int(page_num)}",
|
|
headers={"User-Agent": get_user_agent()},
|
|
)
|
|
|
|
if r.status_code != 200:
|
|
print("Error in fdscanner request")
|
|
return pd.DataFrame(), "request error"
|
|
|
|
data_list.append(r.json())
|
|
|
|
ticker, expiry, option_strike, option_type, ask, bid, oi, vol, voi = (
|
|
[],
|
|
[],
|
|
[],
|
|
[],
|
|
[],
|
|
[],
|
|
[],
|
|
[],
|
|
[],
|
|
)
|
|
for data in data_list:
|
|
for entry in data["data"]:
|
|
ticker.append(entry["tk"])
|
|
expiry.append(entry["expiry"])
|
|
option_strike.append(float(entry["s"]))
|
|
option_type.append("Put" if entry["t"] == "P" else "Call")
|
|
ask.append(entry["a"])
|
|
bid.append(entry["b"])
|
|
oi.append(entry["oi"])
|
|
vol.append(entry["v"])
|
|
voi.append(entry["vol/oi"])
|
|
|
|
df = pd.DataFrame(
|
|
{
|
|
"Ticker": ticker,
|
|
"Exp": expiry,
|
|
"Strike": option_strike,
|
|
"Type": option_type,
|
|
"Vol/OI": voi,
|
|
"Vol": vol,
|
|
"OI": oi,
|
|
}
|
|
)
|
|
|
|
df = df.replace({"2021-", "2022-"}, "", regex=True)
|
|
|
|
report = (
|
|
"```"
|
|
+ tabulate(
|
|
df,
|
|
headers=["T", "Exp", "ST", "C/P", "V/O", "Vol", "OI"],
|
|
tablefmt="fancy_grid",
|
|
showindex=False,
|
|
floatfmt=["", "", ".1f", "", ".1f", ".0f", ".0f", ".2f", ".2f"],
|
|
)
|
|
+ "```"
|
|
)
|
|
embed = discord.Embed(
|
|
title="Unusual Options",
|
|
description=report,
|
|
colour=cfg.COLOR,
|
|
)
|
|
embed.set_author(
|
|
name=cfg.AUTHOR_NAME,
|
|
icon_url=cfg.AUTHOR_ICON_URL,
|
|
)
|
|
|
|
await ctx.send(embed=embed)
|
|
|
|
except Exception as e:
|
|
embed = discord.Embed(
|
|
title="ERROR Unusual Options",
|
|
colour=cfg.COLOR,
|
|
description=e,
|
|
)
|
|
embed.set_author(
|
|
name=cfg.AUTHOR_NAME,
|
|
icon_url=cfg.AUTHOR_ICON_URL,
|
|
)
|
|
|
|
await ctx.send(embed=embed)
|