python - python上的价格令牌电报机器人
问题描述
我对使用 coinmarketcap API 的电报机器人中的加密价格有疑问
机器人工作正常,但电报上的价格有太多零:coin=[7.68321846e-06]$,实际价格为 0.00000768$
我该如何修改这个?提前致谢!
# global variables
api_key = '-----'
bot_token = '----'
chat_id = '-----'
market_symbol = 'coin'
currency_iso = 'USD'
time_interval = 5 * 60 # in seconds
def get_coin_price():
url = 'https://pro-api.coinmarketcap.com/v1/cryptocurrency/quotes/latest'
query = '?symbol=' + market_symbol + '&convert=' + currency_iso
headers = {
'Accepts': 'application/json',
'X-CMC_PRO_API_KEY': api_key
}
# make a request to the coinmarketcap api
response = requests.get(url + query, headers=headers)
response_json = response.json()
# extract the coin price from the json data
coin_price = response_json['data'][market_symbol]
return coin_price['quote'][currency_iso]['price']
# fn to send_message through telegram
def send_message(chat_id, msg):
url = f"https://api.telegram.org/bot{bot_token}/sendMessage?chat_id={chat_id}&text=coin={msg}$"
解决方案
推荐阅读
- javascript - 如何在数据库中包含引号的文本框中设置值?
- reactjs - React Native 属性只能在对象上定义
- c# - 如何在模态引导程序中从发布操作显示确认消息
- snort - 如何在 Snort 中创建内容规则
- oracle - 从 Oracle 并发获取时间戳加序列
- php - 一些关于 array_search 的 php 编码,结果出乎意料
- android - onLocationChanged 未在 android Q (android 10) 上调用
- android - 无需请求权限的 Android 读写 - Theta
- python - 当我向 watson 的 api 发送文本消息时,Watson 对话节点不会调用该操作
- javascript - 如何使用 JavaScript 设置 SVG 元素的大小?