A robust wrapper around yfinance for market-aware financial data fetching.
Project description
FinFetcher
Quick Summary: A robust Python library for fetching clean, market-aware historical financial data. It acts as a smart wrapper around
yfinance, automatically handling asset-specific market hours and timezones to ensure data integrity for quantitative modeling and backtesting.
📊 The Problem it Solves
When fetching daily data during active market hours, standard tools often return an "unfinished" candle for the current day. Using this incomplete data point can introduce significant look-ahead bias or noise in statistical models.
FinFetcher solves this by:
- Identifying the asset's exchange timezone (e.g., NYSE vs. Tokyo SE vs. Crypto).
- Checking the exact market status relative to the server time.
- Automatically filtering out the current day's row if the market hasn't closed yet.
- Calculating the valid
target_date(next trading day) for forecasting targets. It is usable for production (live deplyoment) needs when predicting for the upcoming day (with fetched training data till today).
🏆 Key Capabilities
| Component | Feature | Details |
|---|---|---|
| Smart Ingestion | Market-aware cleaning. | Removes incomplete daily candles based on precise closing times (e.g., 16:20 ET for US Equities to account for delay). |
| Multi-Asset | Native handling for various types. | EQUITY (Stocks/ETFs), CRYPTOCURRENCY (24/7), FUTURES, FOREX, INDEX. |
| Forecasting Prep | Target Date Calculation. | Automatically computes the next valid business day (or calendar day for Crypto) for predictive labeling. |
| Resiliency | Robust Error Handling. | Wraps yfinance with retry logic and custom exceptions for better pipeline stability. |
📦 Installation
pip install finfetcher
🚀 Usage
Basic Example
from finfetcher import DataFetcher
# Initialize for an asset (Equity)
fetcher = DataFetcher("AAPL")
# Fetch data (default: period="4y", interval="1d")
# This returns a pandas DataFrame with Date index
df = fetcher.get_data(period="1mo")
print(f"Data shape: {df.shape}")
print(f"Last available close: {df.index[-1]}")
# Access the calculated target date (next trading day)
print(f"Prediction Target Date: {fetcher.target_date}")
Handling Cryptocurrencies
Crypto markets never close, so the logic adjusts to use a 23:59 UTC cutoff.
crypto_fetcher = DataFetcher("BTC-USD")
df = crypto_fetcher.get_data(period="5d")
# Target date will be tomorrow (calendar day), not business day
print(f"Next Target: {crypto_fetcher.target_date}")
Custom Market Configuration
You can override default market hours or add new asset types by passing a custom_cutoffs dictionary.
from finfetcher import DataFetcher
# Example: Change US Equity close to 13:00 (e.g. half-day)
custom_config = {
"EQUITY": {
"timezones": {
"America/New_York": {"hour": 13, "minute": 0}
}
}
}
fetcher = DataFetcher("AAPL", custom_cutoffs=custom_config)
df = fetcher.get_data()
🛠️ Logic Details
The library contains a set of configuration of market closing times (src/finfetcher/config.py) to handle timezone conversions accurately.
- US Equities: Closes at 16:00 ET (buffered to 16:20 to handle API delays).
- European Markets: Handled via specific timezones (London, Paris, Frankfurt, etc.).
- Asian Markets: Tokyo, Hong Kong, Singapore, etc.
- Crypto: UTC based cutoff.
💻 Tech Stack
- Python 3.10+
- Pandas & NumPy
- yfinance
- pytz
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file finfetcher-0.1.1.tar.gz.
File metadata
- Download URL: finfetcher-0.1.1.tar.gz
- Upload date:
- Size: 13.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
9f5579da2d6c1515824328434187754b90dd210a5129dd3c61ff654ac352c581
|
|
| MD5 |
75414a1884766eac27a59b2ae3413c13
|
|
| BLAKE2b-256 |
f7eb3f102050a1458c3710edf3b00d963c7bc981db0760084396be2c24027f23
|
Provenance
The following attestation bundles were made for finfetcher-0.1.1.tar.gz:
Publisher:
python-package.yml on eolybq/finfetcher
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
finfetcher-0.1.1.tar.gz -
Subject digest:
9f5579da2d6c1515824328434187754b90dd210a5129dd3c61ff654ac352c581 - Sigstore transparency entry: 929898993
- Sigstore integration time:
-
Permalink:
eolybq/finfetcher@6c03341b414c1481072c9eebb0ab18fdd90e02f9 -
Branch / Tag:
refs/tags/v0.1.1 - Owner: https://github.com/eolybq
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
python-package.yml@6c03341b414c1481072c9eebb0ab18fdd90e02f9 -
Trigger Event:
push
-
Statement type:
File details
Details for the file finfetcher-0.1.1-py3-none-any.whl.
File metadata
- Download URL: finfetcher-0.1.1-py3-none-any.whl
- Upload date:
- Size: 9.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
88ae2ff9f0ffef344da38f4086310275fff078cdc224b04b60465993fcdb3af9
|
|
| MD5 |
fa0e8469dab286651e2b1ca14544b5c7
|
|
| BLAKE2b-256 |
ba678f12040c471455f74a74afc0565c69020c042151c6b17d36fdaf66b5415a
|
Provenance
The following attestation bundles were made for finfetcher-0.1.1-py3-none-any.whl:
Publisher:
python-package.yml on eolybq/finfetcher
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
finfetcher-0.1.1-py3-none-any.whl -
Subject digest:
88ae2ff9f0ffef344da38f4086310275fff078cdc224b04b60465993fcdb3af9 - Sigstore transparency entry: 929898995
- Sigstore integration time:
-
Permalink:
eolybq/finfetcher@6c03341b414c1481072c9eebb0ab18fdd90e02f9 -
Branch / Tag:
refs/tags/v0.1.1 - Owner: https://github.com/eolybq
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
python-package.yml@6c03341b414c1481072c9eebb0ab18fdd90e02f9 -
Trigger Event:
push
-
Statement type: