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" \
     https://metalapi.com/api/v1/latest

Method 2: X-API-Key Header

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

Method 3: Query Parameter

curl "https://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 "https://metalapi.com/api/v1/symbols?api_key=YOUR_API_KEY"

Example Response

{
  "success": true,
  "symbols": {
    "XAU": "Gold",
    "XAG": "Silver",
    "XPT": "Platinum",
    "XPD": "Palladium",
    "USD": "US Dollar",
    "EUR": "Euro",
    "GBP": "British Pound"
  },
  "rate_limit": {
    "limit": 10000,
    "remaining": 9995,
    "reset": 1748736000,
    "used": 5,
    "plan": "Standard",
    "reset_date": "2025-06-01T00:00:00.000000Z"
  }
}

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 "https://metalapi.com/api/v1/latest?api_key=YOUR_API_KEY&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
  },
  "rate_limit": {
    "limit": 10000,
    "remaining": 9995,
    "reset": 1748736000,
    "used": 5,
    "plan": "Standard",
    "reset_date": "2025-06-01T00:00:00.000000Z"
  }
}

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 "https://metalapi.com/api/v1/2024-01-15?api_key=YOUR_API_KEY&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
  },
  "rate_limit": {
    "limit": 10000,
    "remaining": 9995,
    "reset": 1748736000,
    "used": 5,
    "plan": "Standard",
    "reset_date": "2025-06-01T00:00:00.000000Z"
  }
}

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 "https://metalapi.com/api/v1/convert?api_key=YOUR_API_KEY&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,
  "rate_limit": {
    "limit": 10000,
    "remaining": 9995,
    "reset": 1748736000,
    "used": 5,
    "plan": "Standard",
    "reset_date": "2025-06-01T00:00:00.000000Z"
  }
}

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 "https://metalapi.com/api/v1/timeframe?api_key=YOUR_API_KEY&start_date=2024-01-01&end_date=2024-01-07&currencies=XAU"

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
    }
  },
  "rate_limit": {
    "limit": 10000,
    "remaining": 9995,
    "reset": 1748736000,
    "used": 5,
    "plan": "Standard",
    "reset_date": "2025-06-01T00:00:00.000000Z"
  }
}

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 "https://metalapi.com/api/v1/change?api_key=YOUR_API_KEY&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
    }
  },
  "rate_limit": {
    "limit": 10000,
    "remaining": 9995,
    "reset": 1748736000,
    "used": 5,
    "plan": "Standard",
    "reset_date": "2025-06-01T00:00:00.000000Z"
  }
}

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 "https://metalapi.com/api/v1/ohlc?api_key=YOUR_API_KEY&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
    }
  },
  "rate_limit": {
    "limit": 10000,
    "remaining": 9995,
    "reset": 1748736000,
    "used": 5,
    "plan": "Standard",
    "reset_date": "2025-06-01T00:00:00.000000Z"
  }
}

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 "https://metalapi.com/api/v1/carat?api_key=YOUR_API_KEY&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"
    }
  },
  "rate_limit": {
    "limit": 10000,
    "remaining": 9995,
    "reset": 1748736000,
    "used": 5,
    "plan": "Standard",
    "reset_date": "2025-06-01T00:00:00.000000Z"
  }
}

Usage

GET /v1/usage

Get API usage statistics for your account.

Example Request

curl "https://metalapi.com/api/v1/usage?api_key=YOUR_API_KEY"

Example Response

{
  "success": true,
  "usage": {
    "requests_made": 15,
    "requests_quota": 1000,
    "requests_remaining": 985,
    "plan": "lite"
  },
  "rate_limit": {
    "limit": 10000,
    "remaining": 9995,
    "reset": 1748736000,
    "used": 5,
    "plan": "Standard",
    "reset_date": "2025-06-01T00:00:00.000000Z"
  }
}

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 comprehensive rate limit information in the headers:

X-RateLimit-Limit: 1000
X-RateLimit-Remaining: 985
X-RateLimit-Reset: 1748189445
X-RateLimit-Used: 15
X-RateLimit-Plan: Standard
X-RateLimit-Reset-Date: 2025-06-01T00:00:00.000000Z

Header Descriptions

X-RateLimit-Limit Your monthly request limit based on subscription plan
X-RateLimit-Remaining Number of requests remaining in current period
X-RateLimit-Reset Unix timestamp when rate limits reset (start of next month)
X-RateLimit-Used Number of requests used in current period
X-RateLimit-Plan Your current subscription plan name
X-RateLimit-Reset-Date ISO 8601 formatted date when limits reset

Pro Tip: Monitor these headers in your application to implement client-side rate limiting and avoid hitting your limits.

Rate Limit Info in JSON Response

In addition to headers, rate limit information is also included in the JSON response body:

{
  "success": true,
  "base": "USD",
  "timestamp": 1748715946,
  "rates": {
    "EUR": 0.8255334,
    "XAG": 0.03602543,
    "XAU": 0.00053853
  },
  "rate_limit": {
    "limit": 10000,
    "remaining": 9992,
    "reset": 1748736000,
    "used": 8,
    "plan": "Standard",
    "reset_date": "2025-06-01T00:00:00.000000Z"
  }
}

Dual Format: Rate limiting information is provided in both HTTP headers and JSON response body for maximum compatibility and ease of use.

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 = 'https://metalapi.com/api/v1';

// Get latest rates
async function getLatestRates() {
  try {
    const response = await axios.get(`${baseUrl}/latest`, {
      params: {
        api_key: apiKey,
        base: 'USD',
        currencies: 'XAU,XAG,EUR'
      }
    });
    
    console.log('Response:', response.data);
    console.log('Rate Limit Info:', response.data.rate_limit);
    
    // You can also access rate limit info from headers
    console.log('Remaining requests:', response.headers['x-ratelimit-remaining']);
  } catch (error) {
    console.error('Error:', error.response.data);
    if (error.response.data.rate_limit) {
      console.log('Rate Limit Info:', error.response.data.rate_limit);
    }
  }
}

// Convert currency
async function convertCurrency() {
  try {
    const response = await axios.get(`${baseUrl}/convert`, {
      params: {
        api_key: apiKey,
        from: 'USD',
        to: 'XAU',
        amount: 1000
      }
    });
    
    console.log(`1000 USD = ${response.data.result} XAU`);
    console.log('Rate Limit Info:', response.data.rate_limit);
  } catch (error) {
    console.error('Error:', error.response.data);
  }
}

// Get symbols
async function getSymbols() {
  try {
    const response = await axios.get(`${baseUrl}/symbols`, {
      params: {
        api_key: apiKey
      }
    });
    
    console.log('Available symbols:', response.data.symbols);
    console.log('Rate Limit Info:', response.data.rate_limit);
  } catch (error) {
    console.error('Error:', error.response.data);
  }
}

getLatestRates();
convertCurrency();
getSymbols();

Python

import requests
import json

API_KEY = 'YOUR_API_KEY'
BASE_URL = 'https://metalapi.com/api/v1'

def get_latest_rates():
    """Get latest exchange rates"""
    params = {
        'api_key': API_KEY,
        'base': 'USD',
        'currencies': 'XAU,XAG,EUR'
    }
    
    response = requests.get(f'{BASE_URL}/latest', params=params)
    
    if response.status_code == 200:
        data = response.json()
        print('Response:', json.dumps(data, indent=2))
        print(f'Remaining requests: {data["rate_limit"]["remaining"]}')
        
        # You can also access rate limit info from headers
        print(f'Rate limit from headers: {response.headers.get("X-RateLimit-Remaining")}')
    else:
        print(f'Error: {response.status_code}')
        error_data = response.json()
        print(json.dumps(error_data, indent=2))
        if 'rate_limit' in error_data:
            print('Rate Limit Info:', error_data['rate_limit'])

def convert_currency(from_currency, to_currency, amount):
    """Convert one currency to another"""
    params = {
        'api_key': API_KEY,
        'from': from_currency,
        'to': to_currency,
        'amount': amount
    }
    
    response = requests.get(f'{BASE_URL}/convert', params=params)
    
    if response.status_code == 200:
        data = response.json()
        print(f'{amount} {from_currency} = {data["result"]} {to_currency}')
        print('Rate Limit Info:', data['rate_limit'])
    else:
        print(f'Error: {response.status_code}')
        print(response.json())

def get_symbols():
    """Get available symbols"""
    params = {
        'api_key': API_KEY
    }
    
    response = requests.get(f'{BASE_URL}/symbols', params=params)
    
    if response.status_code == 200:
        data = response.json()
        print('Available symbols:')
        if 'metals' in data['symbols']:
            print('Metals:', data['symbols']['metals'])
        if 'currencies' in data['symbols']:
            print('Currencies:', data['symbols']['currencies'])
        print('Rate Limit Info:', data['rate_limit'])
    else:
        print(f'Error: {response.status_code}')
        print(response.json())

# Example usage
get_latest_rates()
convert_currency('USD', 'XAU', 1000)
get_symbols()

PHP

Quick Start

<?php
// Simple PHP example - Get latest gold price
$api_key = 'YOUR_API_KEY';
$url = 'https://metalapi.com/api/v1/latest?api_key=' . urlencode($api_key) . '&base=USD¤cies=XAU';

$response = file_get_contents($url);
$data = json_decode($response, true);

if ($data['success']) {
    echo "Gold Price: $" . $data['rates']['XAU'] . " per troy ounce\n";
    echo "Rate Limit: " . $data['rate_limit']['remaining'] . " requests remaining\n";
} else {
    echo "Error: " . $data['message'] . "\n";
}
?>

cURL

# Get latest rates
curl "https://metalapi.com/api/v1/latest?api_key=YOUR_API_KEY&base=USD¤cies=XAU,XAG,EUR"

# Get symbols
curl "https://metalapi.com/api/v1/symbols?api_key=YOUR_API_KEY"

# Convert currency
curl "https://metalapi.com/api/v1/convert?api_key=YOUR_API_KEY&from=USD&to=XAU&amount=1000"

Widgets

Create beautiful, customizable widgets to display real-time metal and currency rates on your website. Our widget system provides easy integration with full customization control.

Widget Generator

Use our interactive widget generator to create custom widgets without any coding. Choose from multiple themes, sizes, and data types.

Customization Options

  • • Multiple themes (Light, Dark, Blue, Green, etc.)
  • • Various sizes (Compact, Medium, Large)
  • • Symbol selection (Metals & Currencies)
  • • Display options (Change %, Auto-refresh)
  • • Domain restrictions for security

Features

  • • Real-time data updates
  • • Responsive design
  • • Mobile-friendly
  • • Rate limit monitoring
  • • Usage analytics

Available Widget Styles

Modern Grid

Clean grid layout with card-based design

  • • Best for: Multiple symbols
  • • Responsive grid system
  • • Card hover effects
Single Ticker

Compact single symbol display

  • • Best for: One symbol
  • • Minimal space usage
  • • Inline integration
Horizontal Ticker

Scrolling ticker for multiple symbols

  • • Best for: Headers/footers
  • • Auto-scrolling
  • • Continuous loop
Detailed Table

Comprehensive table with all details

  • • Best for: Analytics pages
  • • Sortable columns
  • • Extended data
Compact List

Simple vertical list layout

  • • Best for: Sidebars
  • • Minimal design
  • • Space efficient
TV Fullscreen

Full screen display for TV/monitors

  • • Best for: TV displays
  • • Auto-scaling grid
  • • Live clock & branding

Get Started: Visit our widget generator to create your first widget

Open Widget Generator

Integration Guide

Learn how to integrate MetalAPI widgets into your website with these simple steps.

1 Create Your Widget

Use the widget generator to configure your widget settings, select symbols, and customize the appearance.

2 Get Embed Code

After creating your widget, copy the generated embed code. Choose between HTML embed or JavaScript integration.

<!-- HTML Embed -->
<iframe src="https://metalapi.com/widget/YOUR_WIDGET_ID" 
        width="400" height="300" frameborder="0"></iframe>

<!-- JavaScript Integration -->
<div id="metalapi-widget"></div>
<script src="https://metalapi.com/js/widget.js"></script>
<script>
    MetalAPIWidget.init({
        container: '#metalapi-widget',
        widgetId: 'YOUR_WIDGET_ID',
        apiUrl: 'https://metalapi.com/api/widgets/data'
    });
</script>

3 Add to Your Website

Paste the embed code into your HTML where you want the widget to appear. The widget will automatically load and display real-time data.

Tip: Make sure your domain is added to the widget's allowed domains list for security.

Configuration Options

Customize your widgets with these configuration options to match your website's design and requirements.

Appearance

Theme Light, Dark, Blue, Green, etc.
Size Compact, Medium, Large
Layout Horizontal, Vertical, Grid
Border Radius 0px to 20px

Data & Behavior

Auto Refresh Enable/Disable
Show Change % Display price changes
Update Frequency Based on your plan
Symbol Selection Metals, Currencies, Crypto

Live Examples

See our widgets in action with these live examples. Click on any widget to view it in full screen.

Light Theme - Compact

XAU/USD
$2,045.30
+1.2% ↗

Dark Theme - Medium

XAG/USD
$24.85
-0.8% ↘

Multi-Symbol - Large

Gold (XAU) $2,045.30 +1.2%
Silver (XAG) $24.85 -0.8%
EUR/USD 1.0875 +0.3%

Ready to create your own widget?

Support

Need help integrating MetalAPI? Our support team is here to assist you.

Contact Support

Email: [email protected]

Response time: 24 hours

Resources

  • • API Status Page
  • • Community Forum
  • • GitHub Examples