DEV Community

Mahesh Baldaniya
Mahesh Baldaniya

Posted on

Building a Real-Time Gift Nifty Tracker Using Yahoo Finance API (Step-by-Step)

Most trading websites show market data, but very few explain how that data is actually fetched and visualized in real time.

Recently, I worked on a small project to track Gift Nifty live and display it in a clean dashboard with charts and sentiment indicators. In this post, I’ll walk through the approach, APIs, and logic behind building a simple real-time tracker.

🧠 What We Are Building

The goal is to create a lightweight web dashboard that:

Fetches Gift Nifty data in real time
Displays price, change, and trend
Renders a live chart
Calculates basic sentiment (bullish/bearish)
πŸ“Š Why Gift Nifty?

Gift Nifty is widely used as a pre-market indicator to understand how the Indian market might open. It reacts to global cues and trades longer hours than the regular market.

If you're already familiar with the Nifty 50, Gift Nifty acts as an early signal for its movement.

πŸ”Œ Data Source (Yahoo Finance API)

Instead of building a backend from scratch, I used a proxy API that fetches data from Yahoo Finance.

This returns:

Timestamp data
Price values
Market metadata
βš™οΈ Fetching and Processing Data

Basic logic:

async function fetchChart() {
const res = await fetch(API);
const json = await res.json();

const result = json.chart.result[0];
const timestamps = result.timestamp;
const prices = result.indicators.quote[0].close;

return timestamps.map((t, i) => ({
time: new Date(t * 1000),
price: prices[i]
}));
}

Key point:
πŸ‘‰ Always filter out null values before rendering.

πŸ“ˆ Chart Rendering (Chart.js)

For visualization, I used Chart.js because it’s lightweight and easy to integrate.

new Chart(ctx, {
type: "line",
data: {
labels: data.map(d => d.time),
datasets: [{
data: data.map(d => d.price),
borderColor: "#22c55e",
tension: 0.4
}]
}
});
πŸ” Sentiment Logic (Simple but Effective)

Instead of complex AI models, a basic approach works surprisingly well:

const first = data[0].price;
const last = data[data.length - 1].price;

const sentiment = last > first ? "BULLISH" : "BEARISH";

You can extend this further by:

Adding volatility checks
Using moving averages
Tracking global indices
🌍 Adding Global Market Context

Gift Nifty doesn’t move in isolation. It is influenced by global markets like:

Dow Jones Industrial Average
Nasdaq Composite

You can fetch their data using the same API pattern by changing the symbol.

πŸš€ Real-Time Updates

To keep data fresh:

setInterval(loadData, 60000);

πŸ‘‰ Refresh every 60 seconds to simulate real-time behavior.

🧩 UI/UX Considerations

Some things that made a big difference:

Color coding (green/red for trend)
Minimal layout (avoid clutter)
Fast loading (important for traders)
Mobile responsiveness
πŸ”— Live Implementation

If you want to see how this works in a real scenario with live data and simplified analysis, you can check it here:

πŸ‘‰ gift nifty live
⚠️ Challenges Faced
API reliability (Yahoo endpoints sometimes fail)
Handling null/missing data
Timezone conversion (IST vs UTC)
Rate limiting

Top comments (0)