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