mirror of
https://gitlab.com/simple-stock-bots/simple-stock-bot.git
synced 2025-07-25 07:32:01 +00:00
Resolve "Add Options from MarketData.app"
This commit is contained in:
@@ -21,7 +21,7 @@ Want stock data or to host your own bot? Help keep this bot free by using my
|
||||
|
||||
📢 Stay updated on the bot's Telegram: https://t.me/simplestockbotnews.
|
||||
|
||||
**Guide**: All about using and setting up the bot is in the [docs](https://docs.simplestockbot.com).
|
||||
**Guide**: All about using and setting up the bot is in the [docs](https://simplestockbot.com).
|
||||
|
||||
The bot recognizes _"Symbols"_. `$` for stocks and `$$` for cryptos. Example:
|
||||
- `/chart $$eth` gets a month's Ethereum chart.
|
||||
@@ -43,7 +43,7 @@ Pick a ticker, and the bot shares the current price in chat. Note: Prices can la
|
||||
|
||||
Data thanks to [marketdata.app](https://dashboard.marketdata.app/marketdata/aff/go/misterbiggs?keyword=telegram).
|
||||
|
||||
Bot issues? Use `/status` or [contact us](https://docs.simplestockbot.com/contact).
|
||||
Bot issues? Use `/status` or [contact us](https://simplestockbot.com/contact).
|
||||
|
||||
"""
|
||||
|
||||
@@ -56,7 +56,7 @@ All funds help maintain servers, with data from
|
||||
1. Use `/donate [amount in USD]`. E.g., `/donate 2` donates 2 USD.
|
||||
2. Or, quickly donate at [buymeacoffee](https://www.buymeacoffee.com/Anson). No account needed, accepts Paypal & Credit card.
|
||||
|
||||
For questions, visit our [website](https://docs.simplestockbot.com).
|
||||
For questions, visit our [website](https://simplestockbot.com).
|
||||
"""
|
||||
|
||||
|
||||
|
@@ -178,17 +178,33 @@ async def symbol_detect(update: Update, context: ContextTypes.DEFAULT_TYPE):
|
||||
message = update.message.text
|
||||
chat_id = update.message.chat_id
|
||||
if "$" in message:
|
||||
symbols = s.find_symbols(message)
|
||||
log.info("Looking for Symbols")
|
||||
symbols = s.find_symbols(message)
|
||||
else:
|
||||
return
|
||||
except AttributeError as ex:
|
||||
log.info(ex)
|
||||
return
|
||||
if symbols:
|
||||
# Let user know bot is working
|
||||
|
||||
# Detect Options
|
||||
if ("call" in message.lower()) or ("put" in message.lower()):
|
||||
log.info("Options detected")
|
||||
await context.bot.send_chat_action(chat_id=chat_id, action=telegram.constants.ChatAction.TYPING)
|
||||
try:
|
||||
options_data = s.options(message, symbols)
|
||||
|
||||
await update.message.reply_text(
|
||||
text=generate_options_reply(options_data),
|
||||
parse_mode=telegram.constants.ParseMode.MARKDOWN,
|
||||
)
|
||||
return
|
||||
except KeyError as ex:
|
||||
logging.warning(ex)
|
||||
pass
|
||||
|
||||
if symbols:
|
||||
log.info(f"Symbols found: {symbols}")
|
||||
await context.bot.send_chat_action(chat_id=chat_id, action=telegram.constants.ChatAction.TYPING)
|
||||
|
||||
for reply in s.price_reply(symbols):
|
||||
await update.message.reply_text(
|
||||
@@ -198,6 +214,47 @@ async def symbol_detect(update: Update, context: ContextTypes.DEFAULT_TYPE):
|
||||
)
|
||||
|
||||
|
||||
def generate_options_reply(options_data: dict):
|
||||
# Header with Option Symbol and Underlying
|
||||
message_text = f"*{options_data['Option Symbol']} ({options_data['Underlying']})*\n\n"
|
||||
|
||||
# Key details
|
||||
details = (
|
||||
f"*Expiration:* `{options_data['Expiration']}`\n"
|
||||
f"*Side:* `{options_data['side']}`\n"
|
||||
f"*Strike:* `{options_data['strike']}`\n"
|
||||
f"*First Traded:* `{options_data['First Traded']}`\n"
|
||||
f"*Last Updated:* `{options_data['Last Updated']}`\n\n"
|
||||
)
|
||||
message_text += details
|
||||
|
||||
# Pricing info
|
||||
pricing_info = (
|
||||
f"*Bid:* `{options_data['bid']}` (Size: `{options_data['bidSize']}`)\n"
|
||||
f"*Mid:* `{options_data['mid']}`\n"
|
||||
f"*Ask:* `{options_data['ask']}` (Size: `{options_data['askSize']}`)\n"
|
||||
f"*Last:* `{options_data['last']}`\n\n"
|
||||
)
|
||||
message_text += pricing_info
|
||||
|
||||
# Volume and open interest
|
||||
volume_info = f"*Open Interest:* `{options_data['Open Interest']}`\n" f"*Volume:* `{options_data['Volume']}`\n\n"
|
||||
message_text += volume_info
|
||||
|
||||
# Greeks
|
||||
greeks_info = (
|
||||
f"*IV:* `{options_data['Implied Volatility']}`\n"
|
||||
f"*Delta:* `{options_data['delta']}`\n"
|
||||
f"*Gamma:* `{options_data['gamma']}`\n"
|
||||
f"*Theta:* `{options_data['theta']}`\n"
|
||||
f"*Vega:* `{options_data['vega']}`\n"
|
||||
f"*Rho:* `{options_data['rho']}`\n"
|
||||
)
|
||||
message_text += greeks_info
|
||||
|
||||
return message_text
|
||||
|
||||
|
||||
async def intra(update: Update, context: ContextTypes.DEFAULT_TYPE):
|
||||
"""returns a chart of intraday data for a symbol"""
|
||||
log.info(f"Intra command ran by {update.message.chat.username}")
|
||||
|
Reference in New Issue
Block a user