datafetch

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Jul 18, 2026 License: MIT Imports: 24 Imported by: 1

Documentation

Overview

file: insyra/datafetch/yfinance_errors.go

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrGeocodeNotFound means the coordinate does not fall inside any Taiwan
	// village polygon (e.g. a point at sea or outside Taiwan). It is a definitive,
	// non-retryable outcome.
	ErrGeocodeNotFound = errors.New("datafetch: geocoding point not found")
	// ErrGeocodeTimeout means the request exceeded the configured timeout.
	ErrGeocodeTimeout = errors.New("datafetch: geocoding request timeout")
	// ErrGeocodeRateLimited means the free-tier quota (15 requests/hour) is
	// exhausted. A *RateLimitError unwraps to this sentinel.
	ErrGeocodeRateLimited = errors.New("datafetch: geocoding rate limited")
)

Stable sentinel errors for the TWGeocoding fetcher. Callers should match these with errors.Is rather than comparing error strings.

View Source
var (
	ErrRateLimited   = errors.New("yfinance: rate limited")
	ErrTimeout       = errors.New("yfinance: timeout")
	ErrInvalidSymbol = errors.New("yfinance: invalid symbol")
)

Functions

func GoogleMapsStores

func GoogleMapsStores() *googleMapsStoreCrawler

GoogleMapsStores returns a crawler for Google Maps store data. Returns nil if failed to initialize.

func TWGeocoding added in v0.3.0

func TWGeocoding(cfg TWGeocodingConfig) (*twGeocoder, error)

TWGeocoding creates a Taiwan reverse-geocoding fetcher backed by geocoding.zuola.com. Note the free tier is limited to 15 requests/hour per IP; use a GeocodeCache and the batch methods' de-duplication to conserve it.

func YFinance added in v0.2.13

func YFinance(cfg YFinanceConfig) (*yahooFinance, error)

YFinance creates a YahooFinance fetcher using a config struct (no WithXxx in public API).

Types

type GeocodeCache added in v0.3.0

type GeocodeCache interface {
	// Get returns (result, true) for a cached success, (nil, true) for a cached
	// not_found, and (nil, false) when the key is absent.
	Get(key string) (*ReverseGeocodeResult, bool)
	// Set stores a success (non-nil r) or a not_found marker (nil r).
	Set(key string, r *ReverseGeocodeResult)
}

GeocodeCache is an optional store for reverse-geocode results, keyed by the exact coordinate. Implementations must be safe for concurrent use. Only definitive outcomes are ever stored: a non-nil result for a success, and a nil result to mark a definitive not_found. Transient failures are never cached.

func NewFileGeocodeCache added in v0.3.0

func NewFileGeocodeCache(path string) GeocodeCache

NewFileGeocodeCache returns a cache backed by a JSON file at path. Existing contents are loaded on construction and every Set is persisted, so resolved coordinates survive across runs — the highest-value option under the 15 requests/hour quota. Unreadable/corrupt files start from an empty cache.

func NewMemoryGeocodeCache added in v0.3.0

func NewMemoryGeocodeCache() GeocodeCache

NewMemoryGeocodeCache returns an in-process, concurrency-safe cache.

type GoogleMapsStoreData added in v0.1.3

type GoogleMapsStoreData struct {
	ID   string
	Name string
}

type GoogleMapsStoreReview added in v0.1.1

type GoogleMapsStoreReview struct {
	Reviewer      string `json:"reviewer"`
	ReviewerID    string `json:"reviewer_id"`
	ReviewerState string `json:"reviewer_state"`
	ReviewerLevel int    `json:"reviewer_level"`
	ReviewTime    string `json:"review_time"`
	ReviewDate    string `json:"review_date"`
	Content       string `json:"content"`
	Rating        int    `json:"rating"`
}

GoogleMapsStoreReview is a struct for Google Maps store reviews.

type GoogleMapsStoreReviewSortBy added in v0.1.1

type GoogleMapsStoreReviewSortBy uint8
const (
	// SortByRelevance 按相關性排序
	SortByRelevance GoogleMapsStoreReviewSortBy = 1
	// SortByNewest 按最新排序
	SortByNewest GoogleMapsStoreReviewSortBy = 2
	// SortByRating 按評分排序
	SortByHighestRating GoogleMapsStoreReviewSortBy = 3
	// SortByLowestRating 按最低評分排序
	SortByLowestRating GoogleMapsStoreReviewSortBy = 4
)

type GoogleMapsStoreReviews added in v0.1.2

type GoogleMapsStoreReviews []GoogleMapsStoreReview

GoogleMapsStoreReviews is a slice of GoogleMapsStoreReview.

func (GoogleMapsStoreReviews) ToDataTable added in v0.1.2

func (reviews GoogleMapsStoreReviews) ToDataTable() *insyra.DataTable

ToDataTable converts the reviews to a DataTable.

type GoogleMapsStoreReviewsFetchingOptions added in v0.1.1

