mirror of
https://gitlab.com/simple-stock-bots/simple-telegram-stock-bot.git
synced 2025-06-16 15:06:53 +00:00
Mostly wrapped up #75
This commit is contained in:
parent
dcce2cb95a
commit
a583cad741
@ -36,7 +36,7 @@ class IEX_Symbol:
|
|||||||
IEX API Token
|
IEX API Token
|
||||||
"""
|
"""
|
||||||
try:
|
try:
|
||||||
self.IEX_TOKEN = os.environ["IEX"]
|
self.IEX_TOKEN = "pk_3c39d940736e47dabfdd47eb689a65be"
|
||||||
except KeyError:
|
except KeyError:
|
||||||
self.IEX_TOKEN = ""
|
self.IEX_TOKEN = ""
|
||||||
warning(
|
warning(
|
||||||
@ -485,6 +485,23 @@ class IEX_Symbol:
|
|||||||
|
|
||||||
return pd.DataFrame()
|
return pd.DataFrame()
|
||||||
|
|
||||||
|
def spark_reply(self, symbol: Stock) -> str:
|
||||||
|
quote = self.get(f"/stock/{symbol.id}/quote")
|
||||||
|
|
||||||
|
open_change = quote.get("changePercent", 0)
|
||||||
|
after_change = quote.get("extendedChangePercent", 0)
|
||||||
|
|
||||||
|
change = 0
|
||||||
|
|
||||||
|
if open_change:
|
||||||
|
change = change + open_change
|
||||||
|
if after_change:
|
||||||
|
change = change + after_change
|
||||||
|
|
||||||
|
change = change * 100
|
||||||
|
|
||||||
|
return f"`{symbol.tag}`: {quote['companyName']}, {change:.2f}%"
|
||||||
|
|
||||||
def trending(self) -> list[str]:
|
def trending(self) -> list[str]:
|
||||||
"""Gets current coins trending on IEX. Only returns when market is open.
|
"""Gets current coins trending on IEX. Only returns when market is open.
|
||||||
|
|
||||||
|
12
cg_Crypto.py
12
cg_Crypto.py
@ -338,6 +338,18 @@ class cg_Crypto:
|
|||||||
|
|
||||||
return f"No information found for: {symbol}\nEither today is boring or the symbol does not exist."
|
return f"No information found for: {symbol}\nEither today is boring or the symbol does not exist."
|
||||||
|
|
||||||
|
def spark_reply(self, symbol: Coin) -> str:
|
||||||
|
change = self.get(
|
||||||
|
f"/simple/price",
|
||||||
|
params={
|
||||||
|
"ids": symbol.id,
|
||||||
|
"vs_currencies": self.vs_currency,
|
||||||
|
"include_24hr_change": "true",
|
||||||
|
},
|
||||||
|
)[symbol.id]["usd_24h_change"]
|
||||||
|
|
||||||
|
return f"`{symbol.tag}`: {symbol.name}, {change:.2f}%"
|
||||||
|
|
||||||
def trending(self) -> list[str]:
|
def trending(self) -> list[str]:
|
||||||
"""Gets current coins trending on coingecko
|
"""Gets current coins trending on coingecko
|
||||||
|
|
||||||
|
@ -374,6 +374,31 @@ class Router:
|
|||||||
|
|
||||||
return replies
|
return replies
|
||||||
|
|
||||||
|
def spark_reply(self, symbols: list[Symbol]) -> list[str]:
|
||||||
|
"""Gets change for each symbol and returns it in a compact format
|
||||||
|
|
||||||
|
Parameters
|
||||||
|
----------
|
||||||
|
symbols : list[str]
|
||||||
|
List of stock symbols
|
||||||
|
|
||||||
|
Returns
|
||||||
|
-------
|
||||||
|
list[str]
|
||||||
|
List of human readable strings.
|
||||||
|
"""
|
||||||
|
replies = []
|
||||||
|
|
||||||
|
for symbol in symbols:
|
||||||
|
if isinstance(symbol, Stock):
|
||||||
|
replies.append(self.stock.spark_reply(symbol))
|
||||||
|
elif isinstance(symbol, Coin):
|
||||||
|
replies.append(self.crypto.spark_reply(symbol))
|
||||||
|
else:
|
||||||
|
debug(f"{symbol} is not a Stock or Coin")
|
||||||
|
|
||||||
|
return replies
|
||||||
|
|
||||||
def trending(self) -> str:
|
def trending(self) -> str:
|
||||||
"""Checks APIs for trending symbols.
|
"""Checks APIs for trending symbols.
|
||||||
|
|
||||||
@ -398,7 +423,7 @@ class Router:
|
|||||||
][::-1][0:5]
|
][::-1][0:5]
|
||||||
|
|
||||||
for t in sorted_trending:
|
for t in sorted_trending:
|
||||||
reply += self.price_reply(self.find_symbols(t))[0] + "\n"
|
reply += self.spark_reply(self.find_symbols(t))[0] + "\n"
|
||||||
|
|
||||||
if stocks:
|
if stocks:
|
||||||
reply += "\n\n💵Trending Stocks:\n`"
|
reply += "\n\n💵Trending Stocks:\n`"
|
||||||
|
Loading…
x
Reference in New Issue
Block a user