Top-level API¶
The iranquant package re-exports the synchronous helpers, the
AsyncIranQuant client, the IranQuant facade, exceptions, models and quant
functions.
import iranquant as iq
iq.history("فولاد")
iq.AsyncIranQuant()
iq.IranQuant()
iq.MarketScreener
iq.MarketWatcher
iranquant
¶
iranquant — async-first TSETMC / Codal market data client.
Synchronous module-level helpers are the easiest entry point::
import iranquant as iq
df = iq.history("فولاد")
Inside an async application use :class:AsyncIranQuant::
async with AsyncIranQuant() as iq:
df = await iq.history("فولاد")
__all__
module-attribute
¶
__all__ = [
"AsyncHTTPClient",
"AsyncIranQuant",
"CodalLetter",
"CodalSearchResponse",
"DataFrame",
"Engine",
"IranQuant",
"IranQuantConfig",
"IranQuantConnectionError",
"IranQuantError",
"MarketEvent",
"MarketScreener",
"MarketWatcher",
"NetworkError",
"ParseError",
"SymbolNotFoundError",
"__version__",
"analyze_monthly_sales",
"client_type",
"codal_report",
"codal_search",
"compute_money_flow",
"compute_movement_power",
"detect_swing_legs",
"fetch_and_parse_report",
"financial_statements",
"full_history",
"get_financial_statements",
"get_inscode",
"get_monthly_reports",
"history",
"index_history",
"indices_live",
"intraday_trades",
"is_market_open",
"market_watch",
"money_flow",
"monthly_reports",
"monthly_sales_summary",
"movement_power",
"order_book",
"parse_codal_report",
"search",
"search_codal",
]
IranQuantConfig
dataclass
¶
IranQuantConfig(
verify_ssl: bool = (
lambda: _env_flag("IRANQUANT_VERIFY_SSL", True)
)(),
allow_tls_fallback: bool = (
lambda: _env_flag(
"IRANQUANT_ALLOW_TLS_FALLBACK", True
)
)(),
)
Transport security policy.
Values are read from the environment when omitted, and explicit keyword arguments take precedence.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
verify_ssl
|
bool
|
Verify upstream TLS certificates. Defaults to
|
(lambda: _env_flag('IRANQUANT_VERIFY_SSL', True))()
|
allow_tls_fallback
|
bool
|
Retry once over an unverified transport when
certificate verification fails. Defaults to
|
(lambda: _env_flag('IRANQUANT_ALLOW_TLS_FALLBACK', True))()
|
Examples:
AsyncHTTPClient
¶
AsyncHTTPClient(
*,
timeout: float = DEFAULT_TIMEOUT,
max_concurrency: int = MAX_CONCURRENCY,
max_retries: int = MAX_RETRIES,
retry_wait: float = RETRY_WAIT,
headers: Mapping[str, str] | None = None,
proxy: str | None = None,
trust_env: bool | None = None,
config: IranQuantConfig | None = None,
)
Small retrying wrapper around :class:httpx.AsyncClient.
Requests use a verified transport when config.verify_ssl is true. A
certificate failure is retried once over an unverified transport only when
config.allow_tls_fallback is true; the first fallback emits a
UserWarning and a log record. With fallback disabled, the failure raises
:class:~iranquant.exceptions.IranQuantConnectionError without retrying.
Environment proxy variables are ignored by default (trust_env=False) to
avoid corporate/VPN HTTP proxies breaking direct connections to domestic
Iranian hosts. Pass proxy=... to opt into an explicit proxy.
Create the pooled HTTP transports.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
timeout
|
float
|
Per-request timeout in seconds. Defaults to
:data: |
DEFAULT_TIMEOUT
|
max_concurrency
|
int
|
Maximum number of simultaneous requests enforced
by an internal :class: |
MAX_CONCURRENCY
|
max_retries
|
int
|
Total attempts per request. Defaults to
:data: |
MAX_RETRIES
|
retry_wait
|
float
|
Base wait used by the exponential retry backoff, in
seconds. Defaults to :data: |
RETRY_WAIT
|
headers
|
Mapping[str, str] | None
|
Extra headers merged over the built-in TSETMC/Codal headers. |
None
|
proxy
|
str | None
|
Optional explicit proxy URL, e.g.
|
None
|
trust_env
|
bool | None
|
Whether to honour |
None
|
config
|
IranQuantConfig | None
|
TLS policy. Defaults to :class: |
None
|
Examples:
>>> client = AsyncHTTPClient(timeout=10.0, max_concurrency=5)
>>> client.trust_env
False
>>> client = AsyncHTTPClient(
... config=IranQuantConfig(allow_tls_fallback=False)
... )
Source code in src/iranquant/core/client.py
get
async
¶
get(
url: str,
*,
params: Mapping[str, Any] | None = None,
headers: Mapping[str, str] | None = None,
raw: bool = False,
) -> httpx.Response
Perform a GET request with retries and TLS fallback.
The request is retried up to max_retries times on network errors,
and responses with status codes >= 500 are treated as retryable.
Certificate failures use the unverified fallback transport once when
allow_tls_fallback is true; the first fallback emits a
UserWarning. With fallback disabled, the request fails immediately
with :class:~iranquant.exceptions.IranQuantConnectionError.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
url
|
str
|
Absolute request URL. |
required |
params
|
Mapping[str, Any] | None
|
Optional query parameters. Ignored for URL encoding when
|
None
|
headers
|
Mapping[str, str] | None
|
Optional per-request headers merged over the defaults. |
None
|
raw
|
bool
|
When true the URL string is sent verbatim without
percent-encoding. Required for the MarketWatch endpoint, whose
|
False
|
Returns:
| Type | Description |
|---|---|
Response
|
The successful :class: |
Raises:
| Type | Description |
|---|---|
NetworkError
|
If the host is unreachable, a non-2xx status is returned, or all retries are exhausted. |
IranQuantConnectionError
|
If TLS verification fails and
|
Examples:
>>> response = await client.get("https://cdn.tsetmc.com/api/BestLimits/1")
>>> response.status_code
200
Source code in src/iranquant/core/client.py
get_json
async
¶
get_json(
url: str,
*,
params: Mapping[str, Any] | None = None,
headers: Mapping[str, str] | None = None,
raw: bool = False,
) -> Any
GET a URL and decode its JSON body.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
url
|
str
|
Absolute request URL. |
required |
params
|
Mapping[str, Any] | None
|
Optional query parameters. |
None
|
headers
|
Mapping[str, str] | None
|
Optional per-request headers. |
None
|
raw
|
bool
|
When true, send the URL untouched (see :meth: |
False
|
Returns:
| Type | Description |
|---|---|
Any
|
The decoded JSON value (usually a |
Raises:
| Type | Description |
|---|---|
NetworkError
|
If the request fails after retries. |
ParseError
|
If the response body is not valid JSON. |
Examples:
>>> payload = await client.get_json(
... "https://cdn.tsetmc.com/api/Instrument/GetInstrumentSearch/فولاد"
... )
>>> "instrumentSearch" in payload
True
Source code in src/iranquant/core/client.py
aclose
async
¶
Close the primary and fallback HTTP transports.
Safe to call more than once. After closing, the instance must not be used again.
Examples:
Source code in src/iranquant/core/client.py
__aenter__
async
¶
__aexit__
async
¶
IranQuantConnectionError
¶
Bases: NetworkError
Raised when TLS verification fails and fallback is disabled.
Inherits from :class:NetworkError, so existing handlers keep working,
but is excluded from retry loops because the failure is deterministic.
IranQuantError
¶
Bases: Exception
Base class for every exception raised by iranquant.
Catching this single type covers every library-specific failure while still allowing narrower handlers for specific cases.
Examples:
NetworkError
¶
Bases: IranQuantError
Raised when a remote endpoint cannot be reached or returns an error.
Wraps connection failures, timeouts, HTTP error statuses and exhausted retries from TSETMC or Codal.
ParseError
¶
Bases: IranQuantError
Raised when a remote payload cannot be parsed into the expected shape.
Covers invalid JSON, unexpected TSETMC/Codal schemas, malformed dEven
or hEven values, and missing var datasource blocks.
SymbolNotFoundError
¶
Bases: IranQuantError
Raised when a symbol cannot be resolved to a TSETMC instrument code.
Examples:
CodalLetter
¶
Bases: CodalBaseModel
CodalSearchResponse
¶
Bases: CodalBaseModel
A page of Codal search results with Pythonic container behavior.
The wire-format field names (Total, Page, Letters) are kept for
compatibility, and lowercase aliases (total, page, letters) are
provided for idiomatic code. The object is also iterable, indexable and
sized, and can be exported directly to a DataFrame.
Examples:
>>> response = iq.monthly_reports("فولاد")
>>> len(response) == response.total
True
>>> response[0].Symbol
'فولاد'
>>> response.to_dataframe()[["Symbol", "TracingNo"]].head()
__len__
¶
__iter__
¶
__getitem__
¶
to_dataframe
¶
Export the letters to a Pandas or Polars DataFrame.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
engine
|
Literal['pandas', 'polars']
|
|
'pandas'
|
Returns:
| Type | Description |
|---|---|
Any
|
One row per letter with the declared :class: |
Any
|
columns (including nested extra fields is intentionally avoided so |
Any
|
the schema stays stable). |
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
Examples:
>>> frame = iq.monthly_reports("فولاد").to_dataframe()
>>> frame[["Symbol", "TracingNo", "Title"]].head()
Source code in src/iranquant/models/codal.py
MarketScreener
¶
Vectorized filters over a MarketWatch (or batch) DataFrame.
Every filter accepts an optional alternative frame; when omitted the frame passed to the constructor is used. Results preserve the input engine type (Pandas in, Pandas out; Polars in, Polars out) and are reset to a clean index.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
frame
|
DataFrame | None
|
An optional MarketWatch frame from
:func: |
None
|
Raises:
| Type | Description |
|---|---|
ValueError
|
If a filter runs without a bound or call-time frame. |
TypeError
|
If the selected frame is neither a Pandas nor a Polars DataFrame (raised lazily when a filter runs). |
Examples:
>>> screener = MarketScreener(iq.market_watch())
>>> screener.filter_buy_queue()[["symbol", "close", "tmax"]]
>>> MarketScreener().filter_buy_queue(iq.market_watch()).head()
Source code in src/iranquant/quant/screener.py
filter_buy_queue
¶
Symbols locked at tmax with a positive buy-queue volume.
The mask is (tmax > 0) & (close >= tmax) & (sum(zmd) > 0). The
buy-queue volume is the sum of zmd (bid volume) across all order-book
levels.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
frame
|
DataFrame | None
|
Optional alternative frame; defaults to the constructor frame. |
None
|
Returns:
| Type | Description |
|---|---|
DataFrame
|
The matching rows in the same engine as the input. |
Raises:
| Type | Description |
|---|---|
KeyError
|
If |
Examples:
Source code in src/iranquant/quant/screener.py
filter_sell_queue
¶
Symbols locked at tmin with a positive sell-queue volume.
The mask is (tmin > 0) & (close <= tmin) & (sum(zmo) > 0). The
sell-queue volume is the sum of zmo (ask volume) across all
order-book levels.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
frame
|
DataFrame | None
|
Optional alternative frame; defaults to the constructor frame. |
None
|
Returns:
| Type | Description |
|---|---|
DataFrame
|
The matching rows in the same engine as the input. |
Raises:
| Type | Description |
|---|---|
KeyError
|
If |
Examples:
Source code in src/iranquant/quant/screener.py
filter_positive_tick_surge
¶
filter_positive_tick_surge(
frame: DataFrame | None = None,
min_diff_pct: float = 1.5,
) -> DataFrame
Symbols whose last price exceeds the final price by min_diff_pct.
The mask is
((close - final_price) / max(final_price, 1)) * 100 >= min_diff_pct.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
frame
|
DataFrame | None
|
Optional alternative frame; defaults to the constructor frame. |
None
|
min_diff_pct
|
float
|
Minimum percentage gap between the last traded price
and the closing price. Defaults to |
1.5
|
Returns:
| Type | Description |
|---|---|
DataFrame
|
The matching rows in the same engine as the input. |
Raises:
| Type | Description |
|---|---|
KeyError
|
If |
Examples:
>>> surges = screener.filter_positive_tick_surge(min_diff_pct=1.5)
>>> surges[["symbol", "close", "final_price"]].head()
Source code in src/iranquant/quant/screener.py
scan_market
¶
scan_market(
custom_predicate: Callable[
[DataFrame], DataFrame | Series
],
frame: DataFrame | None = None,
) -> DataFrame
Apply a custom Pandas predicate/mask and restore the engine type.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
custom_predicate
|
Callable[[DataFrame], DataFrame | Series]
|
A callable that receives the frame as a
:class: |
required |
frame
|
DataFrame | None
|
Optional alternative frame; defaults to the constructor frame. |
None
|
Returns:
| Type | Description |
|---|---|
DataFrame
|
The filtered rows converted back to the input engine. |
Raises:
| Type | Description |
|---|---|
TypeError
|
If |
Examples:
>>> high_volume = screener.scan_market(
... lambda df: df["volume"] > df["volume"].median()
... )
>>> high_volume[["symbol", "volume"]].sort_values("volume").tail()
Source code in src/iranquant/quant/screener.py
MarketEvent
dataclass
¶
MarketEvent(
event_type: str,
ins_code: str,
symbol: str,
timestamp: datetime,
data: dict[str, Any] = dict(),
)
A structured market state-change event.
Attributes:
| Name | Type | Description |
|---|---|---|
event_type |
str
|
One of |
ins_code |
str
|
TSETMC instrument code (empty when the snapshot lacks it). |
symbol |
str
|
Persian ticker from MarketWatch. |
timestamp |
datetime
|
When the event was detected (UTC unless supplied). |
data |
dict[str, Any]
|
Event-specific payload. Queue events include |
Examples:
>>> event = MarketEvent(
... event_type=BUY_QUEUE_LOCKED,
... ins_code="46348559193224090",
... symbol="فولاد",
... timestamp=dt.datetime.now(dt.timezone.utc),
... data={"close": 4150.0, "tmax": 4150.0},
... )
>>> event.symbol
'فولاد'
MarketWatcher
¶
Poll MarketWatch and emit queue/volume transitions.
process_snapshot is synchronous and stateful so it can also be used in
backtests or tests without any network access. The state machine emits:
BUY_QUEUE_LOCKED/BUY_QUEUE_BROKENwhenclose >= tmaxwith a positive buy queue starts or stops.SELL_QUEUE_LOCKED/SELL_QUEUE_BROKENwhenclose <= tminwith a positive sell queue starts or stops.VOLUME_SPIKEwhen the per-poll volume increase is at least1.8xthe running average increase.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
client
|
AsyncHTTPClient | None
|
Optional shared :class: |
None
|
Examples:
>>> watcher = MarketWatcher()
>>> @watcher.on_event(BUY_QUEUE_LOCKED)
... def on_lock(event: MarketEvent) -> None:
... print(event.symbol, event.data["buy_queue_volume"])
>>> async for event in watcher.watch(interval=5.0, symbols=["فولاد"]):
... print(event.event_type)
Source code in src/iranquant/stream/watcher.py
on_event
¶
Register a sync or async callback for an event type ("*" = all).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
event_type
|
str
|
A specific event constant or |
required |
Returns:
| Type | Description |
|---|---|
Callable[[EventCallback], EventCallback]
|
A decorator that registers the callback and returns it unchanged, |
Callable[[EventCallback], EventCallback]
|
so the method can be used as |
Examples:
>>> @watcher.on_event("*")
... async def log(event: MarketEvent) -> None:
... print(event.event_type, event.symbol)
Source code in src/iranquant/stream/watcher.py
dispatch
async
¶
Invoke every matching listener for each event.
Sync callbacks are called directly; awaitable results are awaited.
Listeners registered for "*" run after type-specific listeners.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
events
|
Iterable[MarketEvent]
|
Events to deliver, typically returned by
:meth: |
required |
Examples:
Source code in src/iranquant/stream/watcher.py
reset
¶
Forget all per-symbol state so the next snapshot starts fresh.
Does not remove registered listeners.
process_snapshot
¶
process_snapshot(
snapshot: DataFrame,
*,
timestamp: datetime | None = None,
symbols: list[str] | None = None,
) -> list[MarketEvent]
Update internal state from a MarketWatch frame and return events.
No I/O is performed; the result is deterministic for a given snapshot sequence, so this is safe to use in backtests and unit tests.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
snapshot
|
DataFrame
|
A MarketWatch frame (from
:func: |
required |
timestamp
|
datetime | None
|
Timestamp attached to emitted events. Defaults to the current UTC time. |
None
|
symbols
|
list[str] | None
|
Optional allow-list. Numeric strings are matched against
|
None
|
Returns:
| Type | Description |
|---|---|
list[MarketEvent]
|
The newly triggered events in snapshot order. An empty frame |
list[MarketEvent]
|
returns an empty list without mutating state. |
Examples:
>>> events = watcher.process_snapshot(iq.market_watch())
>>> [event.event_type for event in events]
['BUY_QUEUE_LOCKED']
Source code in src/iranquant/stream/watcher.py
224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 | |
watch
async
¶
watch(
interval: float = 5.0,
symbols: list[str] | None = None,
only_market_hours: bool = False,
) -> AsyncGenerator[MarketEvent, None]
Poll MarketWatch forever, yielding state-change events.
Each iteration fetches a full market snapshot, updates the state machine, dispatches callbacks, yields every new event, then sleeps. IranQuant errors during a poll are swallowed and retried on the next interval.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
interval
|
float
|
Seconds between full MarketWatch polls. Must be positive.
Defaults to |
5.0
|
symbols
|
list[str] | None
|
Optional allow-list passed to :meth: |
None
|
only_market_hours
|
bool
|
When |
False
|
Yields:
| Type | Description |
|---|---|
AsyncGenerator[MarketEvent, None]
|
class: |
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
Examples:
>>> async for event in watcher.watch(interval=3.0, symbols=["فولاد"]):
... print(event.event_type, event.symbol)
Source code in src/iranquant/stream/watcher.py
__aenter__
async
¶
Enter the async context manager, creating a client if needed.
Returns:
| Type | Description |
|---|---|
MarketWatcher
|
|
Source code in src/iranquant/stream/watcher.py
__aexit__
async
¶
Close the owned HTTP client when leaving the context manager.
Source code in src/iranquant/stream/watcher.py
AsyncIranQuant
¶
AsyncIranQuant(
*,
timeout: float = DEFAULT_TIMEOUT,
max_concurrency: int = MAX_CONCURRENCY,
proxy: str | None = None,
config: IranQuantConfig | None = None,
)
Async client owning a single pooled HTTP transport.
Use this class when your application already runs an event loop. It keeps
one :class:~iranquant.core.client.AsyncHTTPClient alive for all requests,
which reuses connections and applies a shared concurrency limit.
Every method is a thin async wrapper around the corresponding function in
:mod:iranquant.market, :mod:iranquant.codal or :mod:iranquant.quant.
Results default to Pandas; pass engine="polars" for Polars.
Examples:
>>> import iranquant as iq
>>> async with iq.AsyncIranQuant(timeout=15.0) as client:
... frame = await client.history("فولاد")
... market = await client.market_watch()
Create the async client.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
timeout
|
float
|
Per-request timeout in seconds. Defaults to
:data: |
DEFAULT_TIMEOUT
|
max_concurrency
|
int
|
Maximum simultaneous requests. Defaults to
:data: |
MAX_CONCURRENCY
|
proxy
|
str | None
|
Optional explicit proxy URL. Environment proxies are ignored unless this is supplied. |
None
|
config
|
IranQuantConfig | None
|
TLS and fallback policy. Defaults to
:class: |
None
|
Examples:
>>> client = AsyncIranQuant(proxy="http://127.0.0.1:9090")
>>> strict = AsyncIranQuant(
... config=IranQuantConfig(allow_tls_fallback=False)
... )
Source code in src/iranquant/__init__.py
client
property
¶
The underlying :class:~iranquant.core.client.AsyncHTTPClient.
close
async
¶
Close the underlying HTTP transports.
Called automatically when used as an async context manager.
__aenter__
async
¶
__aexit__
async
¶
resolve
async
¶
Resolve a symbol name or numeric instrument code to an insCode.
Numeric input (int or an all-digit string, including Persian digits)
is returned unchanged without any network request.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
symbol_or_inscode
|
str | int
|
Persian ticker ( |
required |
Returns:
| Type | Description |
|---|---|
str
|
The numeric |
Raises:
| Type | Description |
|---|---|
SymbolNotFoundError
|
If a symbol name cannot be matched. |
NetworkError
|
If the lookup request fails. |
ParseError
|
If the search response is malformed. |
Examples:
>>> await client.resolve("فولاد")
'46348559193224090'
>>> await client.resolve(46348559193224090)
'46348559193224090'
Source code in src/iranquant/__init__.py
search
async
¶
Search TSETMC instruments by ticker or company name.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
query
|
str
|
Symbol or company-name fragment, e.g. |
required |
engine
|
Engine
|
|
'pandas'
|
Returns:
| Type | Description |
|---|---|
DataFrame
|
One row per match with |
DataFrame
|
|
DataFrame
|
|
Raises:
| Type | Description |
|---|---|
NetworkError
|
If TSETMC cannot be reached. |
ParseError
|
If the response is malformed. |
Examples:
Source code in src/iranquant/__init__.py
history
async
¶
history(
symbol_or_inscode: str | int,
*,
adjust: AdjustMode = "all",
engine: Engine = "pandas",
) -> DataFrame
Fetch backward-adjusted daily OHLCV history.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
symbol_or_inscode
|
str | int
|
Persian ticker or numeric |
required |
adjust
|
AdjustMode
|
|
'all'
|
engine
|
Engine
|
|
'pandas'
|
Returns:
| Type | Description |
|---|---|
DataFrame
|
Columns |
DataFrame
|
|
DataFrame
|
|
DataFrame
|
|
Raises:
| Type | Description |
|---|---|
SymbolNotFoundError
|
If the symbol cannot be resolved. |
NetworkError
|
If TSETMC cannot be reached. |
ParseError
|
If the payload is malformed. |
ValueError
|
If |
Examples:
>>> frame = await client.history("فولاد", adjust="all")
>>> frame[["jdate", "close", "final_price"]].tail()
Source code in src/iranquant/__init__.py
full_history
async
¶
full_history(
symbol_or_inscode: str | int,
*,
adjust: AdjustMode = "all",
engine: Engine = "pandas",
) -> DataFrame
Fetch daily OHLCV merged with retail/institutional client-type data.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
symbol_or_inscode
|
str | int
|
Persian ticker or numeric |
required |
adjust
|
AdjustMode
|
|
'all'
|
engine
|
Engine
|
|
'pandas'
|
Returns:
| Type | Description |
|---|---|
DataFrame
|
The eleven :meth: |
DataFrame
|
|
DataFrame
|
|
DataFrame
|
|
DataFrame
|
|
Raises:
| Type | Description |
|---|---|
SymbolNotFoundError
|
If the symbol cannot be resolved. |
NetworkError
|
If either request fails. |
ParseError
|
If either payload is malformed. |
Examples:
>>> frame = await client.full_history("فولاد")
>>> frame[["jdate", "buy_I_Volume", "sell_N_Count"]].tail()
Source code in src/iranquant/__init__.py
client_type
async
¶
Fetch retail/institutional (حقیقی/حقوقی) history only.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
symbol_or_inscode
|
str | int
|
Persian ticker or numeric |
required |
engine
|
Engine
|
|
'pandas'
|
Returns:
| Type | Description |
|---|---|
DataFrame
|
Columns |
DataFrame
|
|
DataFrame
|
|
DataFrame
|
|
Raises:
| Type | Description |
|---|---|
SymbolNotFoundError
|
If the symbol cannot be resolved. |
NetworkError
|
If the request fails. |
ParseError
|
If the payload is malformed. |
Examples:
>>> frame = await client.client_type("فولاد")
>>> frame[["date", "buy_I_Volume", "sell_I_Volume"]].tail()
Source code in src/iranquant/__init__.py
market_watch
async
¶
Fetch the live market-wide snapshot in one request.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
engine
|
Engine
|
|
'pandas'
|
Returns:
| Type | Description |
|---|---|
DataFrame
|
One row per symbol with |
DataFrame
|
|
DataFrame
|
|
DataFrame
|
|
Raises:
| Type | Description |
|---|---|
NetworkError
|
If the MarketWatch endpoint cannot be reached. |
ParseError
|
If the response body is not valid JSON. |
ValidationError
|
If the payload does not match the schema. |
Examples:
Source code in src/iranquant/__init__.py
order_book
async
¶
Fetch the best-limit order book (levels 1..5).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
symbol_or_inscode
|
str | int
|
Persian ticker or numeric |
required |
engine
|
Engine
|
|
'pandas'
|
Returns:
| Type | Description |
|---|---|
DataFrame
|
Columns |
DataFrame
|
|
Raises:
| Type | Description |
|---|---|
SymbolNotFoundError
|
If the symbol cannot be resolved. |
NetworkError
|
If the request fails. |
ParseError
|
If the response body is not valid JSON. |
Examples:
Source code in src/iranquant/__init__.py
intraday_trades
async
¶
Fetch intraday OHLCV bars for the current/last session.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
symbol_or_inscode
|
str | int
|
Persian ticker or numeric |
required |
engine
|
Engine
|
|
'pandas'
|
Returns:
| Type | Description |
|---|---|
DataFrame
|
Columns |
DataFrame
|
|
Raises:
| Type | Description |
|---|---|
SymbolNotFoundError
|
If the symbol cannot be resolved. |
NetworkError
|
If the request fails. |
ParseError
|
If the response body is not valid JSON. |
Examples:
Source code in src/iranquant/__init__.py
indices_live
async
¶
Fetch live overall, equal-weight and sector index snapshots.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
engine
|
Engine
|
|
'pandas'
|
Returns:
| Type | Description |
|---|---|
DataFrame
|
Standardized columns |
DataFrame
|
|
DataFrame
|
overall/equal-weight rows also carry |
DataFrame
|
|
Raises:
| Type | Description |
|---|---|
NetworkError
|
If no index data can be fetched. |
Examples:
Source code in src/iranquant/__init__.py
index_history
async
¶
Fetch historical daily values for an index code.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
index_code
|
str
|
TSETMC index code. Defaults to the overall index
( |
OVERALL_INDEX_CODE
|
engine
|
Engine
|
|
'pandas'
|
Returns:
| Type | Description |
|---|---|
DataFrame
|
Standardized index columns plus the raw upstream fields, sorted by |
DataFrame
|
|
Raises:
| Type | Description |
|---|---|
NetworkError
|
If both the B2 and B1 endpoints fail. |
ParseError
|
If a body is not valid JSON. |
Examples:
Source code in src/iranquant/__init__.py
codal_search
async
¶
codal_search(
symbol: str | None = None,
letter_type: int = -1,
category: int = -1,
page: int = 1,
audited: bool = True,
not_audited: bool = True,
mains: bool = True,
childs: bool = True,
) -> CodalSearchResponse
Search Codal announcements using this client's transport.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
symbol
|
str | None
|
Optional Persian ticker filter. |
None
|
letter_type
|
int
|
Codal |
-1
|
category
|
int
|
Codal |
-1
|
page
|
int
|
One-based page. Defaults to |
1
|
audited
|
bool
|
Include audited reports. Defaults to |
True
|
not_audited
|
bool
|
Include unaudited reports. Defaults to |
True
|
mains
|
bool
|
Include parent-company reports. Defaults to |
True
|
childs
|
bool
|
Include subsidiary reports. Defaults to |
True
|
Returns:
| Name | Type | Description |
|---|---|---|
A |
CodalSearchResponse
|
class: |
CodalSearchResponse
|
letters have absolute URLs. |
Raises:
| Type | Description |
|---|---|
NetworkError
|
If Codal cannot be reached. |
ParseError
|
If the response is malformed. |
Examples:
Source code in src/iranquant/__init__.py
monthly_reports
async
¶
Fetch monthly activity reports (LetterType=58).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
symbol
|
str
|
Persian ticker, e.g. |
required |
page
|
int
|
One-based page. Defaults to |
1
|
Returns:
| Name | Type | Description |
|---|---|---|
A |
CodalSearchResponse
|
class: |
Raises:
| Type | Description |
|---|---|
NetworkError
|
If Codal cannot be reached. |
ParseError
|
If the response is malformed. |
Examples:
>>> reports = await client.monthly_reports("فولاد")
>>> tables = await client.codal_report(reports.Letters[0])
Source code in src/iranquant/__init__.py
financial_statements
async
¶
Fetch interim financial statements (LetterType=6).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
symbol
|
str
|
Persian ticker, e.g. |
required |
page
|
int
|
One-based page. Defaults to |
1
|
Returns:
| Name | Type | Description |
|---|---|---|
A |
CodalSearchResponse
|
class: |
Raises:
| Type | Description |
|---|---|
NetworkError
|
If Codal cannot be reached. |
ParseError
|
If the response is malformed. |
Examples:
Source code in src/iranquant/__init__.py
codal_report
async
¶
Download and parse all tables of a Codal report.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
url_or_letter
|
str | CodalLetter
|
Report URL or a |
required |
engine
|
Engine
|
|
'pandas'
|
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
A mapping of |
Raises:
| Type | Description |
|---|---|
NetworkError
|
If the report page cannot be downloaded. |
ParseError
|
If the page has no valid datasource JSON. |
ValueError
|
If |
Examples:
>>> tables = await client.codal_report("/Report/123")
>>> for name, table in tables.items():
... print(name, table.shape)
Source code in src/iranquant/__init__.py
parse_codal_report
async
¶
parse_codal_report(
url_or_letter: str | CodalLetter,
*,
engine: Engine = "pandas",
) -> dict[str, Any]
Download and parse a Codal report using this client's transport.
This is the async counterpart of the top-level
:func:parse_codal_report and an alias for :meth:codal_report.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
url_or_letter
|
str | CodalLetter
|
Report URL or a |
required |
engine
|
Engine
|
|
'pandas'
|
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
A mapping of |
Raises:
| Type | Description |
|---|---|
NetworkError
|
If the report page cannot be downloaded. |
ParseError
|
If the page has no valid datasource JSON. |
ValueError
|
If |
Examples:
>>> tables = await client.parse_codal_report("/Report/123")
>>> for name, table in tables.items():
... print(name, table.shape)
Source code in src/iranquant/__init__.py
monthly_sales_summary
async
¶
Analyze a symbol's latest monthly sales report.
Parses the newest LetterType=58 report and compares its current
month with the previous distinct monthly period.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
symbol
|
str
|
Persian ticker, e.g. |
required |
page
|
int
|
One-based Codal result page. Defaults to |
1
|
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
The dictionary produced by |
dict[str, Any]
|
func: |
dict[str, Any]
|
|
dict[str, Any]
|
and a |
Raises:
| Type | Description |
|---|---|
ParseError
|
If no HTML monthly report is available. |
NetworkError
|
If Codal cannot be reached. |
ValueError
|
If the report has no usable tables. |
Examples:
>>> summary = await client.monthly_sales_summary("فولاد")
>>> summary["current_month_sales"]
>>> summary["summary_df"].head()
Source code in src/iranquant/__init__.py
money_flow
async
¶
money_flow(
symbol_or_inscode: str | int,
*,
adjust: AdjustMode = "all",
vol_window: int = 20,
engine: Engine = "pandas",
) -> DataFrame
Fetch full history and compute money-flow/smart-money analytics.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
symbol_or_inscode
|
str | int
|
Persian ticker or numeric |
required |
adjust
|
AdjustMode
|
Price adjustment mode. Defaults to |
'all'
|
vol_window
|
int
|
Rolling volume window. Defaults to |
20
|
engine
|
Engine
|
|
'pandas'
|
Returns:
| Type | Description |
|---|---|
DataFrame
|
The full-history columns plus |
DataFrame
|
|
DataFrame
|
|
DataFrame
|
|
DataFrame
|
|
Raises:
| Type | Description |
|---|---|
SymbolNotFoundError
|
If the symbol cannot be resolved. |
NetworkError
|
If a request fails. |
ParseError
|
If a payload is malformed. |
KeyError
|
If a required history column is missing. |
ValueError
|
If |
Examples:
>>> flow = await client.money_flow("فولاد")
>>> flow[["jdate", "buyer_power_ratio", "smart_money_entry"]].tail()
Source code in src/iranquant/__init__.py
movement_power
async
¶
movement_power(
symbol_or_inscode: str | int,
*,
windows: tuple[int, int, int] = (5, 20, 60),
adjust: AdjustMode = "all",
engine: Engine = "pandas",
) -> DataFrame
Fetch full history and compute the movement-power score.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
symbol_or_inscode
|
str | int
|
Persian ticker or numeric |
required |
windows
|
tuple[int, int, int]
|
Lookback windows. Defaults to |
(5, 20, 60)
|
adjust
|
AdjustMode
|
Price adjustment mode. Defaults to |
'all'
|
engine
|
Engine
|
|
'pandas'
|
Returns:
| Type | Description |
|---|---|
DataFrame
|
The full-history columns plus |
DataFrame
|
|
Raises:
| Type | Description |
|---|---|
SymbolNotFoundError
|
If the symbol cannot be resolved. |
NetworkError
|
If a request fails. |
ParseError
|
If a payload is malformed. |
KeyError
|
If |
ValueError
|
If |
Examples:
>>> power = await client.movement_power("فولاد")
>>> power[["jdate", "movement_power_score"]].tail()
Source code in src/iranquant/__init__.py
watch
¶
watch(
interval: float = 5.0,
symbols: list[str] | None = None,
only_market_hours: bool = False,
) -> AsyncIterator[MarketEvent]
Return an async iterator of live MarketWatcher events.
The returned watcher shares this client's transport and does not close it when iteration ends.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
interval
|
float
|
Seconds between MarketWatch polls. Defaults to |
5.0
|
symbols
|
list[str] | None
|
Optional ticker/ |
None
|
only_market_hours
|
bool
|
Skip polls outside Sat-Wed 09:00-12:30 Tehran
time. Defaults to |
False
|
Returns:
| Type | Description |
|---|---|
AsyncIterator[MarketEvent]
|
An async iterator of :class: |
Raises:
| Type | Description |
|---|---|
ValueError
|
When iterated with |
Examples:
>>> async for event in client.watch(interval=3.0, symbols=["فولاد"]):
... print(event.event_type, event.symbol)
Source code in src/iranquant/__init__.py
IranQuant
¶
Synchronous facade over :class:AsyncIranQuant.
Each method delegates to the same-named module-level function, so an
IranQuant instance can be passed around as a small client object
without managing any HTTP transport or event loop.
Examples:
>>> iq_client = IranQuant()
>>> frame = iq_client.history("فولاد")
>>> screener = iq_client.screener(iq_client.market_watch())
search
¶
Search TSETMC instruments by ticker or company name.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
query
|
str
|
Symbol or company-name fragment, e.g. |
required |
engine
|
Engine
|
|
'pandas'
|
Returns:
| Type | Description |
|---|---|
DataFrame
|
One row per match with |
DataFrame
|
|
DataFrame
|
|
Raises:
| Type | Description |
|---|---|
NetworkError
|
If TSETMC cannot be reached. |
ParseError
|
If the response is malformed. |
Examples:
Source code in src/iranquant/__init__.py
get_inscode
¶
Resolve a symbol or numeric code to its TSETMC insCode.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
symbol_or_inscode
|
str | int
|
Persian ticker or numeric instrument code. |
required |
Returns:
| Type | Description |
|---|---|
str
|
The numeric |
Raises:
| Type | Description |
|---|---|
SymbolNotFoundError
|
If the symbol cannot be matched. |
NetworkError
|
If the lookup request fails. |
Examples:
Source code in src/iranquant/__init__.py
history
¶
history(
symbol_or_inscode: str | int,
*,
adjust: AdjustMode = "all",
engine: Engine = "pandas",
) -> DataFrame
Fetch backward-adjusted daily OHLCV history.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
symbol_or_inscode
|
str | int
|
Persian ticker or numeric |
required |
adjust
|
AdjustMode
|
|
'all'
|
engine
|
Engine
|
|
'pandas'
|
Returns:
| Type | Description |
|---|---|
DataFrame
|
Columns |
DataFrame
|
|
DataFrame
|
and |
Raises:
| Type | Description |
|---|---|
SymbolNotFoundError
|
If the symbol cannot be resolved. |
NetworkError
|
If the request fails. |
ParseError
|
If the payload is malformed. |
Examples:
Source code in src/iranquant/__init__.py
full_history
¶
full_history(
symbol_or_inscode: str | int,
*,
adjust: AdjustMode = "all",
engine: Engine = "pandas",
) -> DataFrame
Fetch daily OHLCV merged with client-type history.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
symbol_or_inscode
|
str | int
|
Persian ticker or numeric |
required |
adjust
|
AdjustMode
|
|
'all'
|
engine
|
Engine
|
|
'pandas'
|
Returns:
| Type | Description |
|---|---|
DataFrame
|
The |
DataFrame
|
client-type columns. |
Raises:
| Type | Description |
|---|---|
SymbolNotFoundError
|
If the symbol cannot be resolved. |
NetworkError
|
If a request fails. |
ParseError
|
If a payload is malformed. |
Examples:
Source code in src/iranquant/__init__.py
client_type
¶
Fetch retail/institutional client-type history only.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
symbol_or_inscode
|
str | int
|
Persian ticker or numeric |
required |
engine
|
Engine
|
|
'pandas'
|
Returns:
| Type | Description |
|---|---|
DataFrame
|
Columns |
DataFrame
|
client-type columns. |
Raises:
| Type | Description |
|---|---|
SymbolNotFoundError
|
If the symbol cannot be resolved. |
NetworkError
|
If the request fails. |
ParseError
|
If the payload is malformed. |
Examples:
Source code in src/iranquant/__init__.py
market_watch
¶
Fetch the live market-wide snapshot in one request.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
engine
|
Engine
|
|
'pandas'
|
Returns:
| Type | Description |
|---|---|
DataFrame
|
One row per symbol with the MarketWatch columns described in |
DataFrame
|
func: |
Raises:
| Type | Description |
|---|---|
NetworkError
|
If the endpoint cannot be reached. |
ParseError
|
If the response body is not valid JSON. |
Examples:
Source code in src/iranquant/__init__.py
order_book
¶
Fetch the best-limit order book (levels 1..5).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
symbol_or_inscode
|
str | int
|
Persian ticker or numeric |
required |
engine
|
Engine
|
|
'pandas'
|
Returns:
| Type | Description |
|---|---|
DataFrame
|
Columns |
DataFrame
|
|
Raises:
| Type | Description |
|---|---|
SymbolNotFoundError
|
If the symbol cannot be resolved. |
NetworkError
|
If the request fails. |
Examples:
Source code in src/iranquant/__init__.py
intraday_trades
¶
Fetch intraday OHLCV bars for the current/last session.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
symbol_or_inscode
|
str | int
|
Persian ticker or numeric |
required |
engine
|
Engine
|
|
'pandas'
|
Returns:
| Type | Description |
|---|---|
DataFrame
|
Columns |
DataFrame
|
|
Raises:
| Type | Description |
|---|---|
SymbolNotFoundError
|
If the symbol cannot be resolved. |
NetworkError
|
If the request fails. |
Examples:
Source code in src/iranquant/__init__.py
indices_live
¶
Fetch live overall, equal-weight and sector index snapshots.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
engine
|
Engine
|
|
'pandas'
|
Returns:
| Type | Description |
|---|---|
DataFrame
|
Standardized index columns described in |
DataFrame
|
func: |
Raises:
| Type | Description |
|---|---|
NetworkError
|
If no index data can be fetched. |
Examples:
Source code in src/iranquant/__init__.py
index_history
¶
Fetch historical daily values for an index code.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
index_code
|
str
|
TSETMC index code. Defaults to the overall index. |
OVERALL_INDEX_CODE
|
engine
|
Engine
|
|
'pandas'
|
Returns:
| Type | Description |
|---|---|
DataFrame
|
Standardized index columns plus raw upstream fields, sorted by |
DataFrame
|
date. |
Raises:
| Type | Description |
|---|---|
NetworkError
|
If both the B2 and B1 endpoints fail. |
ParseError
|
If a body is not valid JSON. |
Examples:
Source code in src/iranquant/__init__.py
codal_search
¶
codal_search(
symbol: str | None = None,
letter_type: int = -1,
category: int = -1,
page: int = 1,
audited: bool = True,
not_audited: bool = True,
mains: bool = True,
childs: bool = True,
) -> CodalSearchResponse
Search Codal announcements.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
symbol
|
str | None
|
Optional Persian ticker filter. |
None
|
letter_type
|
int
|
|
-1
|
category
|
int
|
|
-1
|
page
|
int
|
One-based page. Defaults to |
1
|
audited
|
bool
|
Include audited reports. Defaults to |
True
|
not_audited
|
bool
|
Include unaudited reports. Defaults to |
True
|
mains
|
bool
|
Include parent-company reports. Defaults to |
True
|
childs
|
bool
|
Include subsidiary reports. Defaults to |
True
|
Returns:
| Name | Type | Description |
|---|---|---|
A |
CodalSearchResponse
|
class: |
Raises:
| Type | Description |
|---|---|
NetworkError
|
If Codal cannot be reached. |
ParseError
|
If the response is malformed. |
Examples:
Source code in src/iranquant/__init__.py
monthly_reports
¶
Fetch monthly activity reports (LetterType=58).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
symbol
|
str
|
Persian ticker, e.g. |
required |
page
|
int
|
One-based page. Defaults to |
1
|
Returns:
| Name | Type | Description |
|---|---|---|
A |
CodalSearchResponse
|
class: |
Raises:
| Type | Description |
|---|---|
NetworkError
|
If Codal cannot be reached. |
ParseError
|
If the response is malformed. |
Examples:
Source code in src/iranquant/__init__.py
financial_statements
¶
Fetch interim financial statements (LetterType=6).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
symbol
|
str
|
Persian ticker, e.g. |
required |
page
|
int
|
One-based page. Defaults to |
1
|
Returns:
| Name | Type | Description |
|---|---|---|
A |
CodalSearchResponse
|
class: |
Raises:
| Type | Description |
|---|---|
NetworkError
|
If Codal cannot be reached. |
ParseError
|
If the response is malformed. |
Examples:
Source code in src/iranquant/__init__.py
codal_report
¶
Download and parse all tables of a Codal report.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
url_or_letter
|
str | CodalLetter
|
Report URL or a |
required |
engine
|
Engine
|
|
'pandas'
|
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
A mapping of |
Raises:
| Type | Description |
|---|---|
NetworkError
|
If the report page cannot be downloaded. |
ParseError
|
If the page has no valid datasource JSON. |
Examples:
Source code in src/iranquant/__init__.py
parse_codal_report
¶
parse_codal_report(
url_or_letter: str | CodalLetter,
*,
engine: Engine = "pandas",
) -> dict[str, Any]
Download and parse all tables of a Codal report.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
url_or_letter
|
str | CodalLetter
|
Report URL or a |
required |
engine
|
Engine
|
|
'pandas'
|
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
A mapping of |
Raises:
| Type | Description |
|---|---|
NetworkError
|
If the report page cannot be downloaded. |
ParseError
|
If the page has no valid datasource JSON. |
Examples:
Source code in src/iranquant/__init__.py
monthly_sales_summary
¶
Analyze a symbol's latest monthly sales report.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
symbol
|
str
|
Persian ticker, e.g. |
required |
page
|
int
|
One-based Codal result page. Defaults to |
1
|
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
The monthly analyzer result plus report metadata and a |
dict[str, Any]
|
|
Raises:
| Type | Description |
|---|---|
ParseError
|
If no HTML monthly report is available. |
NetworkError
|
If Codal cannot be reached. |
Examples:
Source code in src/iranquant/__init__.py
money_flow
¶
money_flow(
symbol_or_inscode: str | int,
*,
adjust: AdjustMode = "all",
vol_window: int = 20,
engine: Engine = "pandas",
) -> DataFrame
Fetch full history and compute smart-money/flow analytics.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
symbol_or_inscode
|
str | int
|
Persian ticker or numeric |
required |
adjust
|
AdjustMode
|
Price adjustment mode. Defaults to |
'all'
|
vol_window
|
int
|
Rolling volume window. Defaults to |
20
|
engine
|
Engine
|
|
'pandas'
|
Returns:
| Type | Description |
|---|---|
DataFrame
|
The full-history columns plus the money-flow columns described in |
DataFrame
|
func: |
Raises:
| Type | Description |
|---|---|
SymbolNotFoundError
|
If the symbol cannot be resolved. |
NetworkError
|
If a request fails. |
KeyError
|
If a required history column is missing. |
ValueError
|
If |
Examples:
Source code in src/iranquant/__init__.py
movement_power
¶
movement_power(
symbol_or_inscode: str | int,
*,
windows: tuple[int, int, int] = (5, 20, 60),
adjust: AdjustMode = "all",
engine: Engine = "pandas",
) -> DataFrame
Fetch full history and compute the movement-power score.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
symbol_or_inscode
|
str | int
|
Persian ticker or numeric |
required |
windows
|
tuple[int, int, int]
|
Lookback windows. Defaults to |
(5, 20, 60)
|
adjust
|
AdjustMode
|
Price adjustment mode. Defaults to |
'all'
|
engine
|
Engine
|
|
'pandas'
|
Returns:
| Type | Description |
|---|---|
DataFrame
|
The full-history columns plus |
DataFrame
|
|
Raises:
| Type | Description |
|---|---|
SymbolNotFoundError
|
If the symbol cannot be resolved. |
NetworkError
|
If a request fails. |
KeyError
|
If |
ValueError
|
If |
Examples:
Source code in src/iranquant/__init__.py
screener
¶
Wrap a MarketWatch frame in a :class:~iranquant.MarketScreener.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
frame
|
DataFrame
|
A MarketWatch (or batch) frame. |
required |
Returns:
| Type | Description |
|---|---|
MarketScreener
|
A screener bound to |
Raises:
| Type | Description |
|---|---|
TypeError
|
When a filter is run with a non-Pandas/Polars frame. |
Examples:
Source code in src/iranquant/__init__.py
analyze_monthly_sales
¶
Summarize a monthly activity report's production & sales table.
The main table is the one whose key contains "تولید و فروش"; if no such
key exists, the table with the most numeric cells is used. Summary rows are
detected by normalized جمع/مجموع labels. A final جمع row is
preferred; when it is absent, the جمع فروش داخلی, جمع فروش صادراتی
and جمع درآمد ارائه خدمات rows are added together.
Values are reported in million Rials, the unit printed in the source
table. prev_month_sales is only populated when the same table exposes a
separate previous-month period; :func:monthly_sales_summary fills it by
parsing the previous monthly letter.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
tables
|
dict[str, Any]
|
The mapping returned by
:func: |
required |
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
A dictionary with: |
dict[str, Any]
|
|
dict[str, Any]
|
|
dict[str, Any]
|
|
dict[str, Any]
|
|
dict[str, Any]
|
|
dict[str, Any]
|
|
dict[str, Any]
|
|
dict[str, Any]
|
|
dict[str, Any]
|
|
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
TypeError
|
If a table value is not a Pandas or Polars DataFrame. |
Examples:
>>> letter = iq.monthly_reports("فولاد").Letters[0]
>>> tables = iq.parse_codal_report(letter)
>>> summary = iq.analyze_monthly_sales(tables)
>>> summary["current_month_sales"]
662639489.0
>>> summary["summary_df"][["شرح - نام محصول"]]
Source code in src/iranquant/codal/monthly.py
308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 | |
fetch_and_parse_report
async
¶
fetch_and_parse_report(
url_or_letter: str | CodalLetter,
engine: Engine = "pandas",
*,
client: AsyncHTTPClient | None = None,
) -> dict[str, Any]
Download a Codal report page and parse all of its datasource tables.
Relative URLs (including those on :class:~iranquant.models.codal.CodalLetter)
are resolved with :func:~iranquant.codal.search.resolve_codal_url before
the request is made.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
url_or_letter
|
str | CodalLetter
|
Either an absolute/relative report URL or a
|
required |
engine
|
Engine
|
|
'pandas'
|
client
|
AsyncHTTPClient | None
|
Optional shared :class: |
None
|
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
The dictionary produced by :func: |
dict[str, Any]
|
|
Raises:
| Type | Description |
|---|---|
NetworkError
|
If the report page cannot be downloaded. |
ParseError
|
If the page has no valid |
ValueError
|
If |
Examples:
>>> letter = reports.Letters[0]
>>> tables = await fetch_and_parse_report(letter)
>>> for name, table in tables.items():
... print(name, table.shape)
Source code in src/iranquant/codal/parser.py
get_financial_statements
async
¶
get_financial_statements(
symbol: str,
page: int = 1,
*,
client: AsyncHTTPClient | None = None,
) -> CodalSearchResponse
Interim financial statements (LetterType=6).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
symbol
|
str
|
Persian ticker, e.g. |
required |
page
|
int
|
One-based result page. Defaults to |
1
|
client
|
AsyncHTTPClient | None
|
Optional shared :class: |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
A |
CodalSearchResponse
|
class: |
CodalSearchResponse
|
financial-statement letters. |
Raises:
| Type | Description |
|---|---|
NetworkError
|
If Codal cannot be reached. |
ParseError
|
If the response is malformed. |
Examples:
>>> statements = await get_financial_statements("فولاد")
>>> statements.Letters[0].Title
'صورتهای مالی ۳ ماهه'
Source code in src/iranquant/codal/search.py
get_monthly_reports
async
¶
get_monthly_reports(
symbol: str,
page: int = 1,
*,
client: AsyncHTTPClient | None = None,
) -> CodalSearchResponse
Monthly activity reports (گزارش فعالیت ماهانه, LetterType=58).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
symbol
|
str
|
Persian ticker, e.g. |
required |
page
|
int
|
One-based result page. Defaults to |
1
|
client
|
AsyncHTTPClient | None
|
Optional shared :class: |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
A |
CodalSearchResponse
|
class: |
CodalSearchResponse
|
|
|
CodalSearchResponse
|
tables. |
Raises:
| Type | Description |
|---|---|
NetworkError
|
If Codal cannot be reached. |
ParseError
|
If the response is malformed. |
Examples:
>>> reports = await get_monthly_reports("فولاد")
>>> tables = await fetch_and_parse_report(reports.Letters[0])
Source code in src/iranquant/codal/search.py
search_codal
async
¶
search_codal(
symbol: str | None = None,
letter_type: int = -1,
category: int = -1,
page: int = 1,
audited: bool = True,
not_audited: bool = True,
mains: bool = True,
childs: bool = True,
*,
client: AsyncHTTPClient | None = None,
) -> CodalSearchResponse
Search Codal announcements.
Parameters mirror the search.codal.ir query API. A temporary client is
created and closed when client is not supplied. Every returned letter
has its Url, ExcelUrl and PdfUrl resolved to absolute URLs.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
symbol
|
str | None
|
Optional Persian ticker to filter by, e.g. |
None
|
letter_type
|
int
|
Codal |
-1
|
category
|
int
|
Codal |
-1
|
page
|
int
|
One-based result page. Defaults to |
1
|
audited
|
bool
|
Include audited reports. Defaults to |
True
|
not_audited
|
bool
|
Include unaudited reports. Defaults to |
True
|
mains
|
bool
|
Include parent-company reports. Defaults to |
True
|
childs
|
bool
|
Include subsidiary reports. Defaults to |
True
|
client
|
AsyncHTTPClient | None
|
Optional shared :class: |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
A |
CodalSearchResponse
|
class: |
CodalSearchResponse
|
|
Raises:
| Type | Description |
|---|---|
NetworkError
|
If |
ParseError
|
If the response is not valid JSON or does not match the expected schema. |
Examples:
>>> response = await search_codal("فولاد", letter_type=58)
>>> response.Total
12
>>> response.Letters[0].Url.startswith("https://codal.ir")
True
Source code in src/iranquant/codal/search.py
95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 | |
_monthly_sales_summary
async
¶
_monthly_sales_summary(
symbol: str,
page: int = 1,
*,
client: AsyncHTTPClient | None = None,
) -> dict[str, Any]
Fetch and analyze a symbol's latest monthly sales report.
The newest report on page is parsed, and its previous distinct monthly
period is parsed too so a true Month-over-Month comparison can be computed.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
symbol
|
str
|
Persian ticker, e.g. |
required |
page
|
int
|
One-based Codal result page. Defaults to |
1
|
client
|
AsyncHTTPClient | None
|
Optional shared :class: |
None
|
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
The dictionary from :func: |
dict[str, Any]
|
|
dict[str, Any]
|
|
Raises:
| Type | Description |
|---|---|
ParseError
|
If Codal returns no HTML monthly reports. |
NetworkError
|
If Codal or the report page cannot be fetched. |
ValueError
|
If the latest report has no usable tables. |
Examples:
>>> summary = await monthly_sales_summary("فولاد")
>>> summary["current_month_sales"]
>>> summary["mom_change_pct"]
Source code in src/iranquant/codal/monthly.py
412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 | |
to_dataframe
¶
Convert a list of record dictionaries to a Pandas or Polars DataFrame.
An empty records list still produces a valid (empty) DataFrame for both
engines. Column order follows the key insertion order of the first record.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
records
|
list[dict[str, Any]]
|
Row-oriented records, typically produced by the market and Codal modules. Every record should share the same keys. |
required |
engine
|
Engine
|
|
'pandas'
|
Returns:
| Name | Type | Description |
|---|---|---|
A |
DataFrame
|
class: |
DataFrame
|
|
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
Examples:
>>> to_dataframe([{"symbol": "فولاد", "close": 4150.0}])
symbol close
0 فولاد 4150.0
>>> to_dataframe([], engine="polars").height
0
Source code in src/iranquant/core/dataframe.py
normalize_persian
¶
Normalize Persian/Arabic text for reliable comparison.
Converts Arabic yeh/kaf/teh-marbuta to their Persian equivalents, converts Arabic-Indic and Persian digits to ASCII digits, removes zero-width and directional control characters, and collapses whitespace.
This is what makes "فولاد" written with an Arabic yeh and the same
symbol written with a Persian yeh resolve to the same TSETMC instrument.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
text
|
str
|
Any string, including Persian, Arabic-Indic or mixed text. |
required |
Returns:
| Type | Description |
|---|---|
str
|
The normalized string with single spaces and ASCII digits. |
Examples:
Source code in src/iranquant/core/normalizer.py
run_sync
¶
Run coro to completion from synchronous code.
A plain asyncio.run is used when no event loop is running. Inside an
already-running loop (Jupyter, Colab, async applications) the coroutine is
executed on a fresh loop in a background thread, which avoids the usual
"asyncio.run() cannot be called from a running event loop" error.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
coro
|
Coroutine[Any, Any, T]
|
An already-created coroutine object. |
required |
Returns:
| Type | Description |
|---|---|
T
|
Whatever the coroutine returns. |
Raises:
| Type | Description |
|---|---|
BaseException
|
Any exception raised by the coroutine is re-raised in the calling thread. |
Examples:
Source code in src/iranquant/core/sync.py
compute_money_flow
¶
Add smart-money, per-capita and real/legal flow columns.
Works with both Pandas and Polars inputs and returns a frame of the same
type. All monetary per-capita values are expressed in Rials
(*_m variants are in million Tomans).
The required input columns are final_price, close, volume,
buy_I_Volume, sell_I_Volume, buy_I_Count and sell_I_Count
(all present in :func:iranquant.full_history). Columns are computed as:
real_buy_per_capita = buy_I_Volume * final_price / max(buy_I_Count, 1)real_sell_per_capita = sell_I_Volume * final_price / max(sell_I_Count, 1)buyer_power_ratio = real_buy_per_capita / max(real_sell_per_capita, 1)net_real_value = (buy_I_Volume - sell_I_Volume) * final_priceownership_change_pct = ((buy_I_Volume - sell_I_Volume) / max(volume, 1)) * 100close_vs_final_pct = ((close - final_price) / max(final_price, 1)) * 100vol_ratio = volume / rolling_mean(volume, vol_window)
smart_money_entry is True when vol_ratio >= 1.8 and
buyer_power_ratio >= 1.5 and net_real_value > 0 and
close >= final_price. smart_money_exit mirrors it with
buyer_power_ratio <= 0.67, net_real_value < 0 and
close <= final_price.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
frame
|
DataFrame
|
A history frame. Any extra columns (including |
required |
vol_window
|
int
|
Rolling window used for the volume-ratio baseline. Must be
at least |
20
|
Returns:
| Type | Description |
|---|---|
DataFrame
|
A frame of the same engine with all input columns plus: |
DataFrame
|
|
DataFrame
|
|
DataFrame
|
|
DataFrame
|
|
DataFrame
|
|
DataFrame
|
|
DataFrame
|
|
DataFrame
|
|
DataFrame
|
|
DataFrame
|
|
DataFrame
|
|
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
KeyError
|
If any required input column is missing. |
Examples:
>>> flow = compute_money_flow(iq.full_history("فولاد"))
>>> flow[["jdate", "buyer_power_ratio", "smart_money_entry"]].tail(3)
The Polars path preserves pl.DataFrame::
>>> import polars as pl
>>> flow = compute_money_flow(iq.full_history("فولاد", engine="polars"))
>>> flow.filter(pl.col("smart_money_entry")).height
Source code in src/iranquant/quant/money_flow.py
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 | |
compute_movement_power
¶
compute_movement_power(
frame: DataFrame,
windows: tuple[int, int, int] = (5, 20, 60),
) -> DataFrame
Compute a signed multi-timeframe Kaufman efficiency power score.
For each window w the signed Kaufman efficiency ratio is::
er_w = sign(close - close.shift(w))
* abs(close - close.shift(w))
/ rolling_sum(abs(close.diff()), w)
The score starts as a weighted sum of the signed ratios. With exactly
three windows the weights are (0.5, 0.3, 0.2); otherwise all windows
are equally weighted. The score is then multiplied by a volume factor
(volume / rolling_mean(volume, min(windows)) clipped to [0.5, 2.0])
and, when present, a buyer-power factor
(clip(buyer_power_ratio, 0.5, 3.0) / 1.5 clipped to [0.5, 1.5]),
scaled by 100 and clipped to [-100, +100].
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
frame
|
DataFrame
|
A history frame containing |
required |
windows
|
tuple[int, int, int]
|
One or more positive lookback windows. Defaults to
|
(5, 20, 60)
|
Returns:
| Type | Description |
|---|---|
DataFrame
|
A frame of the same engine with all input columns plus: |
DataFrame
|
|
DataFrame
|
(for example |
DataFrame
|
|
DataFrame
|
buyer-power-adjusted score in |
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
KeyError
|
If the |
Examples:
>>> power = compute_movement_power(iq.full_history("فولاد"))
>>> power[["jdate", "er_5", "er_20", "movement_power_score"]].tail(3)
>>> power.sort_values("movement_power_score", ascending=False).head()
Source code in src/iranquant/quant/momentum.py
196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 | |
detect_swing_legs
¶
Detect ZigZag swing legs from the close column.
A percentage-reversal ZigZag is run over the closing prices. A leg is
confirmed whenever price reverses by at least reversal_pct from the
running extreme; the final, still-active leg is appended so the output
always ends at the last bar. Input and output engine types match.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
frame
|
DataFrame
|
A history frame containing |
required |
reversal_pct
|
float
|
Minimum reversal, in percent, required to confirm a new
pivot. Must be positive. Defaults to |
5.0
|
Returns:
| Type | Description |
|---|---|
DataFrame
|
One row per leg (completed legs plus the active leg) with columns: |
DataFrame
|
|
DataFrame
|
|
DataFrame
|
|
DataFrame
|
positional indexes when |
DataFrame
|
|
DataFrame
|
|
DataFrame
|
|
DataFrame
|
|
DataFrame
|
|
DataFrame
|
|
DataFrame
|
divided by the previous leg's; |
DataFrame
|
previous average is zero. |
DataFrame
|
An empty frame with the same columns is returned for empty input or |
DataFrame
|
when no pivots are found. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
KeyError
|
If the |
Examples:
>>> legs = detect_swing_legs(iq.history("فولاد"), reversal_pct=5.0)
>>> legs[["direction", "leg_return_pct", "leg_velocity"]].tail(5)
>>> legs[legs["leg_volume_expansion"] > 1.5]["direction"].tolist()
Source code in src/iranquant/quant/momentum.py
84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 | |
is_market_open
¶
Return True during Saturday-Wednesday TSETMC sessions (09:00-12:30 IRST).
Python weekday numbering is Monday=0, so the active days are 5, 6, 0, 1
and 2. The time is interpreted in Asia/Tehran (with a fixed +03:30
fallback when tzdata is unavailable).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
now
|
datetime | None
|
Optional aware or naive datetime. Naive values are assumed to be Tehran local time. Defaults to the current instant. |
None
|
Returns:
| Type | Description |
|---|---|
bool
|
|
bool
|
local time is between 09:00 and 12:30 inclusive, otherwise |
Examples:
>>> import datetime as dt
>>> is_market_open(dt.datetime(2026, 10, 31, 10, 0)) # Saturday
True
>>> is_market_open(dt.datetime(2026, 10, 30, 13, 0)) # Friday
False
Source code in src/iranquant/stream/watcher.py
_as_ins_code
¶
_run_with_client
¶
search
¶
Sync: search TSETMC instruments.
A temporary client is created and closed for the call. Safe to call inside an existing event loop (Jupyter/Colab).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
query
|
str
|
Symbol or company-name fragment, e.g. |
required |
engine
|
Engine
|
|
'pandas'
|
Returns:
| Type | Description |
|---|---|
DataFrame
|
One row per match with |
DataFrame
|
|
DataFrame
|
|
Raises:
| Type | Description |
|---|---|
NetworkError
|
If TSETMC cannot be reached. |
ParseError
|
If the response is malformed. |
Examples:
Source code in src/iranquant/__init__.py
get_inscode
¶
Sync: resolve a symbol name or numeric code to its TSETMC insCode.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
symbol_or_inscode
|
str | int
|
Persian ticker or a numeric instrument code. |
required |
Returns:
| Type | Description |
|---|---|
str
|
The numeric |
str
|
network. |
Raises:
| Type | Description |
|---|---|
SymbolNotFoundError
|
If the symbol cannot be matched. |
NetworkError
|
If the lookup request fails. |
ParseError
|
If the response is malformed. |
Examples:
Source code in src/iranquant/__init__.py
history
¶
history(
symbol_or_inscode: str | int,
*,
adjust: AdjustMode = "all",
engine: Engine = "pandas",
) -> DataFrame
Sync: daily OHLCV history.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
symbol_or_inscode
|
str | int
|
Persian ticker or numeric |
required |
adjust
|
AdjustMode
|
|
'all'
|
engine
|
Engine
|
|
'pandas'
|
Returns:
| Type | Description |
|---|---|
DataFrame
|
Columns |
DataFrame
|
|
DataFrame
|
|
Raises:
| Type | Description |
|---|---|
SymbolNotFoundError
|
If the symbol cannot be resolved. |
NetworkError
|
If TSETMC cannot be reached. |
ParseError
|
If the payload is malformed. |
Examples:
Source code in src/iranquant/__init__.py
full_history
¶
full_history(
symbol_or_inscode: str | int,
*,
adjust: AdjustMode = "all",
engine: Engine = "pandas",
) -> DataFrame
Sync: daily OHLCV merged with client-type history.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
symbol_or_inscode
|
str | int
|
Persian ticker or numeric |
required |
adjust
|
AdjustMode
|
|
'all'
|
engine
|
Engine
|
|
'pandas'
|
Returns:
| Name | Type | Description |
|---|---|---|
The |
DataFrame
|
func: |
DataFrame
|
|
|
DataFrame
|
|
|
DataFrame
|
|
Raises:
| Type | Description |
|---|---|
SymbolNotFoundError
|
If the symbol cannot be resolved. |
NetworkError
|
If a request fails. |
ParseError
|
If a payload is malformed. |
Examples:
Source code in src/iranquant/__init__.py
client_type
¶
Sync: retail/institutional client-type history.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
symbol_or_inscode
|
str | int
|
Persian ticker or numeric |
required |
engine
|
Engine
|
|
'pandas'
|
Returns:
| Type | Description |
|---|---|
DataFrame
|
Columns |
DataFrame
|
|
DataFrame
|
|
DataFrame
|
|
Raises:
| Type | Description |
|---|---|
SymbolNotFoundError
|
If the symbol cannot be resolved. |
NetworkError
|
If the request fails. |
ParseError
|
If the payload is malformed. |
Examples:
Source code in src/iranquant/__init__.py
market_watch
¶
Sync: live market-wide snapshot.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
engine
|
Engine
|
|
'pandas'
|
Returns:
| Type | Description |
|---|---|
DataFrame
|
One row per symbol with |
DataFrame
|
|
DataFrame
|
|
DataFrame
|
|
Raises:
| Type | Description |
|---|---|
NetworkError
|
If the MarketWatch endpoint cannot be reached. |
ParseError
|
If the response body is not valid JSON. |
Examples:
Source code in src/iranquant/__init__.py
order_book
¶
Sync: best-limit order book.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
symbol_or_inscode
|
str | int
|
Persian ticker or numeric |
required |
engine
|
Engine
|
|
'pandas'
|
Returns:
| Type | Description |
|---|---|
DataFrame
|
Columns |
DataFrame
|
|
Raises:
| Type | Description |
|---|---|
SymbolNotFoundError
|
If the symbol cannot be resolved. |
NetworkError
|
If the request fails. |
ParseError
|
If the response body is not valid JSON. |
Examples:
Source code in src/iranquant/__init__.py
intraday_trades
¶
Sync: intraday OHLCV bars for the current/last session.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
symbol_or_inscode
|
str | int
|
Persian ticker or numeric |
required |
engine
|
Engine
|
|
'pandas'
|
Returns:
| Type | Description |
|---|---|
DataFrame
|
Columns |
DataFrame
|
|
Raises:
| Type | Description |
|---|---|
SymbolNotFoundError
|
If the symbol cannot be resolved. |
NetworkError
|
If the request fails. |
ParseError
|
If the response body is not valid JSON. |
Examples:
Source code in src/iranquant/__init__.py
indices_live
¶
Sync: live index snapshots.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
engine
|
Engine
|
|
'pandas'
|
Returns:
| Type | Description |
|---|---|
DataFrame
|
Standardized columns |
DataFrame
|
|
Raises:
| Type | Description |
|---|---|
NetworkError
|
If no index data can be fetched. |
Examples:
Source code in src/iranquant/__init__.py
index_history
¶
Sync: index daily history.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
index_code
|
str
|
TSETMC index code. Defaults to the overall index. |
OVERALL_INDEX_CODE
|
engine
|
Engine
|
|
'pandas'
|
Returns:
| Type | Description |
|---|---|
DataFrame
|
Standardized index columns plus raw upstream fields, sorted by date. |
Raises:
| Type | Description |
|---|---|
NetworkError
|
If both the B2 and B1 endpoints fail. |
ParseError
|
If a body is not valid JSON. |
Examples:
Source code in src/iranquant/__init__.py
codal_search
¶
codal_search(
symbol: str | None = None,
letter_type: int = -1,
category: int = -1,
page: int = 1,
audited: bool = True,
not_audited: bool = True,
mains: bool = True,
childs: bool = True,
) -> CodalSearchResponse
Sync: search Codal announcements.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
symbol
|
str | None
|
Optional Persian ticker filter. |
None
|
letter_type
|
int
|
Codal |
-1
|
category
|
int
|
Codal |
-1
|
page
|
int
|
One-based page. Defaults to |
1
|
audited
|
bool
|
Include audited reports. Defaults to |
True
|
not_audited
|
bool
|
Include unaudited reports. Defaults to |
True
|
mains
|
bool
|
Include parent-company reports. Defaults to |
True
|
childs
|
bool
|
Include subsidiary reports. Defaults to |
True
|
Returns:
| Name | Type | Description |
|---|---|---|
A |
CodalSearchResponse
|
class: |
CodalSearchResponse
|
URLs. |
Raises:
| Type | Description |
|---|---|
NetworkError
|
If Codal cannot be reached. |
ParseError
|
If the response is malformed. |
Examples:
Source code in src/iranquant/__init__.py
monthly_reports
¶
Sync: monthly activity reports (گزارش فعالیت ماهانه).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
symbol
|
str
|
Persian ticker, e.g. |
required |
page
|
int
|
One-based page. Defaults to |
1
|
Returns:
| Name | Type | Description |
|---|---|---|
A |
CodalSearchResponse
|
class: |
CodalSearchResponse
|
|
Raises:
| Type | Description |
|---|---|
NetworkError
|
If Codal cannot be reached. |
ParseError
|
If the response is malformed. |
Examples:
Source code in src/iranquant/__init__.py
financial_statements
¶
Sync: interim financial statements.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
symbol
|
str
|
Persian ticker, e.g. |
required |
page
|
int
|
One-based page. Defaults to |
1
|
Returns:
| Name | Type | Description |
|---|---|---|
A |
CodalSearchResponse
|
class: |
CodalSearchResponse
|
|
Raises:
| Type | Description |
|---|---|
NetworkError
|
If Codal cannot be reached. |
ParseError
|
If the response is malformed. |
Examples:
Source code in src/iranquant/__init__.py
codal_report
¶
Sync: download and parse all tables of a Codal report.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
url_or_letter
|
str | CodalLetter
|
Report URL or a |
required |
engine
|
Engine
|
|
'pandas'
|
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
A mapping of |
Raises:
| Type | Description |
|---|---|
NetworkError
|
If the report page cannot be downloaded. |
ParseError
|
If the page has no valid datasource JSON. |
ValueError
|
If |
Examples:
>>> tables = iq.codal_report("/Report/123")
>>> {name: table.shape for name, table in tables.items()}
Source code in src/iranquant/__init__.py
parse_codal_report
¶
parse_codal_report(
url_or_letter: str | CodalLetter,
*,
engine: Engine = "pandas",
) -> dict[str, Any]
Sync: download and parse all tables of a Codal report.
This is an explicit, discoverable alias for :func:codal_report; both
return the same mapping. A temporary client is created and closed for the
call, and it is safe to use inside a running event loop.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
url_or_letter
|
str | CodalLetter
|
Report URL or a |
required |
engine
|
Engine
|
|
'pandas'
|
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
A mapping of |
Raises:
| Type | Description |
|---|---|
NetworkError
|
If the report page cannot be downloaded. |
ParseError
|
If the page has no valid datasource JSON. |
ValueError
|
If |
Examples:
>>> letter = iq.monthly_reports("فولاد").Letters[0]
>>> tables = iq.parse_codal_report(letter)
>>> summary = iq.analyze_monthly_sales(tables)
Source code in src/iranquant/__init__.py
monthly_sales_summary
¶
Sync: analyze a symbol's latest monthly sales report.
Fetches the newest LetterType=58 report and compares its current month
with the previous distinct monthly period. Values are in million Rials.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
symbol
|
str
|
Persian ticker, e.g. |
required |
page
|
int
|
One-based Codal result page. Defaults to |
1
|
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
The dictionary produced by |
dict[str, Any]
|
func: |
dict[str, Any]
|
|
dict[str, Any]
|
|
Raises:
| Type | Description |
|---|---|
ParseError
|
If no HTML monthly report is available. |
NetworkError
|
If Codal cannot be reached. |
ValueError
|
If the report has no usable tables. |
Examples:
>>> summary = iq.monthly_sales_summary("فولاد")
>>> summary["current_month_sales"]
662639489.0
>>> summary["yoy_change_pct"]
Source code in src/iranquant/__init__.py
money_flow
¶
money_flow(
symbol_or_inscode: str | int,
*,
adjust: AdjustMode = "all",
vol_window: int = 20,
engine: Engine = "pandas",
) -> DataFrame
Sync: fetch full history and compute smart-money/flow analytics.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
symbol_or_inscode
|
str | int
|
Persian ticker or numeric |
required |
adjust
|
AdjustMode
|
Price adjustment mode. Defaults to |
'all'
|
vol_window
|
int
|
Rolling volume window. Defaults to |
20
|
engine
|
Engine
|
|
'pandas'
|
Returns:
| Type | Description |
|---|---|
DataFrame
|
The full-history columns plus the money-flow columns described in |
DataFrame
|
func: |
Raises:
| Type | Description |
|---|---|
SymbolNotFoundError
|
If the symbol cannot be resolved. |
NetworkError
|
If a request fails. |
ParseError
|
If a payload is malformed. |
KeyError
|
If a required history column is missing. |
ValueError
|
If |
Examples:
>>> flow = iq.money_flow("فولاد")
>>> flow[["jdate", "buyer_power_ratio", "smart_money_entry"]].tail()
Source code in src/iranquant/__init__.py
movement_power
¶
movement_power(
symbol_or_inscode: str | int,
*,
windows: tuple[int, int, int] = (5, 20, 60),
adjust: AdjustMode = "all",
engine: Engine = "pandas",
) -> DataFrame
Sync: fetch full history and compute the movement-power score.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
symbol_or_inscode
|
str | int
|
Persian ticker or numeric |
required |
windows
|
tuple[int, int, int]
|
Lookback windows. Defaults to |
(5, 20, 60)
|
adjust
|
AdjustMode
|
Price adjustment mode. Defaults to |
'all'
|
engine
|
Engine
|
|
'pandas'
|
Returns:
| Type | Description |
|---|---|
DataFrame
|
The full-history columns plus |
DataFrame
|
|
Raises:
| Type | Description |
|---|---|
SymbolNotFoundError
|
If the symbol cannot be resolved. |
NetworkError
|
If a request fails. |
ParseError
|
If a payload is malformed. |
KeyError
|
If |
ValueError
|
If |
Examples: