如何使用 Alpha Vantage API 获取当前价格
How do I get just the current price with Alpha Vantage API
我一直在使用 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
"
您需要访问 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
我一直在使用 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
"
您需要访问 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