mirror of
https://gitlab.com/simple-stock-bots/simple-stock-bot.git
synced 2025-06-16 07:16:40 +00:00
Bot now keeps track of symbols for own trending
This commit is contained in:
parent
f34fd37597
commit
082c42c39f
@ -8,6 +8,7 @@ class Symbol:
|
||||
symbol: What the user calls it. ie tsla or btc
|
||||
id: What the api expects. ie tsla or bitcoin
|
||||
name: Human readable. ie Tesla or Bitcoin
|
||||
tag: Uppercase tag to call the symbol. ie $TSLA or $$BTC
|
||||
"""
|
||||
|
||||
currency = "usd"
|
||||
@ -17,6 +18,7 @@ class Symbol:
|
||||
self.symbol = symbol
|
||||
self.id = symbol
|
||||
self.name = symbol
|
||||
self.tag = "$" + symbol
|
||||
|
||||
def __repr__(self) -> str:
|
||||
return f"<{self.__class__.__name__} instance of {self.id} at {id(self)}>"
|
||||
@ -32,6 +34,7 @@ class Stock(Symbol):
|
||||
self.symbol = symbol
|
||||
self.id = symbol
|
||||
self.name = "$" + symbol.upper()
|
||||
self.tag = "$" + symbol.upper()
|
||||
|
||||
|
||||
# Used by Coin to change symbols for ids
|
||||
@ -44,6 +47,7 @@ class Coin(Symbol):
|
||||
@functools.cache
|
||||
def __init__(self, symbol: str) -> None:
|
||||
self.symbol = symbol
|
||||
self.tag = "$$" + symbol.upper()
|
||||
self.get_data()
|
||||
|
||||
def get_data(self) -> None:
|
||||
|
@ -18,6 +18,7 @@ class Router:
|
||||
STOCK_REGEX = "(?:^|[^\\$])\\$([a-zA-Z.]{1,6})"
|
||||
CRYPTO_REGEX = "[$]{2}([a-zA-Z]{1,20})"
|
||||
searched_symbols = {}
|
||||
trending_count = {}
|
||||
|
||||
def __init__(self):
|
||||
self.stock = IEX_Symbol()
|
||||
@ -54,8 +55,12 @@ class Router:
|
||||
|
||||
if symbols:
|
||||
info(symbols)
|
||||
for symbol in symbols:
|
||||
self.trending_count[symbol.tag] = (
|
||||
self.trending_count.get(symbol.tag, 0) + 1
|
||||
)
|
||||
|
||||
return symbols
|
||||
return symbols
|
||||
|
||||
def status(self, bot_resp) -> str:
|
||||
"""Checks for any issues with APIs.
|
||||
@ -364,7 +369,19 @@ class Router:
|
||||
stocks = self.stock.trending()
|
||||
coins = self.crypto.trending()
|
||||
|
||||
reply = "Trending Stocks:\n"
|
||||
reply = ""
|
||||
|
||||
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]
|
||||
|
||||
for t in sorted_trending:
|
||||
reply += self.price_reply(self.find_symbols(t))[0] + "\n"
|
||||
|
||||
reply += "\n\nTrending Stocks:\n"
|
||||
reply += "-" * len("Trending Stocks:") + "\n"
|
||||
for stock in stocks:
|
||||
reply += stock + "\n"
|
||||
|
Loading…
x
Reference in New Issue
Block a user