A lightweight Go library for fetching Indian stock market data from NSE
nse-fetch is a simple and efficient Go library that provides programmatic access to the National Stock Exchange of India (NSE) market data. Fetch real-time stock information, historical data, and market indices with just a few lines of code.
- 🔍 Auto-complete Search - Find stock symbols and instruments quickly
- 📊 Historical Data - Fetch historical equity data for any date range
- 📈 Nifty 50 Performance - Get real-time data for Nifty 50 index and constituents
- 📈 Top Gainers & Losers - Track the top performing and underperforming stocks
- 🚀 Zero Dependencies - Uses only Go standard library
- ⚡ Fast & Lightweight - Optimized for performance
- 🔒 Cookie Handling - Automatically manages NSE session cookies
go get -u github.com/sanesource/nse-fetchRequirements:
- Go 1.24.2 or higher
| Method | Description |
|---|---|
FetchAutoComplete |
Search for stock symbols and get instrument suggestions |
FetchEquityHistorical |
Retrieve historical stock data for a specific symbol and date range |
FetchNifty50Performance |
Get the latest performance data for Nifty 50 index and constituents |
FetchTopGainers |
Fetch the top gaining stocks in the market |
FetchTopLosers |
Fetch the top losing stocks in the market |
Search for stock symbols and get instrument suggestions.
Signature:
func FetchAutoComplete(symbol string) (map[string]any, error)Parameters:
symbol(string) - The search keyword or partial symbol name
Returns:
map[string]any- Response containing matching instrumentserror- Error if the request fails
Example:
package main
import (
"fmt"
"log"
nse "github.com/sanesource/nse-fetch"
)
func main() {
response, err := nse.FetchAutoComplete("TATA")
if err != nil {
log.Fatal(err)
}
// Response structure: { "data": { "symbols": [...] } }
fmt.Printf("Found instruments: %v\n", response)
}Retrieve historical stock data for a specific symbol and date range.
Signature:
func FetchEquityHistorical(symbol, from, to string) (map[string]any, error)Parameters:
symbol(string) - The stock symbol (e.g., "RELIANCE", "TCS")from(string) - Start date in formatDD-MM-YYYYto(string) - End date in formatDD-MM-YYYY
Returns:
map[string]any- Response containing historical dataerror- Error if the request fails
Example:
package main
import (
"fmt"
"log"
nse "github.com/sanesource/nse-fetch"
)
func main() {
// Fetch historical data for RELIANCE from Jan 1 to Jan 31, 2025
response, err := nse.FetchEquityHistorical("RELIANCE", "01-01-2025", "31-01-2025")
if err != nil {
log.Fatal(err)
}
// Response structure: { "data": [...] }
fmt.Printf("Historical data: %v\n", response)
}Get the latest performance data for Nifty 50 index and all its constituent stocks.
Signature:
func FetchNifty50Performance() (map[string]any, error)Parameters:
- None
Returns:
map[string]any- Response containing Nifty 50 performance dataerror- Error if the request fails
Example:
package main
import (
"fmt"
"log"
nse "github.com/sanesource/nse-fetch"
)
func main() {
response, err := nse.FetchNifty50Performance()
if err != nil {
log.Fatal(err)
}
// Response structure: { "data": [...] }
fmt.Printf("Nifty 50 data: %v\n", response)
}Fetch the top gaining stocks in the market.
Signature:
func FetchTopGainers() (map[string]any, error)Parameters:
- None
Returns:
map[string]any- Response containing top gaining stocks dataerror- Error if the request fails
Example:
package main
import (
"fmt"
"log"
nse "github.com/sanesource/nse-fetch"
)
func main() {
response, err := nse.FetchTopGainers()
if err != nil {
log.Fatal(err)
}
// Response structure: { "data": [...] }
fmt.Printf("Top Gainers: %v\n", response)
}Fetch the top losing stocks in the market.
Signature:
func FetchTopLosers() (map[string]any, error)Parameters:
- None
Returns:
map[string]any- Response containing top losing stocks dataerror- Error if the request fails
Example:
package main
import (
"fmt"
"log"
nse "github.com/sanesource/nse-fetch"
)
func main() {
response, err := nse.FetchTopLosers()
if err != nil {
log.Fatal(err)
}
// Response structure: { "data": [...] }
fmt.Printf("Top Losers: %v\n", response)
}go test -v ./...git clone https://github.com/sanesource/nse-fetch.git
cd nse-fetch
go buildContributions are welcome! Please feel free to submit a Pull Request. For major changes, please open an issue first to discuss what you would like to change.
- Fork the repository
- Create your feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add some amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
This library is for educational and research purposes only. Please ensure you comply with NSE's terms of service and usage policies when using this library. The authors are not responsible for any misuse of this library.
- Data provided by National Stock Exchange of India
- Inspired by the need for easy programmatic access to Indian stock market data
- Issues: GitHub Issues
- Discussions: GitHub Discussions
Made with ❤️ by the sanesource team