mirror of
https://gitlab.com/simple-stock-bots/simple-stock-bot.git
synced 2025-06-16 15:17:28 +00:00
#87: bandaid fix so bot can work without market data, and warns users about the lack of stock market data
This commit is contained in:
parent
06e1f62fff
commit
5df8ff11c2
@ -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 . .
|
||||
|
||||
|
@ -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."""
|
||||
|
158
placeholder_Symbol.py
Normal file
158
placeholder_Symbol.py
Normal file
@ -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]
|
@ -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:
|
||||
|
Loading…
x
Reference in New Issue
Block a user