mirror of
https://gitlab.com/simple-stock-bots/simple-telegram-stock-bot.git
synced 2025-06-16 06:56:46 +00:00
Merge branch '94-update-bot-text-and-documentation' into 'master'
Resolve "Update Bot text and documentation" Closes #94 See merge request simple-stock-bots/simple-telegram-stock-bot!44
This commit is contained in:
commit
bf37d4f0ea
@ -13,7 +13,7 @@ COPY --from=builder /root/.local /root/.local
|
||||
|
||||
RUN pip install --no-cache-dir black
|
||||
ENV TELEGRAM=TOKEN
|
||||
ENV IEX=TOKEN
|
||||
ENV MARKETDATA=TOKEN
|
||||
|
||||
COPY . .
|
||||
|
||||
|
@ -1,10 +1,6 @@
|
||||
"""Class with functions for running the bot with IEX Cloud.
|
||||
"""
|
||||
|
||||
import logging
|
||||
import os
|
||||
import datetime as dt
|
||||
from logging import warning
|
||||
from typing import Dict
|
||||
|
||||
import pandas as pd
|
||||
@ -13,6 +9,8 @@ import schedule
|
||||
|
||||
from Symbol import Stock
|
||||
|
||||
log = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class MarketData:
|
||||
"""
|
||||
@ -38,7 +36,7 @@ class MarketData:
|
||||
self.MARKETDATA_TOKEN = ""
|
||||
except KeyError:
|
||||
self.MARKETDATA_TOKEN = ""
|
||||
warning("Starting without an MarketData.app Token will not allow you to get market data!")
|
||||
log.warning("Starting without an MarketData.app Token will not allow you to get market data!")
|
||||
|
||||
if self.MARKETDATA_TOKEN != "":
|
||||
schedule.every().day.do(self.clear_charts)
|
||||
@ -137,6 +135,14 @@ class MarketData:
|
||||
else:
|
||||
return f"Getting a quote for {symbol} encountered an error."
|
||||
|
||||
def spark_reply(self, symbol: Stock) -> str:
|
||||
if quoteResp := self.get(f"stocks/quotes/{symbol}/"):
|
||||
changePercent = round(quoteResp["changepct"][0], 2)
|
||||
return f"`{symbol.tag}`: {changePercent}%"
|
||||
else:
|
||||
logging.warning(f"{symbol} did not have 'changepct' field.")
|
||||
return f"`{symbol.tag}`"
|
||||
|
||||
def intra_reply(self, symbol: Stock) -> pd.DataFrame:
|
||||
"""Returns price data for a symbol of the past month up until the previous trading days close.
|
||||
Also caches multiple requests made in the same day.
|
||||
|
@ -15,7 +15,7 @@ https://docs.simplestockbot.com/commands/
|
||||
|
||||
## Donate
|
||||
|
||||
Simple Stock Bot is run entirely on donations, and costs about $420 a year to run. All donations go directly towards paying for servers, and premium market data provided by [IEX Cloud](https://iexcloud.io/).
|
||||
Simple Stock Bot is run entirely on donations, and costs about $420 a year to run. All donations go directly towards paying for servers, and premium market data provided by [Market Data](https://www.marketdata.app/).
|
||||
|
||||
The best way to donate is through [Buy Me A Coffee](https://www.buymeacoffee.com/Anson) which accepts Paypal or Credit card.
|
||||
|
||||
@ -29,4 +29,4 @@ If you have any questions get in [touch.](contact.md)
|
||||
- Contribute to the project on [GitLab](https://gitlab.com/simple-stock-bots) or just leave a star
|
||||
- Using my referral links to host your own Bot
|
||||
- [DigitalOcean](https://m.do.co/c/6b5df7ef55b6)
|
||||
- [IEX Cloud](https://iexcloud.io/s/62c8503e)
|
||||
- [Market Data](https://www.marketdata.app/)
|
||||
|
@ -26,20 +26,15 @@ Simply calling a symbol in any message that the bot can see will also return the
|
||||
|
||||
**Commands**
|
||||
- `/donate [amount in USD]` to donate. 🎗️
|
||||
- `/dividend $[symbol]` Dividend information for the symbol. 📅
|
||||
- `/intra $[symbol]` Plot of the stocks movement since the last market open. 📈
|
||||
- `/chart $[symbol]` Plot of the stocks movement for the past 1 month. 📊
|
||||
- `/news $[symbol]` News about the symbol. 📰
|
||||
- `/info $[symbol]` General information about the symbol. ℹ️
|
||||
- `/stat $[symbol]` Key statistics about the symbol. 🔢
|
||||
- `/cap $[symbol]` Market Capitalization of symbol. 💰
|
||||
- `/trending` Trending Stocks and Cryptos. 💬
|
||||
- `/help` Get some help using the bot. 🆘
|
||||
|
||||
**Inline Features**
|
||||
You can type @SimpleStockBot `[search]` in any chat or direct message to search for the stock bots full list of stock and crypto symbols and return the price. Then once you select the ticker want the bot will send a message as you in that chat with the latest stock price. Prices may be delayed by up to an hour.
|
||||
|
||||
Market data is provided by [IEX Cloud](https://iexcloud.io)
|
||||
Market data is provided by [Market Data](https://www.marketdata.app/)
|
||||
|
||||
If you believe the bot is not behaving properly run `/status` or [get in touch](https://docs.simplestockbot.com/contact).
|
||||
"""
|
||||
@ -47,7 +42,7 @@ Simply calling a symbol in any message that the bot can see will also return the
|
||||
donate_text = """
|
||||
Simple Stock Bot is run entirely on donations[.](https://www.buymeacoffee.com/Anson)
|
||||
All donations go directly towards paying for servers, and market data is provided by
|
||||
[IEX Cloud](https://iexcloud.io/).
|
||||
[Market Data](https://www.marketdata.app/).
|
||||
|
||||
The easiest way to donate is to run the `/donate [amount in USD]` command with US dollars you would like to donate.
|
||||
|
||||
|
26
bot.py
26
bot.py
@ -8,7 +8,6 @@ import os
|
||||
import random
|
||||
import string
|
||||
import traceback
|
||||
import logging as log
|
||||
from uuid import uuid4
|
||||
|
||||
import mplfinance as mpf
|
||||
@ -32,6 +31,10 @@ from telegram.ext import (
|
||||
from symbol_router import Router
|
||||
from T_info import T_info
|
||||
|
||||
# Enable logging
|
||||
logging.basicConfig(format="%(asctime)s - %(name)s - %(levelname)s - %(message)s", level=logging.INFO)
|
||||
log = logging.getLogger(__name__)
|
||||
|
||||
TELEGRAM_TOKEN = os.environ["TELEGRAM"]
|
||||
|
||||
try:
|
||||
@ -43,10 +46,7 @@ except KeyError:
|
||||
s = Router()
|
||||
t = T_info()
|
||||
|
||||
# Enable logging
|
||||
logging.basicConfig(format="%(asctime)s - %(name)s - %(levelname)s - %(message)s", level=logging.INFO)
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
log.info("Bot script started.")
|
||||
|
||||
|
||||
@ -304,7 +304,6 @@ def trending(update: Update, context: CallbackContext):
|
||||
context.bot.send_chat_action(chat_id=chat_id, action=telegram.ChatAction.TYPING)
|
||||
|
||||
trending_list = s.trending()
|
||||
log.info(trending_list)
|
||||
|
||||
update.message.reply_text(
|
||||
text=trending_list,
|
||||
@ -380,22 +379,21 @@ def error(update: Update, context: CallbackContext):
|
||||
log.warning(f"Logging error: {err_code}")
|
||||
|
||||
if update:
|
||||
message = (
|
||||
log.warning(
|
||||
f"An exception was raised while handling an update\n"
|
||||
f"<pre>update = {html.escape(json.dumps(update.to_dict(), indent=2, ensure_ascii=False))}"
|
||||
"</pre>\n\n"
|
||||
f"<pre>context.chat_data = {html.escape(str(context.chat_data))}</pre>\n\n"
|
||||
f"<pre>context.user_data = {html.escape(str(context.user_data))}</pre>\n\n"
|
||||
f"<pre>{html.escape(tb_string)}</pre>"
|
||||
f"\tupdate = {html.escape(json.dumps(update.to_dict(), indent=2, ensure_ascii=False))}\n"
|
||||
f"\tcontext.chat_data = {str(context.chat_data)}\n"
|
||||
f"\tcontext.user_data = {str(context.user_data)}\n"
|
||||
f"\t{html.escape(tb_string)}"
|
||||
)
|
||||
log.warning(message)
|
||||
else:
|
||||
log.warning(tb_string)
|
||||
|
||||
update.message.reply_text(
|
||||
text=f"An error has occured. Please inform @MisterBiggs if the error persists. Error Code: `{err_code}`",
|
||||
parse_mode=telegram.ParseMode.MARKDOWN,
|
||||
)
|
||||
else:
|
||||
log.warning("No message to send to user.")
|
||||
log.warning(tb_string)
|
||||
|
||||
|
||||
def main():
|
||||
|
14
cg_Crypto.py
14
cg_Crypto.py
@ -1,7 +1,4 @@
|
||||
"""Class with functions for running the bot with IEX Cloud.
|
||||
"""
|
||||
|
||||
import logging as log
|
||||
import logging
|
||||
from typing import List
|
||||
|
||||
import pandas as pd
|
||||
@ -11,6 +8,8 @@ from markdownify import markdownify
|
||||
|
||||
from Symbol import Coin
|
||||
|
||||
log = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class cg_Crypto:
|
||||
"""
|
||||
@ -22,13 +21,6 @@ class cg_Crypto:
|
||||
trending_cache: List[str] = []
|
||||
|
||||
def __init__(self) -> None:
|
||||
"""Creates a Symbol Object
|
||||
|
||||
Parameters
|
||||
----------
|
||||
IEX_TOKEN : str
|
||||
IEX Token
|
||||
"""
|
||||
self.get_symbol_list()
|
||||
schedule.every().day.do(self.get_symbol_list)
|
||||
|
||||
|
@ -4,3 +4,4 @@ flake8==5.0.4
|
||||
Flake8-pyproject==1.2.3
|
||||
pylama==8.4.1
|
||||
mypy==1.2.0
|
||||
types-cachetools==5.3.0.5
|
@ -5,7 +5,6 @@ import datetime
|
||||
import logging
|
||||
import random
|
||||
import re
|
||||
import logging as log
|
||||
|
||||
import pandas as pd
|
||||
import schedule
|
||||
@ -17,6 +16,8 @@ from Symbol import Coin, Stock, Symbol
|
||||
|
||||
from typing import Dict
|
||||
|
||||
log = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class Router:
|
||||
STOCK_REGEX = "(?:^|[^\\$])\\$([a-zA-Z.]{1,6})"
|
||||
@ -77,9 +78,9 @@ class Router:
|
||||
else:
|
||||
symbols.append(Coin(sym))
|
||||
if symbols:
|
||||
log.info(symbols)
|
||||
for symbol in symbols:
|
||||
self.trending_count[symbol.tag] = self.trending_count.get(symbol.tag, 0) + trending_weight
|
||||
log.warning(self.trending_count)
|
||||
|
||||
return symbols
|
||||
|
||||
@ -303,8 +304,7 @@ class Router:
|
||||
|
||||
for symbol in symbols:
|
||||
if isinstance(symbol, Stock):
|
||||
replies.append("Command not supported for stocks.")
|
||||
# replies.append(self.stock.spark_reply(symbol))
|
||||
replies.append(self.stock.spark_reply(symbol))
|
||||
elif isinstance(symbol, Coin):
|
||||
replies.append(self.crypto.spark_reply(symbol))
|
||||
else:
|
||||
@ -322,26 +322,21 @@ class Router:
|
||||
List of preformatted strings to be sent to user.
|
||||
"""
|
||||
|
||||
stocks = self.stock.trending()
|
||||
# stocks = self.stock.trending()
|
||||
coins = self.crypto.trending()
|
||||
|
||||
reply = ""
|
||||
|
||||
log.warning(self.trending_count)
|
||||
if self.trending_count:
|
||||
reply += "🔥Trending on the Stock Bot:\n`"
|
||||
reply += "━" * len("Trending on the Stock Bot:") + "`\n"
|
||||
|
||||
sorted_trending = [s[0] for s in sorted(self.trending_count.items(), key=lambda item: item[1])][::-1][0:5]
|
||||
|
||||
log.warning(sorted_trending)
|
||||
for t in sorted_trending:
|
||||
reply += self.spark_reply(self.find_symbols(t))[0] + "\n"
|
||||
|
||||
if stocks:
|
||||
reply += "\n\n💵Trending Stocks:\n`"
|
||||
reply += "━" * len("Trending Stocks:") + "`\n"
|
||||
for stock in stocks:
|
||||
reply += stock + "\n"
|
||||
|
||||
if coins:
|
||||
reply += "\n\n🦎Trending Crypto:\n`"
|
||||
reply += "━" * len("Trending Crypto:") + "`\n"
|
||||
@ -390,7 +385,6 @@ class Router:
|
||||
log.debug(f"{symbol} is not a Stock or Coin")
|
||||
|
||||
if stocks:
|
||||
# IEX batch endpoint doesnt seem to be working right now
|
||||
for stock in stocks:
|
||||
replies.append(self.stock.price_reply(stock))
|
||||
if coins:
|
||||
|
Loading…
x
Reference in New Issue
Block a user