【问题标题】:How do I get my bot to show the price of BTC?如何让我的机器人显示 BTC 的价格?
【发布时间】:2022-01-08 13:26:44
【问题描述】:

所以我最近一直在尝试使用 yfinance API 在我的 discord 机器人中构建一个比特币价格跟踪器,但是每当我运行命令时它都不会显示价格,有人知道怎么做吗?对于上下文,这是我总是得到的结果:

Open  ...       Volume
Date                      ...
2022-01-08  36663.851562  ...  71013384192

[1 rows x 6 columns]

这是代码

@bot.command(name='BTCstalker', help='Posts updates on BTC.')
async def cyrdat(ctx):
    cryptoData = yf.download(tickers="BTC-EUR", period='1d', interval='1d')
    content = (cryptoData)
    await ctx.send(content)

【问题讨论】:

标签: python discord discord.py bots yfinance


【解决方案1】:

获取美元价格

import requests
response = requests.get('https://api.coindesk.com/v1/bpi/currentprice.json')
data = response.json()
price = data["bpi"]["USD"]["rate"]

import requests
data = requests.get('https://api.coindesk.com/v1/bpi/currentprice.json').json()["bpi"]["USD"]["rate"]

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-12-17
    • 2020-09-10
    • 1970-01-01
    • 2021-05-11
    • 2020-08-11
    • 2019-06-29
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多