1
0
mirror of https://gitlab.com/simple-stock-bots/simple-telegram-stock-bot.git synced 2025-07-23 14:41:26 +00:00
This commit is contained in:
2021-06-23 21:28:13 -07:00
parent baf45e09c8
commit acc0ebdd28
3 changed files with 79 additions and 47 deletions

View File

@@ -7,7 +7,7 @@ import random
import datetime
from fuzzywuzzy import fuzz
from typing import List, Tuple
from logging import debug, info, warning, error, critical
from IEX_Symbol import IEX_Symbol
from cg_Crypto import cg_Crypto
@@ -24,7 +24,7 @@ class Router:
self.stock = IEX_Symbol()
self.crypto = cg_Crypto()
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
in a blob of text and returns them in a list.
Only returns each match once. Example: Whats the price of $tsla?
@@ -36,7 +36,7 @@ class Router:
Returns
-------
List[str]
list[str]
List of stock symbols as strings without dollar sign.
"""
symbols = []
@@ -45,15 +45,15 @@ class Router:
if stock.upper() in self.stock.symbol_list["symbol"].values:
symbols.append(Stock(stock))
else:
print(f"{stock} is not in list of stocks")
info(f"{stock} is not in list of stocks")
coins = set(re.findall(self.CRYPTO_REGEX, text))
for coin in coins:
if coin.lower() in self.crypto.symbol_list["symbol"].values:
symbols.append(Coin(coin.lower()))
else:
print(f"{coin} is not in list of coins")
print(symbols)
info(f"{coin} is not in list of coins")
info(symbols)
return symbols
def status(self, bot_resp) -> str:
@@ -65,7 +65,7 @@ class Router:
Human readable text on status of the bot and relevant APIs
"""
return f"""
stats = f"""
Bot Status:
{bot_resp}
@@ -76,7 +76,11 @@ class Router:
{self.crypto.status()}
"""
def search_symbols(self, search: str) -> List[Tuple[str, str]]:
warning(stats)
return stats
def search_symbols(self, search: str) -> list[tuple[str, str]]:
"""Performs a fuzzy search to find stock symbols closest to a search term.
Parameters
@@ -86,7 +90,7 @@ class Router:
Returns
-------
List[tuple[str, str]]
list[tuple[str, str]]
A list tuples of every stock sorted in order of how well they match. Each tuple contains: (Symbol, Issue Name).
"""
@@ -113,7 +117,7 @@ class Router:
self.searched_symbols[search] = symbol_list
return symbol_list
def inline_search(self, search: str) -> List[Tuple[str, str]]:
def inline_search(self, search: str) -> list[tuple[str, str]]:
"""Searches based on the shortest symbol that contains the same string as the search.
Should be very fast compared to a fuzzy search.
@@ -124,7 +128,7 @@ class Router:
Returns
-------
List[tuple[str, str]]
list[tuple[str, str]]
Each tuple contains: (Symbol, Issue Name).
"""
@@ -141,7 +145,7 @@ class Router:
self.searched_symbols[search] = symbol_list
return symbol_list
def price_reply(self, symbols: list[Symbol]) -> List[str]:
def price_reply(self, symbols: list[Symbol]) -> list[str]:
"""Returns current market price or after hours if its available for a given stock symbol.
Parameters
@@ -158,17 +162,17 @@ class Router:
replies = []
for symbol in symbols:
print(symbol)
info(symbol)
if isinstance(symbol, Stock):
replies.append(self.stock.price_reply(symbol))
elif isinstance(symbol, Coin):
replies.append(self.crypto.price_reply(symbol))
else:
print(f"{symbol} is not a Stock or Coin")
info(f"{symbol} is not a Stock or Coin")
return replies
def dividend_reply(self, symbols: list) -> List[str]:
def dividend_reply(self, symbols: list) -> list[str]:
"""Returns the most recent, or next dividend date for a stock symbol.
Parameters
@@ -192,7 +196,7 @@ class Router:
return replies
def news_reply(self, symbols: list) -> List[str]:
def news_reply(self, symbols: list) -> list[str]:
"""Gets recent english news on stock symbols.
Parameters
@@ -220,12 +224,12 @@ class Router:
return replies
def info_reply(self, symbols: list) -> List[str]:
def info_reply(self, symbols: list) -> list[str]:
"""Gets information on stock symbols.
Parameters
----------
symbols : List[str]
symbols : list[str]
List of stock symbols.
Returns
@@ -289,12 +293,12 @@ class Router:
print(f"{symbol} is not a Stock or Coin")
return pd.DataFrame()
def stat_reply(self, symbols: List[Symbol]) -> List[str]:
def stat_reply(self, symbols: list[Symbol]) -> list[str]:
"""Gets key statistics for each symbol in the list
Parameters
----------
symbols : List[str]
symbols : list[str]
List of stock symbols
Returns
@@ -314,12 +318,12 @@ class Router:
return replies
def cap_reply(self, symbols: List[Symbol]) -> List[str]:
def cap_reply(self, symbols: list[Symbol]) -> list[str]:
"""Gets market cap for each symbol in the list
Parameters
----------
symbols : List[str]
symbols : list[str]
List of stock symbols
Returns
@@ -375,7 +379,7 @@ class Router:
return f"{choice}\nBuy and hold until: {hold}"
def batch_price_reply(self, symbols: list[Symbol]) -> List[str]:
def batch_price_reply(self, symbols: list[Symbol]) -> list[str]:
"""Returns current market price or after hours if its available for a given stock symbol.
Parameters