Skip to content

Datasets

Bundled sample datasets used across the examples, the guide and the tests.

datasets

Bundled sample datasets for Tradetropy.

This package ships a small, curated collection of market data so the examples, the user guide and the test suite all run out of the box - no downloads, no API keys. Every loader returns a first-class Tradetropy domain object (KlineData, TickData or BookData) ready to feed an engine.

The datasets are intentionally small and independent samples from different instruments and periods:

====================== ========= ======== ======= ===================== Loader Type Symbol Rows Notes ====================== ========= ======== ======= ===================== load_btcusd_1m() KlineData BTCUSDT 500 1-minute crypto (npz) load_adausd_1m() KlineData ADAUSDT 500 1-minute crypto (npz) load_aapl_1d() KlineData AAPL 300 daily stock (csv) load_goog_1d() KlineData GOOG 300 daily stock (csv) load_mesu26_ticks() TickData MESU26 2000 futures ticks (npz) load_mnqu26_ticks() TickData MNQU26 2000 futures ticks (npz) load_adausd_ticks() TickData ADAUSDT 43629 ticks paired with book load_adausd_book() BookData ADAUSDT 240 L2 depth, 6 levels ====================== ========= ======== ======= =====================

Multi-timeframe Load a 1-minute series and call .resample() to build any higher timeframe from a single dataset::

    from tradetropy.datasets import load_btcusd_1m

    btc_1m = load_btcusd_1m()
    btc_1h = btc_1m.resample('1h')
    btc_1d = btc_1m.resample('1d')

Multi-symbol Every loader is independent, so combine them freely::

    from tradetropy.datasets import load_btcusd_1m, load_adausd_1m

    data = (load_btcusd_1m(), load_adausd_1m())

L2 order book (paired) load_adausd_ticks() and load_adausd_book() share the same timestamp range, so they replay together for the order-flow L2 indicators (DeepTrades, DeepWall, ...). The order book is fed to the engine through ReplayEngine (a plain backtest has no book)::

    from tradetropy.datasets import load_adausd_ticks, load_adausd_book
    from tradetropy.replay import ReplayEngine

    ticks = load_adausd_ticks()
    book  = load_adausd_book()
    engine = ReplayEngine.by_ticks(
        MyStrategy(), data=(ticks,), book=book,
    )

dataset_path

dataset_path(name: str)

Return a context manager yielding the on-disk path of a bundled dataset.

Handy when you want to read a file directly (e.g. with pandas) instead of through the typed loaders.

Parameters:

Name Type Description Default
name str

Dataset key (see DATASETS / list_datasets()).

required

Returns:

Name Type Description
contextmanager

Yields a pathlib.Path to the data file.

Raises:

Type Description
KeyError

If the dataset name is unknown.

Example

with dataset_path('btcusd_1m') as p: print(p, p.stat().st_size)

Source code in src/tradetropy/datasets/__init__.py
def dataset_path(name: str):
    """
    Return a context manager yielding the on-disk path of a bundled dataset.

    Handy when you want to read a file directly (e.g. with pandas) instead of
    through the typed loaders.

    Args:
        name (str): Dataset key (see ``DATASETS`` / ``list_datasets()``).

    Returns:
        contextmanager: Yields a ``pathlib.Path`` to the data file.

    Raises:
        KeyError: If the dataset name is unknown.

    Example:
        with dataset_path('btcusd_1m') as p:
            print(p, p.stat().st_size)
    """
    if name not in DATASETS:
        raise KeyError(
            f"Unknown dataset {name!r}. Available: {sorted(DATASETS)}"
        )
    return _resolved(DATASETS[name]["file"])

list_datasets

list_datasets() -> 'List[dict]'

List the bundled datasets and their metadata.

Returns:

Type Description
'List[dict]'

list[dict]: One entry per dataset with keys name, kind,

'List[dict]'

symbol, rows, timeframe (klines only) and description.

Example

for d in list_datasets(): print(d['name'], d['kind'], d['symbol'], d['rows'])

Source code in src/tradetropy/datasets/__init__.py
def list_datasets() -> "List[dict]":
    """
    List the bundled datasets and their metadata.

    Returns:
        list[dict]: One entry per dataset with keys ``name``, ``kind``,
        ``symbol``, ``rows``, ``timeframe`` (klines only) and ``description``.

    Example:
        for d in list_datasets():
            print(d['name'], d['kind'], d['symbol'], d['rows'])
    """
    out: List[dict] = []
    for name, meta in DATASETS.items():
        entry = {
            "name": name,
            "kind": meta["kind"],
            "symbol": meta["symbol"],
            "rows": meta["rows"],
            "description": meta["description"],
        }
        if "timeframe" in meta:
            entry["timeframe"] = meta["timeframe"]
        out.append(entry)
    return out

load_btcusd_1m

load_btcusd_1m() -> 'KlineData'

Load 500 one-minute BTCUSDT candles (crypto).

Returns:

Name Type Description
KlineData 'KlineData'

1-minute OHLCV+turnover candles for BTCUSDT.

Example

from tradetropy import BacktestEngine from tradetropy.datasets import load_btcusd_1m

btc = load_btcusd_1m() engine = BacktestEngine.by_klines(MyStrategy(), data=(btc,))

Source code in src/tradetropy/datasets/__init__.py
def load_btcusd_1m() -> "KlineData":
    """
    Load 500 one-minute BTCUSDT candles (crypto).

    Returns:
        KlineData: 1-minute OHLCV+turnover candles for BTCUSDT.

    Example:
        from tradetropy import BacktestEngine
        from tradetropy.datasets import load_btcusd_1m

        btc = load_btcusd_1m()
        engine = BacktestEngine.by_klines(MyStrategy(), data=(btc,))
    """
    return _load_klines("btcusd_1m")

load_adausd_1m

load_adausd_1m() -> 'KlineData'

Load 500 one-minute ADAUSDT candles (crypto).

Returns:

Name Type Description
KlineData 'KlineData'

1-minute OHLCV+turnover candles for ADAUSDT.

Source code in src/tradetropy/datasets/__init__.py
def load_adausd_1m() -> "KlineData":
    """
    Load 500 one-minute ADAUSDT candles (crypto).

    Returns:
        KlineData: 1-minute OHLCV+turnover candles for ADAUSDT.
    """
    return _load_klines("adausd_1m")

load_aapl_1d

load_aapl_1d() -> 'KlineData'

Load 300 daily AAPL candles (stock, from CSV).

Returns:

Name Type Description
KlineData 'KlineData'

Daily OHLCV candles for AAPL.

Source code in src/tradetropy/datasets/__init__.py
def load_aapl_1d() -> "KlineData":
    """
    Load 300 daily AAPL candles (stock, from CSV).

    Returns:
        KlineData: Daily OHLCV candles for AAPL.
    """
    return _load_klines("aapl_1d")

load_goog_1d

load_goog_1d() -> 'KlineData'

Load 300 daily GOOG candles (stock, from CSV).

Returns:

Name Type Description
KlineData 'KlineData'

Daily OHLCV candles for GOOG.

Source code in src/tradetropy/datasets/__init__.py
def load_goog_1d() -> "KlineData":
    """
    Load 300 daily GOOG candles (stock, from CSV).

    Returns:
        KlineData: Daily OHLCV candles for GOOG.
    """
    return _load_klines("goog_1d")

load_mesu26_ticks

load_mesu26_ticks() -> 'TickData'

Load 2000 Micro E-mini S&P 500 (MESU26) futures ticks.

Returns:

Name Type Description
TickData 'TickData'

Trade ticks with bid/ask/volume/flags for MESU26.

Example

from tradetropy import BacktestEngine from tradetropy.datasets import load_mesu26_ticks

ticks = load_mesu26_ticks() engine = BacktestEngine.by_ticks(MyStrategy(), data=(ticks,))

Source code in src/tradetropy/datasets/__init__.py
def load_mesu26_ticks() -> "TickData":
    """
    Load 2000 Micro E-mini S&P 500 (MESU26) futures ticks.

    Returns:
        TickData: Trade ticks with bid/ask/volume/flags for MESU26.

    Example:
        from tradetropy import BacktestEngine
        from tradetropy.datasets import load_mesu26_ticks

        ticks = load_mesu26_ticks()
        engine = BacktestEngine.by_ticks(MyStrategy(), data=(ticks,))
    """
    return _load_ticks("mesu26_ticks")

load_mnqu26_ticks

load_mnqu26_ticks() -> 'TickData'

Load 2000 Micro E-mini Nasdaq-100 (MNQU26) futures ticks.

Returns:

Name Type Description
TickData 'TickData'

Trade ticks with bid/ask/volume/flags for MNQU26.

Source code in src/tradetropy/datasets/__init__.py
def load_mnqu26_ticks() -> "TickData":
    """
    Load 2000 Micro E-mini Nasdaq-100 (MNQU26) futures ticks.

    Returns:
        TickData: Trade ticks with bid/ask/volume/flags for MNQU26.
    """
    return _load_ticks("mnqu26_ticks")

load_adausd_ticks

load_adausd_ticks() -> 'TickData'

Load 43629 ADAUSDT ticks paired in time with load_adausd_book().

The tick timestamps span exactly the order book's range, so the two replay together and the L2 order-flow indicators (DeepTrades, DeepWall, ...) have a book to read as-of each trade.

Returns:

Name Type Description
TickData 'TickData'

Trade ticks for ADAUSDT overlapping the bundled book.

Example

from tradetropy.replay import ReplayEngine from tradetropy.datasets import load_adausd_ticks, load_adausd_book

ticks = load_adausd_ticks() book = load_adausd_book() engine = ReplayEngine.by_ticks( MyStrategy(), data=(ticks,), book=book, )

Source code in src/tradetropy/datasets/__init__.py
def load_adausd_ticks() -> "TickData":
    """
    Load 43629 ADAUSDT ticks paired in time with ``load_adausd_book()``.

    The tick timestamps span exactly the order book's range, so the two replay
    together and the L2 order-flow indicators (``DeepTrades``, ``DeepWall``,
    ...) have a book to read as-of each trade.

    Returns:
        TickData: Trade ticks for ADAUSDT overlapping the bundled book.

    Example:
        from tradetropy.replay import ReplayEngine
        from tradetropy.datasets import load_adausd_ticks, load_adausd_book

        ticks = load_adausd_ticks()
        book  = load_adausd_book()
        engine = ReplayEngine.by_ticks(
            MyStrategy(), data=(ticks,), book=book,
        )
    """
    return _load_ticks("adausd_ticks")

load_adausd_book

load_adausd_book() -> 'BookData'

Load 240 rows of ADAUSDT L2 order-book depth (6 levels per side).

Paired in time with load_adausd_ticks() for the L2 / order-flow examples. Feed it to the engine through ReplayEngine(book=...); a plain backtest has no order book.

Returns:

Name Type Description
BookData 'BookData'

Wide L2 book snapshots (bid/ask price and size per level).

Source code in src/tradetropy/datasets/__init__.py
def load_adausd_book() -> "BookData":
    """
    Load 240 rows of ADAUSDT L2 order-book depth (6 levels per side).

    Paired in time with ``load_adausd_ticks()`` for the L2 / order-flow
    examples. Feed it to the engine through ``ReplayEngine(book=...)``; a plain
    backtest has no order book.

    Returns:
        BookData: Wide L2 book snapshots (bid/ask price and size per level).
    """
    meta = DATASETS["adausd_book"]
    with _resolved(meta["file"]) as path:
        return read_book(
            str(path), meta["symbol"], levels=meta["levels"],
            tick_size=meta["tick_size"],
        )