> ## Documentation Index
> Fetch the complete documentation index at: https://docs.forii.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# API Reference

> One library, one REST surface — every endpoint maps to exactly one function.

The Python library is the source of truth. The REST layer is a thin 1:1
wrapper: zero logic, exceptions mapped to HTTP codes
(`LookupError → 404`, `ValueError → 400`, `FileNotFoundError → 404`).

| endpoint | library function |
| - | - |
| `GET /tickers?sector=&industry=` | `list_tickers(session, sector?, industry?)` |
| `GET /tickers/{code}/daily?start=&end=` | `get_daily_candles(session, code, start?, end?)` |
| `GET /tickers/{code}/metrics?metrics=&asof_lag=` | `get_metrics(session, code, metrics?, start?, end?, asof_lag?)` |
| `GET /panel/{metric}?start=&end=` | `get_panel(metric, start?, end?)` |
| `GET /metrics` | `list_metrics()` |

## Library

```python theme={null}
from db_interface import SessionLocal
from market_api import get_daily_candles, get_metrics, get_panel, list_metrics, list_tickers

session = SessionLocal()

list_tickers(session, sector="IT")          # reference, filterable
get_daily_candles(session, "INFY", start=date(2024, 1, 1))
get_metrics(session, "INFY", metrics=["mom1m", "mvel1"], asof_lag=3)
get_panel("mom1m")                          # wide date × ticker cross-section
list_metrics()                              # metric | category | group | description
```

## REST

```bash theme={null}
python -m uvicorn market_api.app:app --port 8000

curl "localhost:8000/tickers?sector=IT"
curl "localhost:8000/tickers/INFY/daily?start=2024-01-01"
curl "localhost:8000/tickers/INFY/metrics?metrics=mom1m,mvel1&asof_lag=3"
curl "localhost:8000/panel/mom1m"
curl "localhost:8000/metrics"
```

Responses are JSON with DataFrames in records orientation; NaN values are
serialized as `null`.

## Errors

| status | meaning |
| - | - |
| 404 | unknown ticker, or metric not found in any panel |
| 400 | unknown metric name in `metrics=` |

## CLI

```bash theme={null}
python -m market_api.cli export [--nse-code INFY]   # stage per-ticker CSVs
python -m market_api.cli build-panel [--all]        # rebuild panel CSVs
```


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.