Created
June 17, 2022 16:47
-
-
Save StevenTso/557306aa74a40ef1ec5a75856e54aa74 to your computer and use it in GitHub Desktop.
Get gold price in Python
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import requests | |
# get price in USD | |
url = 'https://api.metalpriceapi.com/v1/latest?api_key=[API_KEY]&base=USD¤cies=XAU' | |
r = requests.get(url) | |
gold_dict = r.json() | |
rate = gold_dict["rates"]["XAU"] | |
gold_price = 1/rate | |
print(gold_price) | |
# get price is MXN | |
url = 'https://api.metalpriceapi.com/v1/latest?api_key=[API_KEY]&base=MXN¤cies=XAU' | |
r = requests.get(url) | |
gold_dict = r.json() | |
rate = gold_dict["rates"]["XAU"] | |
gold_price = 1/rate | |
print(gold_price) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment