Best API to get live (spot) silver price rates?

< Back to Guides

We offer a silver live price API. This guide will provide you step by step instructions to get live silver rates using javascript. Methodologies include using Fetch, jQuery, or XHR.

Instructions

  1. Get a free API key to use by signing up at Metalpriceapi.com and replace REPLACE_ME with your API key.
  2. Update base value to a currency or remove this query param.
  3. Update currencies value to a list of values or remove this query param. (XAG)

For 2 and 3, you can find this documented at Offical Documentation

 

Using jQuery to fetch live silver price in Javascript

var settings = {
  "url": "https://api.metalpriceapi.com/v1/latest?api_key=REPLACE_ME&base=USD&currencies=XAU,XAG,EUR",
  "method": "GET",
  "timeout": 0,
};

$.ajax(settings).done(function (response) {
  console.log(response);
});

 

Using Fetch to fetch live silver price in Javascript

var requestOptions = {
  method: 'GET',
  redirect: 'follow'
};

fetch("https://api.metalpriceapi.com/v1/latest?api_key=REPLACE_ME&base=USD&currencies=XAU", requestOptions)
  .then(response => response.text())
  .then(result => console.log(result))
  .catch(error => console.log('error', error));

 

Using XHR to fetch live silver price in Javascript in USD


var xhr = new XMLHttpRequest();
xhr.withCredentials = true;

xhr.addEventListener("readystatechange", function() {
  if(this.readyState === 4) {
    console.log(this.responseText);
  }
});

xhr.open("GET", "https://api.metalpriceapi.com/v1/latest?api_key=REPLACE_ME&base=USD&currencies=XAG");

xhr.send();