The Metals-API is capable of providing real-time precious metals rate data, thanks to its 10+ exchange rate data sources. There are several endpoints in the API, each of which has a different function. Get the most recent exchange rate data for any or a particular group of currencies, translate sums from one currency to another, retrieve Time-Series data for one or more currencies, and ask the API for regular fluctuation data are all endpoint functionalities.
You’ll know about API structure, processes, possible bugs, and code samples in this tutorial.
STEP 1: GET YOUR METALS-API API KEY
- Go to https://metals-api.com/ and press GET API KEY in the top right corner
- They have a range of plans, but we’ll begin with the free one for this instance. Select Get API Key from the drop-down menu.
- You’ll be required to create an account, after which you’ll get a verification email. You will be driven to the most recent Metals-API dashboard when you click on the email to check your account. Click the ‘Dashboard’ button in the left-hand sidebar.
- Your API access key should now be visible to you. Make a copy of it and safely store it; we’ll need it later. The Metals API is now available to you.
STEP 2: CREATE YOUR API REQUEST
There are 5 main API Endpoints through which you can access different kinds of data, all starting out with this Base URL:
Simply attach your unique Access Key to one of the endpoints as a query parameter:
- API root: https://metals-api.com/api
- Endpoint: /latest
- Query strings: ?base=USD&symbols=XAU,XAG&access_key=YOUR_ACCESS_KEY
When we bring it all together, we get the full API Request URL:
- Latest rates endpoint: Returns real-time exchange rate data for all available or a specific set of currencies.
- Convert endpoint: This allows you to convert any number from one currency to another.
- Historical rates endpoint: Returns historical exchange rate data for all available currencies or a selection of them.
- Time-Series data endpoint: Returns daily historical exchange rate data between two specified dates for all available or a specific set of currencies.
- Fluctuation data endpoint: Returns fluctuation data between two specified dates for all available or a specific set of currencies.
Observations: You must divide all metals prices you get by one. Metals API returns values in the base currency. For eg, the return on one dollar is 0.000634 for gold (XAU).
To get the gold rate in USD: 1/0.000634= 1577.28 USD. Gold rate (XAU)
Also published on Medium.