1
0
mirror of https://gitlab.com/simple-stock-bots/simple-telegram-stock-bot.git synced 2025-06-16 15:06:53 +00:00
This commit is contained in:
Anson Biggs 2021-02-04 21:29:19 -07:00
parent 6dd033b7c2
commit ecbbfcd9d6

View File

@ -168,15 +168,22 @@ _Donations can only be made in a chat directly with @simplestockbot_
response = r.get(IEXurl) response = r.get(IEXurl)
if response.status_code == 200: if response.status_code == 200:
IEXData = response.json() IEXData = response.json()
message = f"The current stock price of {IEXData['companyName']} is $**{IEXData['latestPrice']}**"
if IEXData["isUSMarketOpen"]: # Check if market is open.
message = f"The current stock price of {IEXData['companyName']} is $**{IEXData['latestPrice']}**"
change = round(IEXData["changePercent"] * 100, 2)
else:
message = f"{IEXData['companyName']} closed at $**{IEXData['latestPrice']}**, after hours _(15 minute delayed)_ stock price is $**{IEXData['extendedPrice']}**"
change = round(IEXData["extendedChangePercent"] * 100, 2)
# Determine wording of change text # Determine wording of change text
change = round(IEXData["changePercent"] * 100, 2)
if change > 0: if change > 0:
message += f", the stock is currently **up {change}%**" message += f", the stock is currently **up {change}%**"
elif change < 0: elif change < 0:
message += f", the stock is currently **down {change}%**" message += f", the stock is currently **down {change}%**"
else: else:
message += ", the stock hasn't shown any movement today." message += ", the stock hasn't shown any movement today."
else: else:
message = f"The symbol: {symbol} was not found." message = f"The symbol: {symbol} was not found."