1
0
mirror of https://gitlab.com/simple-stock-bots/simple-stock-bot.git synced 2025-07-27 08:31:41 +00:00

Add list of stocks to bot

This commit is contained in:
2023-10-12 02:42:52 +00:00
parent 4a556597df
commit 66f233918e
10 changed files with 47 additions and 23 deletions

View File

@@ -20,6 +20,7 @@ class MarketData:
SYMBOL_REGEX = "[$]([a-zA-Z]{1,4})"
symbol_list: Dict[str, Dict] = {}
charts: Dict[Stock, pd.DataFrame] = {}
openTime = dt.time(hour=9, minute=30, second=0)
@@ -48,6 +49,9 @@ class MarketData:
if self.MARKETDATA_TOKEN != "":
schedule.every().day.do(self.clear_charts)
self.get_symbol_list()
schedule.every().day.do(self.get_symbol_list)
def get(self, endpoint, params: dict = {}, timeout=10) -> dict:
url = "https://api.marketdata.app/v1/" + endpoint
@@ -85,6 +89,21 @@ class MarketData:
return {}
def symbol_id(self, symbol: str) -> Dict[str, Dict]:
return self.symbol_list.get(symbol.upper(), None)
def get_symbol_list(self):
sec_resp = r.get("https://www.sec.gov/files/company_tickers.json")
sec_resp.raise_for_status()
sec_data = sec_resp.json()
for rank, ticker_info in sec_data.items():
self.symbol_list[ticker_info["ticker"]] = {
"ticker": ticker_info["ticker"],
"title": ticker_info["title"],
"mkt_cap_rank": rank,
}
def clear_charts(self) -> None:
"""
Clears cache of chart data.
@@ -129,13 +148,13 @@ class MarketData:
Formatted markdown
"""
if quoteResp := self.get(f"stocks/quotes/{symbol}/"):
if quoteResp := self.get(f"stocks/quotes/{symbol.symbol}/"):
price = round(quoteResp["last"][0], 2)
try:
changePercent = round(quoteResp["changepct"][0], 2)
except TypeError:
return f"The price of {symbol} is {price}"
return f"The price of {symbol.name} is ${price}"
message = f"The current price of {symbol.name} is ${price} and "