Skip to main content

yfinance-ir

CI PyPI Python License: MIT

فارسی

⁧داده‌های بازار ایران با رابط آشنای yfinance: سهام، صندوق‌ها و شاخص‌های بورس تهران (TSETMC)، صورت‌های مالی کدال، دلار، طلا و سکه از TGJU، تورم مرکز آمار ایران و رمزارزها از صرافی‌های ایرانی.⁩

yfinance-shaped market data for the Iranian markets: TSETMC (equities, ETFs, indices), Codal (financial statements), TGJU (FX, gold, coins), the Statistical Centre of Iran (CPI) and, with the crypto extra, Iranian crypto exchanges through ccxt-ir.

Iranian IP required. cdn.tsetmc.com drops foreign IPs.

Since Nowruz 1405: which assets beat inflation and which beat the dollar

Each bar comes from one history() call: TSETMC indices, stocks and ETFs, TGJU's dollar, euro, gold and coin, and Nobitex bitcoin, measured against the SCI CPI and the free-market dollar. examples/scoreboard.ipynb draws this chart. It also plots the same race over time, since Nowruz and over five years, and a heatmap of real and dollar returns over seven windows. The charts are in Persian, so install the notebook extras for text shaping: pip install "yfinance-ir[crypto,notebook]".

The chart is redrawn every month and posted on X as @_fazel94. yfin.ir has the same comparison as a web page.

Install

pip install yfinance-ir            # TSETMC + Codal + TGJU + CPI
pip install "yfinance-ir[crypto]"  # adds BTC-IRT / ETH-USDT style pairs

Each GitHub Release also carries the wheel and sdist.

Quickstart

import yfinance_ir as yf

folad = yf.Ticker("فولاد")
folad.history(period="1y")          # adjusted daily OHLCV
folad.history(period="5d", interval="5m")   # intraday bars rebuilt from TSETMC trades
folad.info["marketCap"]
folad.income_stmt                   # Codal, wide, newest period first
folad.cashflow                      # Codal cash-flow statement
yf.Ticker("اهرم").option_chain()    # nearest expiration: calls, puts, underlying

yf.download(["فولاد", "فملی"], period="6mo")
yf.Ticker("USD").history(period="5y")   # TGJU dollar, Rial
yf.Ticker("شاخص کل").history()          # TEDPIX
yf.Ticker("CPI").history()              # SCI consumer price index, monthly
yf.Ticker("BTC-IRT").history()          # Nobitex, needs the `crypto` extra

Example: فولاد in Rial, USD and real terms

examples/real_returns.py prices فولاد in TGJU dollars and deflates it by the SCI CPI. Both series are forward-filled onto the stock's trading days.

import pandas as pd

folad = yf.Ticker("فولاد").history(period="5y")["Close"]
usd = yf.Ticker("USD").history(period="5y")["Close"].reindex(folad.index, method="ffill")
cpi = yf.Ticker("CPI").history(period="5y")["Close"].reindex(folad.index, method="ffill")

frame = pd.DataFrame({"Rial": folad, "USD": folad / usd, "Real": folad / cpi * cpi.iloc[-1]})
print(frame.iloc[-1] / frame.iloc[0] - 1)

Output on 2026-09-21:

فولاد 2021-09-25 -> 2026-09-21 (5.0y)
        total annualised
Rial  +228.1%     +26.9%
USD    -60.8%     -17.1%
Real   -52.0%     -13.7%

examples/cookbook.ipynb runs the recipes of chapters 1, 2 and 7 of Python for Finance Cookbook (returns, CPI deflation, outliers, stylised facts, SMA/Bollinger/RSI backtests with backtrader, 1/n portfolio, Monte Carlo efficient frontier) on TSETMC stocks and Nobitex crypto pairs. Install its dependencies with pip install "yfinance-ir[crypto,notebook]".

Symbols

