1
0
mirror of https://gitlab.com/simple-stock-bots/simple-telegram-stock-bot.git synced 2025-06-16 15:06:53 +00:00

trending stocks now decay #75

This commit is contained in:
Anson Biggs 2021-08-30 13:21:56 -07:00
parent 99fdd6e8be
commit c7f083b2b1

View File

@ -7,6 +7,7 @@ import re
from logging import critical, debug, error, info, warning from logging import critical, debug, error, info, warning
import pandas as pd import pandas as pd
import schedule
from fuzzywuzzy import fuzz from fuzzywuzzy import fuzz
from cg_Crypto import cg_Crypto from cg_Crypto import cg_Crypto
@ -24,6 +25,20 @@ class Router:
self.stock = IEX_Symbol() self.stock = IEX_Symbol()
self.crypto = cg_Crypto() self.crypto = cg_Crypto()
schedule.every().hour().do(self.trending_decay)
def trending_decay(self, decay=0.5):
"""Decays the value of each trending stock by a multiplier"""
info("Decaying trending symbols.")
if self.trending_count:
for key in self.trending_count.keys():
if self.trending_count[key] < 0.01:
# This just makes sure were not keeping around keys that havent been called in a very long time.
self.trending_count.pop(key, None)
else:
self.trending_count[key] = self.trending_count[key] * decay
def find_symbols(self, text: str) -> list[Symbol]: def find_symbols(self, text: str) -> list[Symbol]:
"""Finds stock tickers starting with a dollar sign, and cryptocurrencies with two dollar signs """Finds stock tickers starting with a dollar sign, and cryptocurrencies with two dollar signs
in a blob of text and returns them in a list. in a blob of text and returns them in a list.
@ -38,6 +53,8 @@ class Router:
list[Symbol] list[Symbol]
List of stock symbols as Symbol objects List of stock symbols as Symbol objects
""" """
schedule.run_pending()
symbols = [] symbols = []
stocks = set(re.findall(self.STOCK_REGEX, text)) stocks = set(re.findall(self.STOCK_REGEX, text))
for stock in stocks: for stock in stocks: