API Documentation

Complete guide to integrating with MetalAPI

Base URL

http://www.metalapi.com/api/v1/

Getting Started

MetalAPI provides real-time and historical data for precious metals, currencies, and commodities. Our RESTful API returns JSON responses and supports HTTPS encryption.

Quick Start

  1. Sign up for a free account
  2. Get your API key from the dashboard
  3. Make your first API call

Authentication

All API requests require authentication using your API key. You can include your API key in three ways:

Method 1: Bearer Token (Recommended)

curl -H "Authorization: Bearer YOUR_API_KEY" \
     http://www.metalapi.com/api/v1/latest

Method 2: X-API-Key Header

curl -H "X-API-Key: YOUR_API_KEY" \
     http://www.metalapi.com/api/v1/latest

Method 3: Query Parameter

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.

Endpoints

Symbols

GET /v1/symbols

Get the list of all supported symbols (currencies and metals).

Example Request

curl -H "Authorization: Bearer YOUR_API_KEY" \
     "http://www.metalapi.com/api/v1/symbols"

Example Response

{
  "success": true,
  "symbols": {
    "XAU": "Gold",
    "XAG": "Silver",
    "XPT": "Platinum",
    "XPD": "Palladium",
    "USD": "US Dollar",
    "EUR": "Euro",
    "GBP": "British Pound"
  }
}

Latest Rates

GET /v1/latest

Get the latest rates for all supported symbols.

Parameters

Parameter Type Description
base string Base currency (default: USD)
currencies string Comma-separated list of currencies

Example Request

curl -H "Authorization: Bearer YOUR_API_KEY" \
     "http://www.metalapi.com/api/v1/latest?base=USD&currencies=XAU,XAG,EUR"

Example Response

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

Historical Rates

GET /v1/{date}

Get historical rates for a specific date.

Parameters

Parameter Type Description
date string Date in YYYY-MM-DD format
base string Base currency (default: USD)
currencies string Comma-separated list of currencies

Example Request

curl -H "Authorization: Bearer YOUR_API_KEY" \
     "http://www.metalapi.com/api/v1/2024-01-15?base=USD&currencies=XAU,XAG"

Example Response

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

Convert

GET /v1/convert

Convert one currency to another.

Parameters

Parameter Type Description
from string Source currency
to string Target currency
amount number Amount to convert

Example Request

curl -H "Authorization: Bearer YOUR_API_KEY" \
     "http://www.metalapi.com/api/v1/convert?from=USD&to=XAU&amount=1000"

Example Response

{
  "success": true,
  "query": {
    "from": "USD",
    "to": "XAU",
    "amount": 1000
  },
  "info": {
    "timestamp": 1748189445,
    "rate": 0.00053853
  },
  "result": 0.53853
}

Timeframe

GET /v1/timeframe

Get historical rates for a date range (max 365 days).

Parameters

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

Example Request

curl -H "Authorization: Bearer YOUR_API_KEY" \
     "http://www.metalapi.com/api/v1/timeframe?start_date=2024-01-01&end_date=2024-01-07&currencies=XAU,XAG"

Example Response

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

Change

GET /v1/change

Calculate rate changes between two dates.

Parameters

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

Example Request

curl -H "Authorization: Bearer YOUR_API_KEY" \
     "http://www.metalapi.com/api/v1/change?start_date=2024-01-01&end_date=2024-01-02&currencies=XAU"

Example Response

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

OHLC

GET /v1/ohlc

Get Open, High, Low, Close prices for a specific date.

Parameters

Parameter Type Description
date string Date (YYYY-MM-DD)
base string Base currency (default: USD)
currencies string Comma-separated list of currencies

Example Request

curl -H "Authorization: Bearer YOUR_API_KEY" \
     "http://www.metalapi.com/api/v1/ohlc?date=2024-01-01&currencies=XAU"

Example Response

{
  "success": true,
  "ohlc": true,
  "date": "2024-01-01",
  "base": "USD",
  "rates": {
    "XAU": {
      "open": 0.0005277594,
      "high": 0.0005654565,
      "low": 0.0005116035,
      "close": 0.00053853
    }
  }
}

Carat

GET /v1/carat

Get gold prices by carat (available for paid plans).

Parameters

Parameter Type Description
carat string Gold carat (8, 10, 14, 18, 22, 24)
base string Base currency (default: USD)

Example Request

curl -H "Authorization: Bearer YOUR_API_KEY" \
     "http://www.metalapi.com/api/v1/carat?carat=24"

Example Response

{
  "success": true,
  "carat": "24",
  "date": "2025-05-27",
  "base": "USD",
  "timestamp": 1748336188,
  "rates": {
    "XAU24K": {
      "price": 1856.9,
      "unit": "troy_oz",
      "carat": "24"
    }
  }
}

Usage

GET /v1/usage

Get API usage statistics for your account.

Example Request

curl -H "Authorization: Bearer YOUR_API_KEY" \
     "http://www.metalapi.com/api/v1/usage"

Example Response

{
  "success": true,
  "usage": {
    "requests_made": 15,
    "requests_quota": 1000,
    "requests_remaining": 985,
    "plan": "lite"
  }
}

Rate Limits

API rate limits are based on your subscription plan. Requests are counted monthly and reset on the first day of each month.

Subscription Plans

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

Rate Limit Headers

Every API response includes rate limit information in the headers:

X-RateLimit-Limit: 1000
X-RateLimit-Remaining: 985
X-RateLimit-Reset: 1748189445

Error Codes

When an error occurs, the API returns a JSON response with error details:

Error Response Format

{
  "success": false,
  "error": {
    "code": 101,
    "type": "no_api_key",
    "info": "You have not supplied an API Access Key."
  }
}

Error Codes

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

Code Examples

JavaScript (Node.js)

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();

Python

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)

PHP

Error: 0
null

cURL

# Get latest rates
curl -H "Authorization: Bearer YOUR_API_KEY" \
     "http://www.metalapi.com/api/v1/latest?base=USD&currencies=XAU,XAG,EUR"

# Get historical rates
curl -H "Authorization: Bearer YOUR_API_KEY" \
     "http://www.metalapi.com/api/v1/2024-01-15?base=USD&currencies=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&currencies=XAU"

# Get usage statistics
curl -H "Authorization: Bearer YOUR_API_KEY" \
     "http://www.metalapi.com/api/v1/usage"

Widgets

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.

Widget Features

  • • Real-time data updates based on your subscription plan
  • • Multiple themes (Light, Dark, Blue, Green, Purple)
  • • Three sizes (Small, Medium, Large)
  • • Responsive design for all devices
  • • Easy integration with any website
  • • Customizable symbols and display options

Widget Generator

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.

Access the Widget Generator:

Generator Features:

  • Live preview with real data
  • Symbol selection (metals & currencies)
  • Theme and size customization
  • Copy embed code to clipboard
  • Save and manage widgets

Usage Statistics:

  • Real-time request tracking
  • Plan-based rate limiting
  • Monthly usage overview
  • Reset date information

Integration Guide

Integrating MetalAPI widgets into your website is simple and requires just a few lines of code.

Step 1: Include the Widget Script

<script src="http://www.metalapi.com/js/widget.js"></script>

Step 2: Create a Container

<div id="my-metal-widget"></div>

Step 3: Initialize the Widget

<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>

Configuration Options

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

Live Examples

Here are some live examples of MetalAPI widgets in different configurations:

Light Theme - Medium

Light theme widget preview

XAU, XAG, XPT

theme: 'light', size: 'medium'

Dark Theme - Large

Dark theme widget preview

USD, EUR, GBP

theme: 'dark', size: 'large'

Blue Theme - Small

Blue theme widget preview

XAU, USD

theme: 'blue', size: 'small'

Pro Tip

Use the Widget Generator to see live previews and get the exact embed code for your desired configuration.

Advanced Usage

Multiple Widgets

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'
});

Widget Methods

Control your widgets programmatically:

// Manually refresh data
widget.refresh();

// Update configuration
widget.updateConfig({
    symbols: ['XAU', 'XAG', 'XPT'],
    theme: 'dark'
});

// Destroy widget
widget.destroy();

Event Handling

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);
    }
});

Support

Need help with the API? We're here to assist you!

Email Support

[email protected]

Response within 24 hours

Documentation

Comprehensive guides and examples

Always up-to-date