go-yfinance

module
v1.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 26, 2026 License: Apache-2.0

README

go-yfinance

Go Reference Go Report Card License

Unofficial Go port of the popular Python library yfinance.

This project is a Go implementation based on the logic of yfinance. It aims to provide a native Go experience (rewrite) while respecting the original API structure.

Features

  • TLS Fingerprint Spoofing: Uses CycleTLS to bypass Yahoo's bot detection with Chrome JA3 fingerprint
  • Automatic Authentication: Cookie/Crumb management with CSRF fallback for EU users
  • Thread-Safe: Concurrent-safe client and configuration
  • Comprehensive Error Handling: Typed errors with proper Go error wrapping

Installation

go get github.com/wnjoon/go-yfinance

Quick Start

package main

import (
    "fmt"
    "log"

    "github.com/wnjoon/go-yfinance/pkg/models"
    "github.com/wnjoon/go-yfinance/pkg/ticker"
)

func main() {
    // Create a ticker
    t, err := ticker.New("AAPL")
    if err != nil {
        log.Fatal(err)
    }
    defer t.Close()

    // Get current quote
    quote, err := t.Quote()
    if err != nil {
        log.Fatal(err)
    }
    fmt.Printf("AAPL: $%.2f (%+.2f%%)\n",
        quote.RegularMarketPrice,
        quote.RegularMarketChangePercent)

    // Get historical data
    bars, err := t.History(models.HistoryParams{
        Period:   "1mo",
        Interval: "1d",
    })
    if err != nil {
        log.Fatal(err)
    }
    fmt.Printf("\nLast 5 days:\n")
    start := len(bars) - 5
    if start < 0 {
        start = 0
    }
    for _, bar := range bars[start:] {
        fmt.Printf("%s: O=%.2f H=%.2f L=%.2f C=%.2f V=%d\n",
            bar.Date.Format("2006-01-02"),
            bar.Open, bar.High, bar.Low, bar.Close, bar.Volume)
    }

    // Get company info
    info, err := t.Info()
    if err != nil {
        log.Fatal(err)
    }
    fmt.Printf("\nCompany: %s\n", info.LongName)
    fmt.Printf("Sector: %s\n", info.Sector)
    fmt.Printf("Industry: %s\n", info.Industry)
    fmt.Printf("Market Cap: $%d\n", info.MarketCap)
}

Rate Limiting

⚠️ Note: This library does not enforce rate limiting internally. Yahoo Finance may block IP addresses with excessive request volume. To avoid 429 Too Many Requests errors, manage concurrency on the client side using worker pools, semaphores, or request throttling.

Configuration

import "github.com/wnjoon/go-yfinance/pkg/config"

// Global configuration
cfg := config.Get()
cfg.SetTimeout(60 * time.Second).
    SetMaxRetries(5).
    SetDebug(true)

// Or create custom config
customCfg := config.NewDefault().
    SetProxy("http://proxy:8080").
    EnableCache(10 * time.Minute)

Project Structure

go-yfinance/
├── cmd/example/              # Usage examples
├── internal/
│   └── endpoints/            # Yahoo Finance API endpoints
├── pkg/
│   ├── client/               # HTTP client with TLS fingerprint
│   │   ├── client.go         # CycleTLS-based client
│   │   ├── auth.go           # Cookie/Crumb authentication
│   │   └── errors.go         # Error types
│   ├── config/               # Configuration management
│   ├── ticker/               # Ticker data (Phase 1+)
│   └── models/               # Data models (Phase 1+)
└── README.md

Dependencies

go-yfinance is distributed under the Apache Software License 2.0. See the LICENSE file in the repository for details.

Disclaimer

Please read this carefully before using this library.

  1. Unofficial API: This library is not affiliated with, endorsed by, or connected to Yahoo! Finance. It wraps unofficial API endpoints intended for web browser consumption.

  2. Research & Educational Use: This library is intended for research and educational purposes.

  3. Terms of Service: Use of this library must comply with Yahoo!'s Terms of Service. Users are solely responsible for ensuring their usage is compliant.

  4. Risk of Blocking: Since this library relies on unofficial methods, Yahoo! Finance may change their API structure or block IP addresses making excessive requests at any time without notice.

  5. No Warranty: This software is provided "as is", without warranty of any kind, express or implied. The authors shall not be held liable for any damages or legal issues arising from the use of this software.

Credits

This project is a Go implementation based on the logic of yfinance. Special thanks to Ran Aroussi and all contributors of the original project for their excellent work.

Directories

Path Synopsis
cmd
debug command
Debug authentication flow
Debug authentication flow
example command
Example usage of go-yfinance
Example usage of go-yfinance
internal
endpoints
Package endpoints defines Yahoo Finance API endpoint constants.
Package endpoints defines Yahoo Finance API endpoint constants.
pkg
cache
Package cache provides an in-memory caching layer for go-yfinance.
Package cache provides an in-memory caching layer for go-yfinance.
calendars
Package calendars provides Yahoo Finance economic calendar functionality.
Package calendars provides Yahoo Finance economic calendar functionality.
client
Package client provides HTTP client functionality for Yahoo Finance API.
Package client provides HTTP client functionality for Yahoo Finance API.
config
Package config provides configuration management for go-yfinance.
Package config provides configuration management for go-yfinance.
industry
Package industry provides Yahoo Finance industry data functionality.
Package industry provides Yahoo Finance industry data functionality.
live
Package live provides real-time WebSocket streaming for Yahoo Finance data.
Package live provides real-time WebSocket streaming for Yahoo Finance data.
lookup
Package lookup provides Yahoo Finance ticker lookup functionality.
Package lookup provides Yahoo Finance ticker lookup functionality.
market
Package market provides Yahoo Finance market status and summary functionality.
Package market provides Yahoo Finance market status and summary functionality.
models
Package models provides data structures for Yahoo Finance API responses.
Package models provides data structures for Yahoo Finance API responses.
multi
Package multi provides functionality for downloading data for multiple tickers.
Package multi provides functionality for downloading data for multiple tickers.
repair
Package repair provides price data repair functionality for financial time series.
Package repair provides price data repair functionality for financial time series.
screener
Package screener provides Yahoo Finance stock screener functionality.
Package screener provides Yahoo Finance stock screener functionality.
search
Package search provides Yahoo Finance search functionality.
Package search provides Yahoo Finance search functionality.
sector
Package sector provides Yahoo Finance sector data functionality.
Package sector provides Yahoo Finance sector data functionality.
stats
Package stats provides statistical utility functions for price repair operations.
Package stats provides statistical utility functions for price repair operations.
ticker
Package ticker provides the main interface for accessing Yahoo Finance data.
Package ticker provides the main interface for accessing Yahoo Finance data.
utils
Package utils provides utility functions for go-yfinance.
Package utils provides utility functions for go-yfinance.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL