简体   繁体   中英

How do I get just the current price with Alpha Vantage API

I've been using the python Alpha Vantage API to get data about Bitcoin but now I need to get just the price. My code gives me this output,

{"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"}}

and I need to get this to just 5.

" 56057.81000000 "

You need to access the 5. Exchange_Rate key inside Realtime Currency Exchange Rate key, ie:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM