Real-Time XAUUSD Price Tracking Using Node.js and WebSockets
The next gold move could happen in minutes. Make sure you're watching real-time data, not yesterday's prices.

Gold is one of the most actively traded assets in the world. Whether you're a trader, investor, or developer building financial applications, having access to real-time gold prices is essential.
In this tutorial, we'll build a simple real-time gold price tracker using Node.js and WebSockets. By the end, you'll have a live dashboard that updates automatically whenever the market price changes.
Why Real-Time Data Matters
Many free APIs provide delayed market data, which can be unsuitable for trading applications. Real-time streaming allows your application to:
Receive updates instantly
Reduce API requests
Improve user experience
React faster to market movements
Prerequisites
Before getting started, you'll need:
Node.js installed
A RealMarketAPI account
Basic JavaScript knowledge
Step 1: Create a New Project
mkdir gold-tracker
cd gold-tracker
npm init -y
npm install ws
Step 2: Connect to the WebSocket
Create a file called index.js.
const WebSocket = require('ws');
const ws = new WebSocket('YOUR_WEBSOCKET_URL');
ws.on('open', () => { console.log('Connected'); });
ws.on('message', (data) => { const tick = JSON.parse(data); console.log(tick); });
ws.on('close', () => { console.log('Disconnected'); });
Step 3: Subscribe to Gold Prices
After connecting, subscribe to the XAUUSD symbol.
ws.send(JSON.stringify({ action: 'subscribe', symbol: 'XAUUSD' }));
Now every new price update will be streamed directly to your application.
Step 4: Display Live Prices
ws.on('message', (data) => { const tick = JSON.parse(data);
console.clear();
console.log('Gold Price Tracker');
console.log('------------------');
console.log(`Bid: ${tick.bid}`);
console.log(`Ask: ${tick.ask}`);
console.log(`Time: ${tick.timestamp}`);
});
Step 5: Add Price Change Detection
Let's highlight significant market movements.
let lastPrice = null;
ws.on('message', (data) => { const tick = JSON.parse(data);
if (lastPrice && tick.bid > lastPrice) {
console.log('๐ Gold moving up');
}
if (lastPrice && tick.bid < lastPrice) {
console.log('๐ Gold moving down');
}
lastPrice = tick.bid;
});
Possible Enhancements
You can extend this project by:
Sending Telegram alerts Creating a web dashboard with React Storing historical prices Calculating moving averages Detecting breakout opportunities
Final Thoughts
Building a real-time gold price tracker is a great introduction to financial market data and WebSocket development. With just a few lines of code, you can create applications that react instantly to market movements.
If you're building trading tools, dashboards, or automated strategies, real-time streaming data can significantly improve both performance and user experience.