You pass Resolves to Example
Persian symbol TSETMC instrument Ticker("فولاد"), Ticker("اهرم")
Persian index name TSETMC index Ticker("شاخص کل")
InsCode (10 to 20 digits) TSETMC instrument Ticker("46348559193224090")
TGJU alias or slug FX / gold / coin Ticker("USD"), Ticker("geram18")
CPI, CPI_URBAN, CPI_RURAL SCI price index Ticker("CPI")
BASE-IRT / BASE-USDT crypto pair Ticker("BTC-IRT")
ISIN cache lookup only, see below Ticker("IRO1FOLD0009")

Persian and Arabic spellings are unified (ی/ي, ک/ك, ZWNJ). TGJU aliases and the per-source rules are in docs/data-sources.md. Resolutions are cached in ~/.cache/yfinance_ir/symbols.sqlite; yf.cache.clear() drops them, yf.set_config(cache_dir=...) moves them.

Ticker API

Member Source Notes
history(...) TSETMC / TGJU / SCI / crypto daily OHLCV (monthly for CPI), adjusted by default; TSETMC also 1m–90m and 1h bars rebuilt from trades
info TSETMC yfinance-style keys: marketCap, trailingPE, sharesOutstanding, …
dividends, splits, actions TSETMC adjust + share-change see docs/conventions.md
orderbook TSETMC / exchange 5 levels, bid/ask price-volume-count
client_types, client_type_history() TSETMC individual vs institutional flow
major_holders TSETMC > 1 % shareholders
news Codal summaries + TSETMC supervisor messages
income_stmt, balance_sheet, cashflow, quarterly_* Codal wide frame, columns = period end
options, option_chain(date) TSETMC option market watch expirations; calls and puts with bid, ask, last, volume, open interest
monthly_activity() Codal monthly production/sales letters

Tickers("فولاد فملی") bundles several tickers. download([...]) returns the yfinance MultiIndex layout: group_by="column" gives (Price, Ticker), group_by="ticker" flips it.

Compared with other packages

yfinance-ir pytse-client finpy-tse tehran-stocks
Sources TSETMC, Codal, TGJU, SCI CPI, Nobitex (crypto extra) TSETMC TSETMC, free-market dollar TSETMC
API shape yfinance: Ticker(...).history(), download([...]) Ticker(...).history frame, download(symbols=...) Get_*_History() functions SQLAlchemy models + CLI
Adjusted daily history dividends and capital increases adjust=True adjust_price=True dividend and share tables, no adjusted series documented
Intraday bars 1m–90m, 1h, rebuilt from trades 30s–1h, aggregated from trade details (get_trade_details(..., timeframe=)) trade and order-book history, no bars —
Order book, client types yes yes yes —
Codal statements income, balance sheet, cash flow, monthly activity — — —
Option chains yes — — —
FX, gold, coin TGJU — USD only (Get_USD_RIAL) —
CPI SCI, monthly — — —
Index history any TSETMC index by name FinancialIndex(...).history Get_CWI_History, Get_EWI_History, sector indices —
Jalali dates input and output include_jdate=True jalali_date=True output
Licence MIT GPL-3.0 BSD-3-Clause MIT
Last commit 2026-10 2025-03 2024-04 2023-10
PyPI yes yes yes yes

Checked against each package's README on 2026-10-11; "—" means the README does not document it. Corrections welcome as issues.

Conventions

Topic Rule
Prices TSETMC and TGJU in Rial; *-IRT crypto pairs in Toman
Columns Open High Low Close Volume Dividends "Stock Splits", plus TSETMC Last, Value, Count; auto_adjust=False adds Adj Close
Dates Gregorian DatetimeIndex; start/end accept Gregorian, Jalali (1403-01-01), dEven ints, date/datetime; end exclusive; intraday bars carry a tz-aware Datetime index, Asia/Tehran for TSETMC and UTC for crypto
Adjustment Dividend gaps from TSETMC GetPriceAdjustList; share-count changes it omits are bonus issues (old / new); markers land on the next bar
Non-trading rows Zero-volume calendar rows while a symbol is suspended are dropped
Errors SymbolNotFound, BlockedError, RateLimitError, DataUnavailable, all subclasses of YFIRError

Full definitions: docs/conventions.md.

Configuration

