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