mirror of
https://gitlab.com/simple-stock-bots/simple-telegram-stock-bot.git
synced 2025-06-16 15:06:53 +00:00
Merge branch '93-add-change-percent-to-market-data' into 'master'
Resolve "Add change percent to Market Data" Closes #93 See merge request simple-stock-bots/simple-telegram-stock-bot!41
This commit is contained in:
commit
86349deba4
@ -101,8 +101,19 @@ class MarketData:
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
if quoteResp := self.get(f"stocks/quotes/{symbol}/"):
|
if quoteResp := self.get(f"stocks/quotes/{symbol}/"):
|
||||||
return f"The current price of {quoteResp['symbol']} is ${quoteResp['last']}"
|
price = round(quoteResp["last"][0], 2)
|
||||||
|
changePercent = round(quoteResp["changepct"][0], 2)
|
||||||
|
|
||||||
|
message = f"The current price of {symbol.name} is ${price} and "
|
||||||
|
|
||||||
|
if changePercent > 0.0:
|
||||||
|
message += f"is currently up {changePercent}% for the day."
|
||||||
|
elif changePercent < 0.0:
|
||||||
|
message += f"is currently down {changePercent}% for the day."
|
||||||
|
else:
|
||||||
|
message += "hasn't shown any movement for the day."
|
||||||
|
|
||||||
|
return message
|
||||||
else:
|
else:
|
||||||
return f"Getting a quote for {symbol} encountered an error."
|
return f"Getting a quote for {symbol} encountered an error."
|
||||||
|
|
||||||
|
@ -32,8 +32,8 @@ class Stock(Symbol):
|
|||||||
def __init__(self, symbol: str) -> None:
|
def __init__(self, symbol: str) -> None:
|
||||||
self.symbol = symbol
|
self.symbol = symbol
|
||||||
self.id = symbol
|
self.id = symbol
|
||||||
self.name = "$" + symbol
|
self.name = "$" + symbol.upper()
|
||||||
self.tag = "$" + symbol.upper()
|
self.tag = "$" + symbol.lower()
|
||||||
|
|
||||||
|
|
||||||
class Coin(Symbol):
|
class Coin(Symbol):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user