mirror of
https://gitlab.com/simple-stock-bots/simple-stock-bot.git
synced 2025-07-22 06:01:40 +00:00
Resolve "inline functionality is broken"
This commit is contained in:
@@ -103,7 +103,7 @@ class MarketData:
|
||||
)
|
||||
status.raise_for_status()
|
||||
except r.HTTPError:
|
||||
return f"API returned an HTTP error code {status.status_code} in {status.elapsed.total_seconds()} Seconds."
|
||||
return f"API returned an HTTP error code {status.status_code} in {status.elapsed.total_seconds()} seconds."
|
||||
except r.Timeout:
|
||||
return "API timed out before it was able to give status. This is likely due to a surge in usage or a complete outage."
|
||||
|
||||
@@ -111,7 +111,7 @@ class MarketData:
|
||||
|
||||
if statusJSON["status"] == "ok":
|
||||
return (
|
||||
f"CoinGecko API responded that it was OK with a {status.status_code} in {status.elapsed.total_seconds()} Seconds."
|
||||
f"CoinGecko API responded that it was OK with a {status.status_code} in {status.elapsed.total_seconds()} seconds."
|
||||
)
|
||||
else:
|
||||
return f"MarketData.app is currently reporting the following status: {statusJSON['status']}"
|
||||
@@ -131,7 +131,11 @@ class MarketData:
|
||||
|
||||
if quoteResp := self.get(f"stocks/quotes/{symbol}/"):
|
||||
price = round(quoteResp["last"][0], 2)
|
||||
changePercent = round(quoteResp["changepct"][0], 2)
|
||||
|
||||
try:
|
||||
changePercent = round(quoteResp["changepct"][0], 2)
|
||||
except TypeError:
|
||||
return f"The price of {symbol} is {price}"
|
||||
|
||||
message = f"The current price of {symbol.name} is ${price} and "
|
||||
|
||||
@@ -148,11 +152,13 @@ class MarketData:
|
||||
|
||||
def spark_reply(self, symbol: Stock) -> str:
|
||||
if quoteResp := self.get(f"stocks/quotes/{symbol}/"):
|
||||
changePercent = round(quoteResp["changepct"][0], 2)
|
||||
return f"`{symbol.tag}`: {changePercent}%"
|
||||
else:
|
||||
logging.warning(f"{symbol} did not have 'changepct' field.")
|
||||
return f"`{symbol.tag}`"
|
||||
try:
|
||||
changePercent = round(quoteResp["changepct"][0], 2)
|
||||
return f"`{symbol.tag}`: {changePercent}%"
|
||||
except TypeError:
|
||||
pass
|
||||
|
||||
return f"`{symbol.tag}`"
|
||||
|
||||
def intra_reply(self, symbol: Stock) -> pd.DataFrame:
|
||||
"""Returns price data for a symbol of the past month up until the previous trading days close.
|
||||
|
@@ -77,10 +77,10 @@ class cg_Crypto:
|
||||
try:
|
||||
status.raise_for_status()
|
||||
return (
|
||||
f"CoinGecko API responded that it was OK with a {status.status_code} in {status.elapsed.total_seconds()} Seconds."
|
||||
f"CoinGecko API responded that it was OK with a {status.status_code} in {status.elapsed.total_seconds()} seconds."
|
||||
)
|
||||
except r.HTTPError:
|
||||
return f"CoinGecko API returned an error code {status.status_code} in {status.elapsed.total_seconds()} Seconds."
|
||||
return f"CoinGecko API returned an error code {status.status_code} in {status.elapsed.total_seconds()} seconds."
|
||||
|
||||
def price_reply(self, coin: Coin) -> str:
|
||||
"""Returns current market price or after hours if its available for a given coin symbol.
|
||||
|
@@ -123,7 +123,8 @@ class Router:
|
||||
Each tuple contains: (Symbol, Issue Name).
|
||||
"""
|
||||
|
||||
df = pd.concat([self.stock.symbol_list, self.crypto.symbol_list])
|
||||
# df = pd.concat([self.stock.symbol_list, self.crypto.symbol_list])
|
||||
df = self.crypto.symbol_list
|
||||
|
||||
df = df[df["description"].str.contains(search, regex=False, case=False)].sort_values(
|
||||
by="type_id", key=lambda x: x.str.len()
|
||||
@@ -338,8 +339,8 @@ class Router:
|
||||
reply += self.spark_reply(self.find_symbols(t))[0] + "\n"
|
||||
|
||||
if coins:
|
||||
reply += "\n\n🦎Trending Crypto:\n`"
|
||||
reply += "━" * len("Trending Crypto:") + "`\n"
|
||||
reply += "\n\n🦎Trending on CoinGecko:\n`"
|
||||
reply += "━" * len("Trending on CoinGecko:") + "`\n"
|
||||
for coin in coins:
|
||||
reply += coin + "\n"
|
||||
|
||||
@@ -353,7 +354,8 @@ class Router:
|
||||
return "Trending data is not currently available."
|
||||
|
||||
def random_pick(self) -> str:
|
||||
choice = random.choice(list(self.stock.symbol_list["description"]) + list(self.crypto.symbol_list["description"]))
|
||||
# choice = random.choice(list(self.stock.symbol_list["description"]) + list(self.crypto.symbol_list["description"]))
|
||||
choice = random.choice(list(self.crypto.symbol_list["description"]))
|
||||
hold = (datetime.date.today() + datetime.timedelta(random.randint(1, 365))).strftime("%b %d, %Y")
|
||||
|
||||
return f"{choice}\nBuy and hold until: {hold}"
|
||||
|
Reference in New Issue
Block a user