From 5df8ff11c2373d02de21e948a06d101388e66cbf Mon Sep 17 00:00:00 2001 From: Anson Biggs Date: Sun, 28 Aug 2022 12:57:36 -0600 Subject: [PATCH] #87: bandaid fix so bot can work without market data, and warns users about the lack of stock market data --- .devcontainer/Dockerfile | 3 +- Symbol.py | 8 +- placeholder_Symbol.py | 158 +++++++++++++++++++++++++++++++++++++++ symbol_router.py | 16 +--- 4 files changed, 170 insertions(+), 15 deletions(-) create mode 100644 placeholder_Symbol.py diff --git a/.devcontainer/Dockerfile b/.devcontainer/Dockerfile index 7d7528f..e489016 100644 --- a/.devcontainer/Dockerfile +++ b/.devcontainer/Dockerfile @@ -12,8 +12,7 @@ ENV MPLBACKEND=Agg COPY --from=builder /root/.local /root/.local RUN pip install --no-cache-dir black -ENV TELEGRAM=TOKEN -ENV IEX=TOKEN +ENV TELEGRAM=724630968:AAFmLveRXhtTU_0dgzC724eGUpVK9b3Cw8w COPY . . diff --git a/Symbol.py b/Symbol.py index 06c25c0..802f8f2 100644 --- a/Symbol.py +++ b/Symbol.py @@ -31,7 +31,7 @@ class Stock(Symbol): def __init__(self, symbol: pd.DataFrame) -> None: if len(symbol) > 1: - logging.info(f"Crypto with shared id:\n\t{symbol.id}") + logging.info(f"Stock with shared id:\n\t{symbol.id}") symbol = symbol.head(1) self.symbol = symbol.symbol.values[0] @@ -39,6 +39,12 @@ class Stock(Symbol): self.name = symbol.name.values[0] self.tag = symbol.type_id.values[0].upper() + def __init__(self): + self.symbol = "Placeholder" + self.id = "Placeholder" + self.name = "Placeholder" + self.tag = "Placeholder" + class Coin(Symbol): """Cryptocurrency Object. Gets data from CoinGecko.""" diff --git a/placeholder_Symbol.py b/placeholder_Symbol.py new file mode 100644 index 0000000..64e4f63 --- /dev/null +++ b/placeholder_Symbol.py @@ -0,0 +1,158 @@ +"""Class with functions for running the bot with IEX Cloud. +""" + +import logging + +import pandas as pd + +from Symbol import Stock + + +class placeholder_Symbol: + """ + Functions for finding stock market information about symbols. + """ + + placeholder_message = """ + Due to increased costs for market data from IEX Cloud, a new provider will be required for the bot to have stock market data. Until then only cryptocurrency data will be available on the bot. + *Track this issue here:* https://t.me/simplestockchat + """ + + def __init__(self) -> None: + """Creates a placeholder Symbol Object""" + + logging.warning("Creating a placeholder Symbol.") + + def status(self) -> str: + """Checks IEX Status dashboard for any current API issues. + + Returns + ------- + str + Human readable text on status of stock market data + """ + + return self.placeholder_message + + def price_reply(self, symbol: Stock) -> str: + """Returns price movement of Stock for the last market day, or after hours. + + Parameters + ---------- + symbol : Stock + + Returns + ------- + str + Formatted markdown + """ + + return self.placeholder_message + + def dividend_reply(self, symbol: Stock) -> str: + """Returns the most recent, or next dividend date for a stock symbol. + + Parameters + ---------- + symbol : Stock + + Returns + ------- + str + Formatted markdown + """ + return self.placeholder_message + + def news_reply(self, symbol: Stock) -> str: + """Gets most recent, english, non-paywalled news + + Parameters + ---------- + symbol : Stock + + Returns + ------- + str + Formatted markdown + """ + return self.placeholder_message + + def info_reply(self, symbol: Stock) -> str: + """Gets description for Stock + + Parameters + ---------- + symbol : Stock + + Returns + ------- + str + Formatted text + """ + return self.placeholder_message + + def stat_reply(self, symbol: Stock) -> str: + """Key statistics on a Stock + + Parameters + ---------- + symbol : Stock + + Returns + ------- + str + Formatted markdown + """ + return self.placeholder_message + + def cap_reply(self, symbol: Stock) -> str: + """Get the Market Cap of a stock""" + + return self.placeholder_message + + def intra_reply(self, symbol: Stock) -> pd.DataFrame: + """Returns price data for a symbol since the last market open. + + Parameters + ---------- + symbol : str + Stock symbol. + + Returns + ------- + pd.DataFrame + Returns a timeseries dataframe with high, low, and volume data if its available. Otherwise returns empty pd.DataFrame. + """ + + return pd.DataFrame() + + def chart_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. + + Parameters + ---------- + symbol : str + Stock symbol. + + Returns + ------- + pd.DataFrame + Returns a timeseries dataframe with high, low, and volume data if its available. Otherwise returns empty pd.DataFrame. + """ + + return pd.DataFrame() + + def spark_reply(self, symbol: Stock) -> str: + return "" + + def trending(self) -> list[str]: + """Gets current coins trending on IEX. Only returns when market is open. + + Returns + ------- + list[str] + list of $ID: NAME, CHANGE% + """ + + return [self.placeholder_message] diff --git a/symbol_router.py b/symbol_router.py index d61ce66..d718543 100644 --- a/symbol_router.py +++ b/symbol_router.py @@ -12,7 +12,7 @@ import schedule from cachetools import TTLCache, cached from cg_Crypto import cg_Crypto -from IEX_Symbol import IEX_Symbol +from placeholder_Symbol import placeholder_Symbol from Symbol import Coin, Stock, Symbol @@ -22,7 +22,7 @@ class Router: trending_count = {} def __init__(self): - self.stock = IEX_Symbol() + self.stock = placeholder_Symbol() self.crypto = cg_Crypto() schedule.every().hour.do(self.trending_decay) @@ -62,16 +62,8 @@ class Router: schedule.run_pending() symbols = [] - stocks = set(re.findall(self.STOCK_REGEX, text)) - for stock in stocks: - sym = self.stock.symbol_list[ - self.stock.symbol_list["symbol"].str.fullmatch(stock, case=False) - ] - if ~sym.empty: - print(sym) - symbols.append(Stock(sym)) - else: - info(f"{stock} is not in list of stocks") + if re.findall(self.STOCK_REGEX, text): + symbols.append(Stock()) coins = set(re.findall(self.CRYPTO_REGEX, text)) for coin in coins: