# Download historical price data as CSV or Parquet

> Download price history of stocks, FX, crypto and futures as CSV, Parquet, Arrow or JSON over one REST endpoint, with a free daily sample, cursor paging and an exact cost check before you pull.

Source: https://getmarkethistory.com/docs/guides/download-historical-price-data

Every dataset downloads the same way: one bars endpoint, a `format` parameter, and a cursor for
ranges longer than a page. Stocks, FX, crypto, futures, indices: the historical trading data of
each comes as OHLCV bars, and [Datasets](https://getmarkethistory.com/docs/coverage) lists what each one holds.

## Free download, no key

The daily bars of any US stock or crypto pair over the last two years download without an
account. Half a year of Apple, as a CSV file:

```bash
curl -o aapl-1d.csv "https://getmarkethistory.com/api/v1/bars/stocks/us/AAPL/1d?start=2026-01-01&end=2026-06-30&format=csv"
```

The two years of a ticker fit one page. This path answers one dated request per address every 30
seconds; on the other datasets it serves the newest 100 daily bars only. Other timeframes, and
anything in bulk, need a key: a free account's monthly bars pay for `1h` and longer.

## Any range, any timeframe

With a key, the path is `/query/v1/bars/{asset}/{region}/{ticker}/{timeframe}`. A year of Apple at
one minute, as Parquet:

```bash
curl -D headers.txt -o aapl-2024-1m-1.parquet \
  "https://getmarkethistory.com/query/v1/bars/stocks/us/AAPL/1m?start=2024-01-01&end=2024-12-31&format=parquet&limit=100000" \
  -H "Authorization: Bearer $MARKET_HISTORY_KEY"
```

`limit` is rows per page: 10,000 by default, 100,000 at most. When `headers.txt` holds an
`X-Next-Cursor`, send the same request again with `&cursor=<token>` for the next page, and stop
when the header is absent. Pages run oldest first; the cursor never expires.
[Limits & billing](https://getmarkethistory.com/docs/limits#paging) has the rules.

## Which formats can I download?

| `format`  | What you get                               |
| --------- | ------------------------------------------ |
| `jsonl`   | one JSON object per line, the default      |
| `json`    | one JSON document                          |
| `csv`     | a header row, then one bar per line        |
| `parquet` | a Parquet file with typed columns          |
| `arrow`   | an Arrow IPC stream                        |
| `mbt1`    | the most compact binary encoding, for bars |

A bar costs the same in every format, so pick what your code reads best. Columns and types are in
[Data & formats](https://getmarkethistory.com/docs/formats).

## How do I know what a download costs before I make it?

Ask the cost endpoint. It is free, needs no key, and counts exactly what the same request would
bill without returning the bars:

```bash
curl "https://getmarkethistory.com/api/v1/stocks/us/AAPL/cost?timeframe=1m&start=2024-01-01&end=2024-12-31"
```

```json
{
  "bars": 187812,
  "bars_charged": 187900,
  "credits": 1879,
  "dataset": "stocks/us",
  "end": "2024-12-31",
  "exact": true,
  "limit": 10000,
  "pack": { "bars": 1000000, "usd": 5.0 },
  "product": "bars",
  "rows": 187812,
  "start": "2024-01-01",
  "ticker": "AAPL",
  "timeframe": "1m",
  "usd": 0.94
}
```

`bars_charged` is what you are billed: each page rounds up to a block of 100 bars, so a large
`limit` wastes less. `pack` is the smallest one-off purchase that covers it. A request that
matches no bars is free.

## Can I download it from Python?

The [client](https://getmarkethistory.com/docs/quickstart#4-into-pandas) follows the cursor and fetches Parquet underneath;
write the result wherever you like:

```python
from markethistory import Client

mh = Client()  # reads MARKET_HISTORY_KEY
print(mh.estimate("stocks/us", "AAPL", "1m", start="2024-01-01", end="2024-12-31"))
df = mh.frame("stocks/us", "AAPL", "1m", start="2024-01-01", end="2024-12-31")
df.to_parquet("aapl-2024-1m.parquet")
df.to_csv("aapl-2024-1m.csv")
```

`estimate()` is the cost endpoint above. Without a key, `mh.preview("stocks/us", "AAPL",
start="2026-01-01", end="2026-06-30")` returns the free daily page.

## Can I download several tickers at once?

Yes, with a key: the query form takes a comma-separated `ticker`, and every row carries its
`symbol`.

```bash
curl "https://getmarkethistory.com/query/v1/bars?dataset=stocks/us&ticker=AAPL,SPY&timeframe=1d&start=2024-01-01&end=2024-12-31&format=csv" \
  -H "Authorization: Bearer $MARKET_HISTORY_KEY"
```

The free sample is one ticker per request. A dataset's ticker list, with each one's first and last
bar, is free at `/api/v1/symbols?dataset=stocks/us&timeframe=1m`.
