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 ¶
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 |
required |
Returns:
| Name | Type | Description |
|---|---|---|
contextmanager |
Yields a |
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
list_datasets ¶
List the bundled datasets and their metadata.
Returns:
| Type | Description |
|---|---|
'List[dict]'
|
list[dict]: One entry per dataset with keys |
'List[dict]'
|
|
Example
for d in list_datasets(): print(d['name'], d['kind'], d['symbol'], d['rows'])
Source code in src/tradetropy/datasets/__init__.py
load_btcusd_1m ¶
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
load_adausd_1m ¶
Load 500 one-minute ADAUSDT candles (crypto).
Returns:
| Name | Type | Description |
|---|---|---|
KlineData |
'KlineData'
|
1-minute OHLCV+turnover candles for ADAUSDT. |
load_aapl_1d ¶
Load 300 daily AAPL candles (stock, from CSV).
Returns:
| Name | Type | Description |
|---|---|---|
KlineData |
'KlineData'
|
Daily OHLCV candles for AAPL. |
load_goog_1d ¶
Load 300 daily GOOG candles (stock, from CSV).
Returns:
| Name | Type | Description |
|---|---|---|
KlineData |
'KlineData'
|
Daily OHLCV candles for GOOG. |
load_mesu26_ticks ¶
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
load_mnqu26_ticks ¶
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. |
load_adausd_ticks ¶
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
load_adausd_book ¶
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). |