type GoogleMapsStoreReviewsFetchingOptions struct {
	SortBy GoogleMapsStoreReviewSortBy
	// MaxWaitingInterval_Milliseconds is the maximum waiting interval in milliseconds between requests.
	MaxWaitingInterval_Milliseconds uint
}

GoogleMapsStoreReviewsFetchingOptions is a struct for options when fetching reviews.

type RateLimitError added in v0.3.0

type RateLimitError struct {
	Limit     int       // X-Ratelimit-Limit (requests per window)
	Remaining int       // X-Ratelimit-Remaining
	ResetAt   time.Time // X-Ratelimit-Reset, zero if the header was absent/unparseable
}

RateLimitError carries the rate-limit state parsed from the API's X-Ratelimit-* response headers. It unwraps to ErrGeocodeRateLimited so callers can either branch with errors.Is(err, ErrGeocodeRateLimited) or read ResetAt for a precise back-off.

func (*RateLimitError) Error added in v0.3.0

func (e *RateLimitError) Error() string

func (*RateLimitError) Unwrap added in v0.3.0

func (e *RateLimitError) Unwrap() error

Unwrap lets errors.Is(err, ErrGeocodeRateLimited) succeed for a *RateLimitError.

type ReverseGeocodeResult added in v0.3.0

type ReverseGeocodeResult struct {
	Lat         float64 `json:"lat"`
	Lng         float64 `json:"lng"`
	VillCode    string  `json:"villcode"`
	CountyName  string  `json:"county_name"`
	TownName    string  `json:"town_name"`
	VillageName string  `json:"village_name"`
	VillageEng  string  `json:"village_eng"`
	CountyID    string  `json:"county_id"`
	CountyCode  string  `json:"county_code"`
	TownID      string  `json:"town_id"`
	TownCode    string  `json:"town_code"`
}

ReverseGeocodeResult is the typed result of a single reverse-geocode lookup.

func (*ReverseGeocodeResult) ToDataTable added in v0.3.0

func (r *ReverseGeocodeResult) ToDataTable() *insyra.DataTable

ToDataTable returns a single-row DataTable representation of the result, with the same column order as the batch methods' output (minus GeocodeStatus).

type TWGeocodingConfig added in v0.3.0

type TWGeocodingConfig struct {
	// Timeout is the per-request timeout. Default: 15s.
	Timeout time.Duration
	// Interval is the minimum spacing between requests (client-side throttle).
	// 0 disables throttling. Must be >= 0.
	Interval time.Duration
	// UserAgent is the HTTP User-Agent header. Default: a browser-like UA.
	UserAgent string
	// Retries is the number of retry attempts for transient failures. Must be >= 0.
	Retries int
	// RetryBackoff is the base backoff between retries. Must be >= 0. Default: 300ms.
	RetryBackoff time.Duration
	// BaseURL overrides the reverse-geocoding endpoint (for tests/mocks or a
	// future paid/self-hosted tier). Default: the official zuola endpoint.
	BaseURL string
	// Cache, when non-nil, serves and stores definitive results to conserve the
	// scarce request quota. Use NewMemoryGeocodeCache or NewFileGeocodeCache.
	Cache GeocodeCache
}

TWGeocodingConfig configures a TWGeocoding fetcher. A zero value is valid and yields sensible defaults.

type YFFinancialStatementTables added in v0.2.13

type YFFinancialStatementTables struct {
	Values *insyra.DataTable
	Items  *insyra.DataTable
	Meta   *insyra.DataTable
}

YFFinancialStatementTables provides multiple views of a statement.

type YFHistoryParams added in v0.2.13

type YFHistoryParams = models.HistoryParams

type YFOptionChainTables added in v0.2.13

type YFOptionChainTables struct {
	Calls      *insyra.DataTable
	Puts       *insyra.DataTable
	Underlying *insyra.DataTable
	Expiration time.Time
}

YFOptionChainTables splits option chains into separate tables.

type YFPeriod added in v0.2.13

type YFPeriod string

YFPeriod represents frequency values used for financial statements. Accepted values: YFPeriodAnnual, YFPeriodYearly, YFPeriodQuarterly. When empty or unrecognized, it defaults to YFPeriodAnnual.

const (
	YFPeriodAnnual    YFPeriod = "annual"
	YFPeriodYearly    YFPeriod = "yearly"
	YFPeriodQuarterly YFPeriod = "quarterly"
)

type YFinanceConfig added in v0.2.13

type YFinanceConfig struct {
	// Timeout: 單次請求最多等待多久(避免卡死)
	Timeout time.Duration

	// Interval: 每次請求之間最少要隔多久(節流)
	// 0 表示不節流
	Interval time.Duration

	// UserAgent: HTTP User-Agent
	UserAgent string

	// Retries: 失敗時重試次數(0 表示不重試)
	Retries int

	// RetryBackoff: 每次重試前等待多久(0 表示用預設)
	RetryBackoff time.Duration

	// Concurrency: 多 ticker 並行抓取時的最大並行數(0 表示用預設)
	Concurrency int
}

Directories

Path Synopsis
internal

Jump to

Keyboard shortcuts

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