Live metal price widgets
Display continuously updated gold and silver prices on websites, customer portals, and mobile applications.
metals:XAUUSD · metals:XAGUSDwss://ws.goldapi.io/v1Free Plan evaluation included · Unlimited access with Business Plan
Display continuously updated gold and silver prices on websites, customer portals, and mobile applications.
metals:XAUUSD · metals:XAGUSDKeep buy, sell, and inventory screens synchronized with current spot, bid, and ask data.
Pricing and inventory workflowsPower real-time watchlists, charts, alerts, and internal market-data tools without REST polling loops.
Push-based market updatesCombine precious-metal and FX channels for localized prices and multi-currency customer experiences.
metals:XAGEUR · fx:USDEURFeed current market prices into valuation, melt-value, and operational workflows.
XAU · XAG · XPT · XPDUpdate precious-metal holdings and market values as normalized prices are published.
REST-compatible data modelsSign in to the GoldAPI dashboard and copy your dedicated WebSocket API key. It is separate from your REST API key.
Exchange the dedicated key from a trusted backend. The response includes a 15-minute token, WebSocket URL, permitted channels, and limits.
POST https://www.goldapi.io/api/ws/token
x-ws-api-key: YOUR_GOLDAPI_WEBSOCKET_KEYToken endpoint reference →Open wss://ws.goldapi.io/v1, then authenticate before subscribing. requestId correlates each command with its response.
{
"type": "auth",
"token": "YOUR_SHORT_LIVED_WS_TOKEN",
"requestId": "prices-auth"
}After the authenticated response, subscribe to one or more concrete metal or FX channels.
{
"type": "subscribe",
"channels": [
"metals:XAUUSD",
"metals:XAGUSD",
"fx:USDEUR"
],
"requestId": "prices-subscribe"
}metals:XAUUSDGold priced in US dollarsmetals:XAGEURSilver priced in eurosmetals:XPTUSDPlatinum priced in US dollarsmetals:XPDAUDPalladium priced in Australian dollarsfx:USDEURUS dollar to eurofx:GBPAUDBritish pound to Australian dollar{
"type": "price.update",
"channel": "metals:XAUUSD",
"publishedAt": 1792651200,
"data": {
"timestamp": 1792651200,
"datetime": "2026-10-22T06:40:00.000Z",
"metal": "XAU",
"currency": "USD",
"exchange": "FOREXCOM",
"symbol": "FOREXCOM:XAUUSD",
"open_time": 1792627200,
"open_price": 4166.13,
"prev_close_price": 4166.13,
"low_price": 4163.755,
"high_price": 4187.87,
"price": 4175.12,
"unit": "troy_ounce",
"change": 8.99,
"change_percent": 0.22,
"ask": 4175.42,
"bid": 4174.71,
"spread": 0.71,
"range": 24.115
}
}The normalized payload includes timestamps, exchange and symbol information, open and previous-close prices, daily high and low, spread, and trading range.
// Node.js 18+ · npm install ws
const WebSocket = require('ws');
async function connect() {
const response = await fetch('https://www.goldapi.io/api/ws/token', {
method: 'POST',
headers: { 'x-ws-api-key': process.env.GOLDAPI_WS_API_KEY }
});
if (!response.ok) throw new Error('Unable to issue WebSocket token');
const session = await response.json();
const socket = new WebSocket(session.websocketUrl);
socket.on('open', () => socket.send(JSON.stringify({
type: 'auth', token: session.token, requestId: 'prices-auth'
})));
socket.on('message', raw => {
const message = JSON.parse(raw.toString());
if (message.type === 'authenticated') {
socket.send(JSON.stringify({
type: 'subscribe',
channels: ['metals:XAUUSD', 'metals:XAGUSD'],
requestId: 'prices-subscribe'
}));
}
if (message.type === 'price.update') console.log(message);
if (message.type === 'error') console.error(message.code, message.message);
});
const heartbeat = setInterval(() => {
if (socket.readyState === WebSocket.OPEN) socket.send(JSON.stringify({
type: 'ping', requestId: 'ping-' + Date.now()
}));
}, 25000);
socket.on('close', () => clearInterval(heartbeat));
}
connect().catch(console.error);The GoldAPI WebSocket API provides a persistent, push-based connection for receiving real-time precious-metals and foreign-exchange price updates without repeatedly polling REST endpoints.
GoldAPI supports gold (XAU), silver (XAG), platinum (XPT), and palladium (XPD) across supported quote currencies.
Precious-metal channels use the metals: prefix, such as metals:XAUUSD. Foreign-exchange channels use the fx: prefix, such as fx:USDEUR. Your connection token identifies the channel families available to your account.
No. Wildcards describe the channel families your token is permitted to access. Clients subscribe to concrete channels such as metals:XAUUSD or metals:XAGEUR.
No. WebSocket access uses a dedicated WebSocket API key available in the GoldAPI dashboard. Keep it in a trusted backend or secret manager and exchange it for a short-lived WebSocket token.
A WebSocket connection token currently lasts 15 minutes. When it expires, request a fresh token and reconnect.
No. For Free accounts, successfully issuing a WebSocket token counts as one shared monthly request. Establishing the connection and receiving market-data messages do not increment that monthly request count.
Free includes WebSocket evaluation with one connection and up to 10 channels. Business includes production access with up to five concurrent connections and 20 channels per connection. Pro does not include WebSocket access.
The server sends a TOKEN_EXPIRED error and closes the connection with code 4001. Request a new token and establish a fresh connection.
Yes. The old key immediately stops issuing new tokens, while connections using an existing short-lived token remain active until that token expires.