【问题标题】:How do I get just the current price with Alpha Vantage API如何使用 Alpha Vantage API 获取当前价格
【发布时间】:2021-02-21 00:17:53
【问题描述】:

我一直在使用 python Alpha Vantage API 来获取有关比特币的数据,但现在我只需要获取价格。我的代码给了我这个输出,

{"Realtime Currency Exchange Rate": {"1. From_Currency Code": "BTC", "2. From_Currency Name": "Bitcoin", "3. To_Currency Code": "USD", "4. To_Currency Name": "United States Dollar", "5. Exchange Rate": "56057.81000000", "6. Last Refreshed": "2021-02-20 23:55:01", "7. Time Zone": "UTC", "8. Bid Price": "56057.50000000", "9. Ask Price": "56057.81000000"}}

而我需要把它减到 5 个。

56057.81000000

【问题讨论】:

标签: python stock alpha-vantage


【解决方案1】:

您需要访问Realtime Currency Exchange Rate 键内的5. Exchange_Rate 键,即:

j_obj = {"Realtime Currency Exchange Rate": {"1. From_Currency Code": "BTC", "2. From_Currency Name": "Bitcoin", "3. To_Currency Code": "USD", "4. To_Currency Name": "United States Dollar", "5. Exchange Rate": "56057.81000000", "6. Last Refreshed": "2021-02-20 23:55:01", "7. Time Zone": "UTC", "8. Bid Price": "56057.50000000", "9. Ask Price": "56057.81000000"}}

exchange_rate = j_obj["Realtime Currency Exchange Rate"]["5. Exchange Rate"]
print(exchange_rate)
# 56057.81000000

Demo

【讨论】:

    猜你喜欢
    • 2020-07-31
    • 2022-10-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-06-12
    • 2020-05-11
    • 2019-02-16
    • 1970-01-01
    相关资源
    最近更新 更多