yf.set_config(
    min_interval=0.1,      # seconds between requests to the same host
    timeout=20.0,          # per-request timeout
    threads=4,             # download() workers
    cache_dir=None,        # default: $XDG_CACHE_HOME/yfinance_ir
    crypto_exchange="nobitex",
    trust_env=True,        # honour HTTP(S)_PROXY
)

Limitations

  • Intraday bars exist for TSETMC instruments other than indices, span at most 3 months per call and cost one request per trading day. Some of TSETMC's backends answer the trade feed with HTTP 500 or an empty list; a failed request reconnects to reach another backend, and a day still empty after 12 passes (about 3 minutes, long pauses logged at WARNING) raises DataUnavailable. Other sources: TGJU is daily, crypto 1d/1h, CPI monthly.
  • Option chains have no implied volatility or last-trade date; TSETMC publishes neither.
  • CPI downloads from amar.org.ir run with verify=False because the server omits its intermediate certificate.
  • ISIN lookup only hits the local cache; resolve by symbol or InsCode first.
  • Index history has no open or volume.
  • ccxt-ir 4.19.0's fetch_ohlcv and fetch_order_book are broken; Nobitex and Wallex history and Nobitex depth come from their public REST APIs instead, other exchanges re-raise the ccxt error. Tether: Nobitex refuses USDT-IRT history, Wallex serves it.

Reasons and endpoint details: docs/data-sources.md.

Development

python -m venv .venv && .venv/bin/pip install -e ".[dev,crypto]"
.venv/bin/python -m ruff check .
.venv/bin/python -m pytest                   # 95 offline tests, replayed fixtures
.venv/bin/python -m pytest -m live           # 12 smoke tests, needs an Iranian IP
.venv/bin/python tests/capture_fixtures.py   # re-record tests/fixtures/

Offline tests run through responses against the exact URLs the package calls, so a wrong path in yfinance_ir/sources/ fails a test instead of hitting the network.

Versions are CalVer, YYYY.M.MICRO. CHANGELOG.md names breaking changes; the number does not encode them. See CONTRIBUTING.md.

Not affiliated with yfinance, Yahoo, TSETMC, Codal, TGJU or the Statistical Centre of Iran. The package reads their public endpoints and copies the yfinance API shape. The data comes with no accuracy guarantee and is not investment advice. You are responsible for following each source's terms of use.

Author

Built by Kiyarash Fazeli (kiya.nlogn.ir). He writes in English on kialog and in Persian on kiablog. nlogn.ir lists his other sites and projects.

License

MIT, Copyright (c) 2026 Kiyarash Fazeli. See LICENSE.

Metadata

Release files for yfinance-ir 2026.11.3

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for yfinance-ir 2026.11.3
File Size Uploaded Provenance Actions
yfinance_ir-2026.11.3.tar.gz 66.7 kB Without provenance Details for yfinance_ir-2026.11.3.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for yfinance-ir 2026.11.3
File Interpreter ABI Platform Actions
yfinance_ir-2026.11.3-py3-none-any.whl Python 3 none any Details for yfinance_ir-2026.11.3-py3-none-any.whl

Total release size: 119.3 kB

Release files / yfinance_ir-2026.11.3.tar.gz

Download URL yfinance_ir-2026.11.3.tar.gz
Size 66.7 kB
Tags Source
SHA-256 checksum
How to use checksums
c9f377570470ef9a3678bb9fac0d6a03a2df616a114a6273d23816de58025328
BLAKE2b-256 checksum
How to use checksums
7cf0ecc35c9de490b4497d22d5ed10bd850d8e4d4674042684fb3070b240c297
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.11.12

Release files / yfinance_ir-2026.11.3-py3-none-any.whl

Download URL yfinance_ir-2026.11.3-py3-none-any.whl
Size 52.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
6dc379ba39531f454f64c9b4b09c093a6d42e708a1706c42b716e7e72baa3ed8
BLAKE2b-256 checksum
How to use checksums
97765262f41308a4c571fa9f9251eba50b0e02ebff7fa8bb0f4a8ec62d2cfee5
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.11.12

Security for yfinance-ir 2026.11.3

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page