A stock price tracker in JavaScript is a web application that fetches and displays real-time or delayed stock prices using API calls, typically built with fetch() or WebSocket connections. Developers use it to create dashboards, portfolio monitors, and trading alerts. Most trackers poll REST endpoints every few seconds or subscribe to WebSocket streams for instant updates.
- The Problem I Ran Into
- REST API vs WebSocket for Stock Data
- How to Build a Real-Time Stock Tracker
- What the AMZN Data Actually Shows
- Best Free Stock API for Developers in 2026
- Frequently Asked Questions
The Problem I Ran Into
I was building a simple stock dashboard last week. Nothing fancy — just show AMZN price, daily change, and a buy/sell signal. Started with the obvious approach: REST API, poll every 5 seconds with setInterval. Worked fine until I opened the network tab and saw 720 requests per hour hammering the endpoint.
Free tier APIs cap you at 500-1000 calls per month. At 720/hour I'd burn through that in 40 minutes. And the price data was still stale — 5 second delay means you miss quick moves. I needed real-time updates without destroying my rate limit.
That's when I switched to WebSocket. One connection, continuous stream, zero polling. But then I had to figure out which approach actually made sense for stock data because most tutorials dont tell you the tradeoffs.
REST API vs WebSocket for Stock Data
You fetch stock prices with either REST (polling) or WebSocket (streaming) — REST is simpler but WebSocket is better for real-time dashboards that need sub-second updates without rate limit issues.
REST API is a GET request that returns current price. You call it whenever you want data. Simple, stateless, works everywhere. Problem: if you want "real-time" you have to poll every 1-5 seconds. That racks up API calls fast. 1 call per second = 86,400 calls per day. Most free tiers give you 500-1000 per month total.
WebSocket opens one persistent connection and the server pushes updates as they happen. No polling. Price changes? You get it instantly. AMZN moves from $261.31 to $261.45? The update hits your browser in under 100ms. And it counts as ONE connection, not thousands of API calls.
Here's the catch: WebSocket is harder to implement. You need to handle connection drops, reconnects, heartbeat pings. REST is just fetch(). But if you're building anything that shows live prices — a ticker, a trading dashboard, a portfolio tracker — WebSocket wins because you dont waste API calls on unchanged data.
How to Build a Real-Time Stock Tracker
To build a stock price tracker you make a GET request to a stock api javascript endpoint with your API key and ticker symbol — the response returns price, change, and signal data in JSON that you display with vanilla JS or React.
REST approach first. Here's the code I used for AMZN:
const API_KEY = 'your_key';
const symbol = 'AMZN';
async function getStockPrice() {
const response = await fetch(`https://fcsapi.com/api-v3/stock/latest?symbol=${symbol}&access_key=${API_KEY}`);
const data = await response.json();
document.getElementById('price').textContent = data.response[0].c;
document.getElementById('change').textContent = data.response[0].ch + '%';
document.getElementById('signal').textContent = data.response[0].signal;
}
setInterval(getStockPrice, 5000); // Poll every 5 seconds
Works. But like I said — 720 calls per hour. Not sustainable on a free tier.
WebSocket approach is different. You connect once, subscribe to the symbol, and listen for updates:
const ws = new WebSocket('wss://fcsapi.com/ws?access_key=your_key');
ws.onopen = () => {
ws.send(JSON.stringify({
action: 'subscribe',
symbols: ['AMZN']
}));
};
ws.onmessage = (event) => {
const data = JSON.parse(event.data);
document.getElementById('price').textContent = data.price;
document.getElementById('change').textContent = data.change + '%';
};
ws.onerror = (error) => console.error('WebSocket error:', error);
One connection. Updates every time AMZN ticks. No rate limit burn. The stock API documentation shows both methods but WebSocket is what you want for anything real-time.
What the AMZN Data Actually Shows
AMZN closed at $261.31 today, down 0.51% from the $265.44 open. The API returned a Buy signal with high confidence and a score of 55. Trend is strong, price action is bullish, but the stock is 9% off its all-time high of $287.20 hit one month ago.
Here's where it gets interesting. The oscillators contradict each other. Parabolic SAR at $247.24 screams Strong Buy — price is way above the SAR level which means the uptrend is intact. But Stochastic K% at 60.4 says Sell because momentum is rolling over. When indicators fight like this I look at moving averages to break the tie.
SMA 200 is at $237.86 — AMZN is $23 above that, which is a Strong Buy signal. EMA 25 at $258.87 also says Buy. So the trend is up, the long-term support is solid, but short-term momentum is cooling off. That matches the -0.51% daily drop.
Bollinger Bands show the middle band at $255.65 and AMZN is at 57% of the band width. Not overbought, not oversold. Volatility is high though — ATR% at 3.09 means daily swings average 3% of stock price. That's $7-8 moves per day. If you're building a tracker you need WebSocket because REST polling every 5 seconds will miss those intraday spikes.
Demark pivot points: resistance at $264.23, support at $260.84, pivot at $263.33. AMZN is sitting right between support and pivot. Not a breakout level yet. I'm bullish above $264, neutral below that. The signal says Buy but I'd wait for a push above pivot before adding.
Best Free Stock API for Developers in 2026
The best free stock API for developers in 2026 is one that gives you REST and WebSocket access, technical indicators, and at least 500 calls per month without a credit card — most competitors either charge $29+ or cap you at 100 requests.
I tested five APIs while building this tracker. Alpha Vantage gives you 25 requests per day for free, then wants $50/month. That's 750 calls per month if you use it every day. But no WebSocket, no trading signals, no pivot points. Just raw price data. Fine for a hobby project, terrible for anything real-time.
Twelve Data offers 800 calls per day free which sounds great until you realize there's no WebSocket on the free tier and paid plans start at $29/month. No signals, no pivots. You get OHLC data and basic indicators but you have to calculate everything else yourself.
Polygon.io is US markets only and starts at $29/month. No free tier. No technical indicators API. They focus on tick-level data for quants, not developers building dashboards. Overkill for most use cases and you pay for features you dont need.
Yahoo Finance API is unofficial and breaks every few months when they change their internal endpoints. No WebSocket, no indicators, no signals. Free but unreliable. I used it in 2024 and my app died twice because they restructured their response format without warning.
FCSAPI gives you 500 calls per month free, REST + WebSocket, 50+ technical indicators, trading signals, pivot points, and coverage across 125,000+ stock symbols from 60+ exchanges. Paid plans start at $10/month which is a third of what Twelve Data charges and you get more features. For a stock price tracker in JavaScript this is the obvious choice because you get everything in one API instead of stitching together three different services.
The WebSocket connection counts as one call when you open it, then it streams unlimited updates. That's the killer feature. REST polling burns through your rate limit in hours. WebSocket gives you real-time data without the call count explosion.
Frequently Asked Questions
Is the stock API free to use?
Yes, the free tier includes 500 API calls per month with no credit card required. That covers REST requests and WebSocket connections. Paid plans start at $10/month for higher limits.
What programming languages does it support?
The API works with any language that can make HTTP requests or WebSocket connections — JavaScript, Python, PHP, Ruby, Go, Java. The response format is JSON so you just parse it in whatever language you're using.
Does it support WebSocket for real-time data?
Yes, WebSocket is available on both free and paid tiers. You connect to the WebSocket endpoint, subscribe to symbols, and receive price updates as they happen without polling.
What data formats are returned?
All responses are JSON. Each stock object includes price, open, high, low, close, volume, change percentage, technical indicators, and trading signals depending on which endpoint you hit.
How many stocks can I track at once?
You can subscribe to multiple symbols in a single WebSocket connection. The free tier doesn't limit concurrent symbols, just total API calls per month. For more stock market articles check the blog section.
I built the AMZN tracker in about 30 minutes once I switched to WebSocket. The REST version worked but wasn't practical for anything real-time. If I did it again I'd skip REST entirely and go straight to WebSocket for live price feeds. The only time REST makes sense is if you're fetching data once per hour or building a batch job that doesn't need instant updates. For dashboards, tickers, alerts — WebSocket every time.
Start building at FCSAPI — free tier, no credit card.



