Complete guide to integrating with MetalAPI
Base URL
http://www.metalapi.com/api/v1/
MetalAPI provides real-time and historical data for precious metals, currencies, and commodities. Our RESTful API returns JSON responses and supports HTTPS encryption.
All API requests require authentication using your API key. You can include your API key in three ways:
curl -H "Authorization: Bearer YOUR_API_KEY" \
http://www.metalapi.com/api/v1/latest
curl -H "X-API-Key: YOUR_API_KEY" \
http://www.metalapi.com/api/v1/latest
curl "http://www.metalapi.com/api/v1/latest?api_key=YOUR_API_KEY"
Test API Key: For testing purposes, you can use: test-api-key-12345
Important: Keep your API key secure and never expose it in client-side code.
GET /v1/symbols
Get the list of all supported symbols (currencies and metals).
curl -H "Authorization: Bearer YOUR_API_KEY" \
"http://www.metalapi.com/api/v1/symbols"
{
"success": true,
"symbols": {
"XAU": "Gold",
"XAG": "Silver",
"XPT": "Platinum",
"XPD": "Palladium",
"USD": "US Dollar",
"EUR": "Euro",
"GBP": "British Pound"
}
}
GET /v1/latest
Get the latest rates for all supported symbols.
Parameter | Type | Description |
---|---|---|
base | string | Base currency (default: USD) |
currencies | string | Comma-separated list of currencies |
curl -H "Authorization: Bearer YOUR_API_KEY" \
"http://www.metalapi.com/api/v1/latest?base=USD¤cies=XAU,XAG,EUR"
{
"success": true,
"timestamp": 1748189445,
"base": "USD",
"date": "2025-05-27",
"rates": {
"XAU": 0.00053853,
"USDXAU": 1856.906765,
"XAG": 0.032,
"USDXAG": 31.25,
"EUR": 0.8255334,
"USDEUR": 1.211338027
}
}
GET /v1/{date}
Get historical rates for a specific date.
Parameter | Type | Description |
---|---|---|
date | string | Date in YYYY-MM-DD format |
base | string | Base currency (default: USD) |
currencies | string | Comma-separated list of currencies |
curl -H "Authorization: Bearer YOUR_API_KEY" \
"http://www.metalapi.com/api/v1/2024-01-15?base=USD¤cies=XAU,XAG"
{
"success": true,
"timestamp": 1705363200,
"historical": true,
"date": "2024-01-15",
"base": "USD",
"rates": {
"XAU": 0.00053853,
"USDXAU": 1856.906765,
"XAG": 0.032,
"USDXAG": 31.25
}
}
GET /v1/convert
Convert one currency to another.
Parameter | Type | Description |
---|---|---|
from | string | Source currency |
to | string | Target currency |
amount | number | Amount to convert |
curl -H "Authorization: Bearer YOUR_API_KEY" \
"http://www.metalapi.com/api/v1/convert?from=USD&to=XAU&amount=1000"
{
"success": true,
"query": {
"from": "USD",
"to": "XAU",
"amount": 1000
},
"info": {
"timestamp": 1748189445,
"rate": 0.00053853
},
"result": 0.53853
}
GET /v1/timeframe
Get historical rates for a date range (max 365 days).
Parameter | Type | Description |
---|---|---|
start_date | string | Start date (YYYY-MM-DD) |
end_date | string | End date (YYYY-MM-DD) |
base | string | Base currency (default: USD) |
currencies | string | Comma-separated list of currencies |
curl -H "Authorization: Bearer YOUR_API_KEY" \
"http://www.metalapi.com/api/v1/timeframe?start_date=2024-01-01&end_date=2024-01-07¤cies=XAU,XAG"
{
"success": true,
"timeframe": true,
"start_date": "2024-01-01",
"end_date": "2024-01-07",
"base": "USD",
"rates": {
"2024-01-01": {
"XAU": 0.00053853,
"USDXAU": 1856.906765,
"XAG": 0.032,
"USDXAG": 31.25
},
"2024-01-02": {
"XAU": 0.00053853,
"USDXAU": 1856.906765,
"XAG": 0.032,
"USDXAG": 31.25
}
}
}
GET /v1/change
Calculate rate changes between two dates.
Parameter | Type | Description |
---|---|---|
start_date | string | Start date (YYYY-MM-DD) |
end_date | string | End date (YYYY-MM-DD) |
base | string | Base currency (default: USD) |
currencies | string | Comma-separated list of currencies |
curl -H "Authorization: Bearer YOUR_API_KEY" \
"http://www.metalapi.com/api/v1/change?start_date=2024-01-01&end_date=2024-01-02¤cies=XAU"
{
"success": true,
"change": true,
"start_date": "2024-01-01",
"end_date": "2024-01-02",
"base": "USD",
"rates": {
"XAU": {
"start_rate": 0.00053853,
"end_rate": 0.00053853,
"change": 0,
"change_pct": 0
}
}
}
GET /v1/ohlc
Get Open, High, Low, Close prices for a specific date.
Parameter | Type | Description |
---|---|---|
date | string | Date (YYYY-MM-DD) |
base | string | Base currency (default: USD) |
currencies | string | Comma-separated list of currencies |
curl -H "Authorization: Bearer YOUR_API_KEY" \
"http://www.metalapi.com/api/v1/ohlc?date=2024-01-01¤cies=XAU"
{
"success": true,
"ohlc": true,
"date": "2024-01-01",
"base": "USD",
"rates": {
"XAU": {
"open": 0.0005277594,
"high": 0.0005654565,
"low": 0.0005116035,
"close": 0.00053853
}
}
}
GET /v1/carat
Get gold prices by carat (available for paid plans).
Parameter | Type | Description |
---|---|---|
carat | string | Gold carat (8, 10, 14, 18, 22, 24) |
base | string | Base currency (default: USD) |
curl -H "Authorization: Bearer YOUR_API_KEY" \
"http://www.metalapi.com/api/v1/carat?carat=24"
{
"success": true,
"carat": "24",
"date": "2025-05-27",
"base": "USD",
"timestamp": 1748336188,
"rates": {
"XAU24K": {
"price": 1856.9,
"unit": "troy_oz",
"carat": "24"
}
}
}
GET /v1/usage
Get API usage statistics for your account.
curl -H "Authorization: Bearer YOUR_API_KEY" \
"http://www.metalapi.com/api/v1/usage"
{
"success": true,
"usage": {
"requests_made": 15,
"requests_quota": 1000,
"requests_remaining": 985,
"plan": "lite"
}
}
API rate limits are based on your subscription plan. Requests are counted monthly and reset on the first day of each month.
Plan | Monthly Requests | Update Interval | Features |
---|---|---|---|
Free | 100 | Daily | Basic endpoints, Email support |
Lite | 1,000 | 30 minutes | All endpoints, Basic analytics |
Standard | 10,000 | 10 minutes | Priority support, Advanced analytics |
Advanced | 50,000 | 60 seconds | Webhook support, Custom domains |
Pro | 100,000 | 60 seconds | Premium support, White-label options |
Ultra | 500,000 | 15 seconds | Dedicated support, White-label |
Business | 500,000 | 15 seconds | SLA guarantee, Dedicated support |
Enterprise | 1,500,000 | 5 seconds | Custom integrations, Enterprise support |
Every API response includes rate limit information in the headers:
X-RateLimit-Limit: 1000
X-RateLimit-Remaining: 985
X-RateLimit-Reset: 1748189445
When an error occurs, the API returns a JSON response with error details:
{
"success": false,
"error": {
"code": 101,
"type": "no_api_key",
"info": "You have not supplied an API Access Key."
}
}
Code | Type | Description |
---|---|---|
101 | no_api_key | No API key provided |
102 | invalid_api_key | Invalid API key |
103 | quota_exceeded | Monthly quota exceeded |
104 | invalid_base | Invalid base currency |
105 | invalid_symbols | Invalid currency symbols |
106 | invalid_date | Invalid date format |
300 | function_access_restricted | Feature not available for your plan |
404 | endpoint_not_found | Endpoint not found |
const axios = require('axios');
const apiKey = 'YOUR_API_KEY';
const baseUrl = 'http://www.metalapi.com/api/v1';
// Get latest rates
async function getLatestRates() {
try {
const response = await axios.get(`${baseUrl}/latest`, {
headers: {
'Authorization': `Bearer ${apiKey}`
},
params: {
base: 'USD',
currencies: 'XAU,XAG,EUR'
}
});
console.log(response.data);
} catch (error) {
console.error('Error:', error.response.data);
}
}
// Convert currency
async function convertCurrency() {
try {
const response = await axios.get(`${baseUrl}/convert`, {
headers: {
'Authorization': `Bearer ${apiKey}`
},
params: {
from: 'USD',
to: 'XAU',
amount: 1000
}
});
console.log(`1000 USD = ${response.data.result} XAU`);
} catch (error) {
console.error('Error:', error.response.data);
}
}
getLatestRates();
convertCurrency();
import requests
import json
API_KEY = 'YOUR_API_KEY'
BASE_URL = 'http://www.metalapi.com/api/v1'
def get_latest_rates():
"""Get latest exchange rates"""
headers = {
'Authorization': f'Bearer {API_KEY}'
}
params = {
'base': 'USD',
'currencies': 'XAU,XAG,EUR'
}
response = requests.get(f'{BASE_URL}/latest', headers=headers, params=params)
if response.status_code == 200:
data = response.json()
print(json.dumps(data, indent=2))
else:
print(f'Error: {response.status_code}')
print(response.json())
def convert_currency(from_currency, to_currency, amount):
"""Convert one currency to another"""
headers = {
'Authorization': f'Bearer {API_KEY}'
}
params = {
'from': from_currency,
'to': to_currency,
'amount': amount
}
response = requests.get(f'{BASE_URL}/convert', headers=headers, params=params)
if response.status_code == 200:
data = response.json()
print(f'{amount} {from_currency} = {data["result"]} {to_currency}')
else:
print(f'Error: {response.status_code}')
print(response.json())
# Example usage
get_latest_rates()
convert_currency('USD', 'XAU', 1000)
Error: 0
null
# Get latest rates
curl -H "Authorization: Bearer YOUR_API_KEY" \
"http://www.metalapi.com/api/v1/latest?base=USD¤cies=XAU,XAG,EUR"
# Get historical rates
curl -H "Authorization: Bearer YOUR_API_KEY" \
"http://www.metalapi.com/api/v1/2024-01-15?base=USD¤cies=XAU,XAG"
# Convert currency
curl -H "Authorization: Bearer YOUR_API_KEY" \
"http://www.metalapi.com/api/v1/convert?from=USD&to=XAU&amount=1000"
# Get timeframe data
curl -H "Authorization: Bearer YOUR_API_KEY" \
"http://www.metalapi.com/api/v1/timeframe?start_date=2024-01-01&end_date=2024-01-07¤cies=XAU"
# Get usage statistics
curl -H "Authorization: Bearer YOUR_API_KEY" \
"http://www.metalapi.com/api/v1/usage"
MetalAPI provides embeddable widgets that allow you to display real-time metal and currency rates directly on your website. Our widgets are fully customizable, responsive, and automatically update based on your subscription plan.
Use our interactive widget generator to create customized widgets for your website. The generator provides a live preview and generates the embed code for you.
Integrating MetalAPI widgets into your website is simple and requires just a few lines of code.
<script src="http://www.metalapi.com/js/widget.js"></script>
<div id="my-metal-widget"></div>
<script>
new MetalAPIWidget({
widgetId: 'my-metal-widget',
apiKey: 'YOUR_API_KEY',
baseUrl: 'http://www.metalapi.com',
symbols: ['XAU', 'XAG', 'XPT'],
type: 'metal',
theme: 'light',
size: 'medium',
showChange: true,
showPercentage: true,
autoRefresh: true
});
</script>
Option | Type | Default | Description |
---|---|---|---|
widgetId |
string | required | ID of the container element |
apiKey |
string | required | Your MetalAPI key |
symbols |
array | [] | Array of symbols to display (max 10) |
type |
string | 'metal' | 'metal' or 'currency' |
theme |
string | 'light' | 'light', 'dark', 'blue', 'green', 'purple' |
size |
string | 'medium' | 'small', 'medium', 'large' |
showChange |
boolean | false | Show price change indicators |
showPercentage |
boolean | false | Show percentage changes |
autoRefresh |
boolean | true | Enable automatic updates |
Here are some live examples of MetalAPI widgets in different configurations:
Light theme widget preview
XAU, XAG, XPT
theme: 'light', size: 'medium'
Dark theme widget preview
USD, EUR, GBP
theme: 'dark', size: 'large'
Blue theme widget preview
XAU, USD
theme: 'blue', size: 'small'
Use the Widget Generator to see live previews and get the exact embed code for your desired configuration.
You can create multiple widgets on the same page with different configurations:
// Metal prices widget
const metalWidget = new MetalAPIWidget({
widgetId: 'metals',
apiKey: 'your-key',
baseUrl: 'http://www.metalapi.com',
symbols: ['XAU', 'XAG'],
type: 'metal',
theme: 'light'
});
// Currency rates widget
const currencyWidget = new MetalAPIWidget({
widgetId: 'currencies',
apiKey: 'your-key',
baseUrl: 'http://www.metalapi.com',
symbols: ['USD', 'EUR'],
type: 'currency',
theme: 'dark'
});
Control your widgets programmatically:
// Manually refresh data
widget.refresh();
// Update configuration
widget.updateConfig({
symbols: ['XAU', 'XAG', 'XPT'],
theme: 'dark'
});
// Destroy widget
widget.destroy();
Listen to widget events:
const widget = new MetalAPIWidget({
// ... configuration
onDataUpdate: function(data) {
console.log('Widget data updated:', data);
},
onError: function(error) {
console.error('Widget error:', error);
}
});
Need help with the API? We're here to assist you!
Comprehensive guides and examples
Always up-to-date