mirror of
https://gitlab.com/simple-stock-bots/simple-stock-bot.git
synced 2025-06-16 15:17:28 +00:00
This commit is contained in:
parent
c4d984a751
commit
f184fbe51d
4
bot.py
4
bot.py
@ -197,13 +197,13 @@ def crypto(update, context):
|
||||
)
|
||||
message = update.message.text
|
||||
|
||||
reply = s.crypto(message)
|
||||
reply = s.crypto_reply(message)
|
||||
|
||||
if reply:
|
||||
update.message.reply_text(text=reply, parse_mode=telegram.ParseMode.MARKDOWN)
|
||||
else:
|
||||
update.message.reply_text(
|
||||
text=f"Pair: f{message} returned an error.",
|
||||
text=f"Pair: {message} returned an error.",
|
||||
parse_mode=telegram.ParseMode.MARKDOWN,
|
||||
)
|
||||
|
||||
|
@ -268,7 +268,7 @@ Market data is provided by [IEX Cloud](https://iexcloud.io)
|
||||
|
||||
return infoMessages
|
||||
|
||||
def crypto(self, pair):
|
||||
def crypto_reply(self, pair):
|
||||
"""Get quote for a cryptocurrency pair.
|
||||
|
||||
Args:
|
||||
@ -276,6 +276,8 @@ Market data is provided by [IEX Cloud](https://iexcloud.io)
|
||||
"""
|
||||
|
||||
pair = pair.split(" ")[-1].replace("/", "").upper()
|
||||
pair += "USD" if len(pair) == 3 else pair
|
||||
|
||||
IEXurl = f"https://cloud.iexapis.com/stable/crypto/{pair}/quote?token={self.IEX_TOKEN}"
|
||||
|
||||
response = r.get(IEXurl)
|
||||
@ -284,8 +286,7 @@ Market data is provided by [IEX Cloud](https://iexcloud.io)
|
||||
data = response.json()
|
||||
|
||||
quote = f"Symbol: {data['symbol']}\n"
|
||||
quote += f"Price: {data['latestPrice']}\n"
|
||||
quote += f"Volume: {data['latestVolume']}\n"
|
||||
quote += f"Price: ${data['latestPrice']}\n"
|
||||
|
||||
new, old = data["latestPrice"], data["previousClose"]
|
||||
if old is not None:
|
||||
|
Loading…
x
Reference in New Issue
Block a user