Skip to content

Data IO

Read and save candles, ticks and order books in NumPy .npz (the base binary format), CSV, Parquet and HDF5. Parquet needs tradetropy[parquet] and HDF5 needs tradetropy[hdf5]; .npz and CSV need no extra.

io

read_ticks

read_ticks(path: str | Path, symbol: 'str | None' = None, format: 'Literal["csv", "parquet", "hdf5", "npz"] | None' = None, source: str = 'auto', hdf5_key: str = 'data', col_datetime: str = 'datetime', tick_size: float = 0.01, tick_value: float = 0.01, contract_size: float = 1.0, digits: int = 2, avg_spread: float = 0.0, volume_min: float = 0.01, volume_max: float = 100.0, volume_step: float = 0.01) -> 'TickData'

Read ticks from file and return TickData.

Accepts external files (broker CSV) and files generated by save_ticks().

Required columns: datetime, bid, ask Optional columns: volume, flags, volume_real, price (filled by normalize_ticks() if missing)

Parameters:

Name Type Description Default
path str | Path

File path to read from.

required
symbol 'str | None'

Trading symbol. If None, read from HDF5 attrs (saved by TickData.save()). Required for CSV/Parquet or non-tradetropy files.

None
format 'Literal["csv", "parquet", "hdf5", "npz"] | None'

File format ('csv', 'parquet', 'hdf5'). None -> auto-detect.

None
source str

Tick file schema. 'auto' (default) reads the generic datetime/bid/ask/volume/flags/price schema; on failure it sniffs for a known broker-specific schema and raises an actionable error suggesting the right source= instead of a raw KeyError. 'mt5' reads an MT5 "Export Ticks" CSV directly (tab-separated /

'auto'
hdf5_key str

Key inside HDF5 file.

'data'
col_datetime str

Datetime column name.

'datetime'
tick_size float

Minimum price move.

0.01
tick_value float

Value of one tick.

0.01
contract_size float

Size of contract.

1.0
digits int

Number of decimal places.

2
avg_spread float

Average bid-ask spread.

0.0
volume_min float

Minimum order volume.

0.01
volume_max float

Maximum order volume.

100.0
volume_step float

Minimum volume increment (lot step).

0.01

Returns:

Name Type Description
TickData 'TickData'

Normalized tick data object.

Raises:

Type Description
DataError

If source='mt5' is used on a file that is not an MT5 tick export, or if the generic schema is missing required columns and no known broker-specific schema is detected.

Example

ticks = read_ticks('ticks.parquet', 'BTCUSDT') ticks = read_ticks('session.h5') # symbol read from attrs ticks = read_ticks('broker_export.csv', 'BTCUSDT') ticks = read_ticks('MESU26_ticks.csv', 'MESU26', source='mt5')

Source code in src/tradetropy/io/_ticks.py
def read_ticks(
    path: str | Path,
    symbol: "str | None" = None,
    format: 'Literal["csv", "parquet", "hdf5", "npz"] | None' = None,
    source: str = "auto",
    hdf5_key: str = "data",
    col_datetime: str = "datetime",
    tick_size: float = 0.01,
    tick_value: float = 0.01,
    contract_size: float = 1.0,
    digits: int = 2,
    avg_spread: float = 0.0,
    volume_min: float = 0.01,
    volume_max: float = 100.0,
    volume_step: float = 0.01,
) -> "TickData":
    """
    Read ticks from file and return TickData.

    Accepts external files (broker CSV) and files generated by save_ticks().

    Required columns: datetime, bid, ask
    Optional columns: volume, flags, volume_real, price
                      (filled by normalize_ticks() if missing)

    Args:
        path: File path to read from.
        symbol: Trading symbol. If None, read from HDF5 attrs (saved by
            TickData.save()). Required for CSV/Parquet or non-tradetropy files.
        format: File format ('csv', 'parquet', 'hdf5'). None -> auto-detect.
        source: Tick file schema. 'auto' (default) reads the generic
            datetime/bid/ask/volume/flags/price schema; on failure it sniffs
            for a known broker-specific schema and raises an actionable error
            suggesting the right `source=` instead of a raw KeyError. 'mt5'
            reads an MT5 "Export Ticks" CSV directly (tab-separated <DATE>/
            <TIME>/<BID>/<ASK>/<LAST>/<VOLUME>/<FLAGS>, forward-filling bid/ask
            across rows) - see _read_mt5_ticks_csv() for the schema details.
        hdf5_key: Key inside HDF5 file.
        col_datetime: Datetime column name.
        tick_size: Minimum price move.
        tick_value: Value of one tick.
        contract_size: Size of contract.
        digits: Number of decimal places.
        avg_spread: Average bid-ask spread.
        volume_min: Minimum order volume.
        volume_max: Maximum order volume.
        volume_step: Minimum volume increment (lot step).

    Returns:
        TickData: Normalized tick data object.

    Raises:
        DataError: If source='mt5' is used on a file that is not an MT5 tick
            export, or if the generic schema is missing required columns and
            no known broker-specific schema is detected.

    Example:
        ticks = read_ticks('ticks.parquet', 'BTCUSDT')
        ticks = read_ticks('session.h5')  # symbol read from attrs
        ticks = read_ticks('broker_export.csv', 'BTCUSDT')
        ticks = read_ticks('MESU26_ticks.csv', 'MESU26', source='mt5')
    """
    from tradetropy.core.data_types import TickData
    from tradetropy.data import normalize_ticks

    path    = Path(path)
    format  = format or _detect_format(path)

    tick_kwargs = dict(
        tick_size=tick_size, tick_value=tick_value,
        contract_size=contract_size, digits=digits,
        avg_spread=avg_spread,
        volume_min=volume_min, volume_max=volume_max,
        volume_step=volume_step,
    )

    if source == "mt5":
        if symbol is None:
            raise ValueError(
                "symbol is required for source='mt5' (an MT5 export carries "
                "no tradetropy attrs)."
            )
        return _read_mt5_ticks_csv(path, symbol, **tick_kwargs)

    if source != "auto":
        raise DataError(
            f"Unknown source {source!r}. Available sources: 'auto', 'mt5'."
        )

    if symbol is None and format in ("hdf5", "npz"):
        attrs = _read_attrs(path, format, hdf5_key)
        symbol = attrs.get("tradetropy_symbol")
        if symbol is not None:
            tick_size   = attrs.get("tradetropy_tick_size", tick_size)
            tick_value  = attrs.get("tradetropy_tick_value", tick_value)
            contract_size = attrs.get("tradetropy_contract_size", contract_size)
            digits      = attrs.get("tradetropy_digits", digits)
            avg_spread  = attrs.get("tradetropy_avg_spread", avg_spread)
            volume_min  = attrs.get("tradetropy_volume_min", volume_min)
            volume_max  = attrs.get("tradetropy_volume_max", volume_max)
            volume_step = attrs.get("tradetropy_volume_step", volume_step)

    if symbol is None:
        raise ValueError(
            "symbol is required. Pass it explicitly or use a file saved by "
            "TickData.save() with format='hdf5'."
        )

    df = _read(path, format, hdf5_key)

    if "ts" not in df.columns and col_datetime not in df.columns:
        if format == "csv" and _sniff_mt5_tick_header(path):
            raise DataError(
                f"{path.name!r} looks like an MT5 tick export (columns "
                f"{list(_MT5_TICK_HEADER_COLS)}), not the generic tradetropy "
                f"tick schema (datetime, bid, ask, ...). "
                f"Re-run with source='mt5' to read it directly."
            )
        raise DataError(
            f"{path.name!r} is missing a {col_datetime!r} or 'ts' column. "
            f"Found columns: {list(df.columns)}. If this is a broker-specific "
            f"export, pass source=... (available: 'mt5') or convert it to the "
            f"generic schema first (datetime, bid, ask, volume, flags, price)."
        )

    if "ts" in df.columns:
        ts_ms = df["ts"].to_numpy(dtype=np.int64)
        df = df.drop(columns=["ts"])
    else:
        ts_ms = _datetime_to_ts_ms(df[col_datetime])
        df = df.drop(columns=[col_datetime])

    cols_map = {c.lower(): c for c in df.columns}

    def _col(name: str, default: float = 0.0) -> np.ndarray:
        real = cols_map.get(name)
        return (
            df[real].to_numpy(dtype=np.float64)
            if real
            else np.full(len(df), default, dtype=np.float64)
        )

    data = np.column_stack([
        ts_ms,
        _col("bid"), _col("ask"), _col("volume"), _col("flags"),
        _col("volume_real", np.nan), _col("price"),
    ])

    tick_data = TickData(symbol=symbol, data=data, **tick_kwargs)
    if "ts" not in df.columns:
        tick_data.data = normalize_ticks(tick_data.data)
    return tick_data

read_klines

read_klines(path: str | Path, symbol: 'str | None' = None, timeframe: 'str | int | None' = None, format: 'Literal["csv", "parquet", "hdf5", "npz"] | None' = None, hdf5_key: str = 'data', col_datetime: str = 'datetime', tick_size: float = 0.01, tick_value: float = 0.01, contract_size: float = 1.0, digits: int = 2, avg_spread: float = 0.0, volume_min: float = 0.01, volume_max: float = 100.0, volume_step: float = 0.01) -> 'KlineData'

Read klines from file and return KlineData.

Accepts external files (broker CSV) and files generated by save_klines().

Required columns: datetime, open, high, low, close, volume Optional columns: turnover (filled with NaN if missing)

Parameters:

Name Type Description Default
path str | Path

File path to read from.

required
symbol 'str | None'

Trading symbol. If None, read from HDF5 attrs (saved by KlineData.save()). Required for CSV/Parquet or non-tradetropy files.

None
timeframe 'str | int | None'

Candle interval. Accepts a timeframe string ('1m', '5m', '1h', '1d', etc.) or an integer number of milliseconds, parsed via parse_timeframe(). If None, read from HDF5 attrs.

None
format 'Literal["csv", "parquet", "hdf5", "npz"] | None'

File format ('csv', 'parquet', 'hdf5'). None -> auto-detect.

None
hdf5_key str

Key inside HDF5 file.

'data'
col_datetime str

Datetime column name.

'datetime'
tick_size float

Minimum price move.

0.01
tick_value float

Value of one tick.

0.01
contract_size float

Size of contract.

1.0
digits int

Number of decimal places.

2
volume_min float

Minimum order volume.

0.01
volume_max float

Maximum order volume.

100.0
volume_step float

Minimum volume increment (lot step).

0.01

Returns:

Name Type Description
KlineData 'KlineData'

Kline data object.

Example

klines = read_klines('ohlc.parquet', 'BTCUSDT', timeframe='1m') klines = read_klines('session.h5') # all read from attrs klines = read_klines('bybit_export.csv', 'BTCUSDT', timeframe=60_000)

Source code in src/tradetropy/io/_klines.py
def read_klines(
    path: str | Path,
    symbol: "str | None" = None,
    timeframe: "str | int | None" = None,
    format: 'Literal["csv", "parquet", "hdf5", "npz"] | None' = None,
    hdf5_key: str = "data",
    col_datetime: str = "datetime",
    tick_size: float = 0.01,
    tick_value: float = 0.01,
    contract_size: float = 1.0,
    digits: int = 2,
    avg_spread: float = 0.0,
    volume_min: float = 0.01,
    volume_max: float = 100.0,
    volume_step: float = 0.01,
) -> "KlineData":
    """
    Read klines from file and return KlineData.

    Accepts external files (broker CSV) and files generated by save_klines().

    Required columns: datetime, open, high, low, close, volume
    Optional columns: turnover (filled with NaN if missing)

    Args:
        path: File path to read from.
        symbol: Trading symbol. If None, read from HDF5 attrs (saved by
            KlineData.save()). Required for CSV/Parquet or non-tradetropy files.
        timeframe: Candle interval. Accepts a timeframe string ('1m', '5m',
            '1h', '1d', etc.) or an integer number of milliseconds, parsed via
            parse_timeframe(). If None, read from HDF5 attrs.
        format: File format ('csv', 'parquet', 'hdf5'). None -> auto-detect.
        hdf5_key: Key inside HDF5 file.
        col_datetime: Datetime column name.
        tick_size: Minimum price move.
        tick_value: Value of one tick.
        contract_size: Size of contract.
        digits: Number of decimal places.
        volume_min: Minimum order volume.
        volume_max: Maximum order volume.
        volume_step: Minimum volume increment (lot step).

    Returns:
        KlineData: Kline data object.

    Example:
        klines = read_klines('ohlc.parquet', 'BTCUSDT', timeframe='1m')
        klines = read_klines('session.h5')  # all read from attrs
        klines = read_klines('bybit_export.csv', 'BTCUSDT', timeframe=60_000)
    """
    from tradetropy.core.constants import parse_timeframe
    from tradetropy.core.data_types import KlineData

    path    = Path(path)
    format  = format or _detect_format(path)

    if format in ("hdf5", "npz") and (symbol is None or timeframe is None):
        attrs = _read_attrs(path, format, hdf5_key)
        if symbol is None:
            symbol = attrs.get("tradetropy_symbol")
        if attrs.get("tradetropy_symbol") is not None:
            tick_size    = attrs.get("tradetropy_tick_size", tick_size)
            tick_value   = attrs.get("tradetropy_tick_value", tick_value)
            contract_size = attrs.get("tradetropy_contract_size", contract_size)
            digits       = attrs.get("tradetropy_digits", digits)
            avg_spread   = attrs.get("tradetropy_avg_spread", avg_spread)
            volume_min   = attrs.get("tradetropy_volume_min", volume_min)
            volume_max   = attrs.get("tradetropy_volume_max", volume_max)
            volume_step  = attrs.get("tradetropy_volume_step", volume_step)
            if timeframe is None:
                stored_interval = attrs.get("tradetropy_interval_ms")
                if stored_interval is not None:
                    timeframe = int(stored_interval)

    if symbol is None:
        raise ValueError(
            "symbol is required. Pass it explicitly or use a file saved by "
            "KlineData.save() with format='hdf5'."
        )

    if timeframe is None:
        raise ValueError(
            "read_klines() requires a timeframe (e.g. timeframe='5m' or "
            "timeframe=60_000). The file has no tradetropy_interval_ms attr "
            "(not saved by KlineData.save(), or saved before the timeframe "
            "was set) - pass timeframe explicitly to fix it going forward."
        )
    interval_ms = parse_timeframe(timeframe)

    df = _read(path, format, hdf5_key)

    # Discard partial candles if coming from save_klines()
    if "partial" in df.columns:
        df = (
            df[df["partial"] == 0]
            .drop(columns=["partial"])
            .reset_index(drop=True)
        )

    # Accept a raw 'ts' column (record path / _append_klines_hdf5) or a
    # human-readable 'datetime' column (save_klines csv), mirroring read_ticks.
    if "ts" in df.columns:
        ts_ms = df["ts"].to_numpy(dtype=np.int64)
        df    = df.drop(columns=["ts"])
    else:
        ts_ms = _datetime_to_ts_ms(df[col_datetime])
        df    = df.drop(columns=[col_datetime])

    cols_map = {c.lower(): c for c in df.columns}

    def _col(name: str, default: float = 0.0) -> np.ndarray:
        real = cols_map.get(name)
        return (
            df[real].to_numpy(dtype=np.float64)
            if real
            else np.full(len(df), default, dtype=np.float64)
        )

    data = np.column_stack([
        ts_ms,
        _col("open"), _col("high"), _col("low"), _col("close"),
        _col("volume"), _col("turnover", np.nan),
    ])

    return KlineData(
        symbol=symbol, data=data, timeframe=interval_ms,
        tick_size=tick_size, tick_value=tick_value,
        contract_size=contract_size, digits=digits,
        volume_min=volume_min, volume_max=volume_max,
        volume_step=volume_step,
    )

read_book

read_book(path: 'str | Path', symbol: 'str | None' = None, levels: 'int | None' = None, format: 'Literal["csv", "parquet", "hdf5", "npz"] | None' = None, layout: Literal['auto', 'wide', 'long'] = 'auto', hdf5_key: str = 'book', col_datetime: str = 'datetime', tick_size: float = 0.01) -> BookData

Read L2 order-book rows and return a BookData (multi-format, multi-layout).

Round-trips files written by save_book() / BookData.save() in any format (csv, parquet, hdf5) and the append-only HDF5 written by the live record= path (_append_book_hdf5). Two on-disk layouts are supported and normalized to the same wide BookData in memory:

  • 'wide' (tradetropy native): grouped bid_px_/bid_sz_/ask_px_/ask_sz_ columns, one book event per row.
  • 'long' (Binance bookDepth-style): 'timestamp'/'percentage'/'depth'/ 'notional' columns, one row per price level per side, with cumulative depth/notional. De-cumulated back to per-level price/size on read (exact for tradetropy-written files, approximate per-band VWAP for a real Binance bookDepth file, which carries no explicit per-level price).

The 'ts' column is accepted directly, or rebuilt from a 'datetime' / 'timestamp' column. For the wide layout the level count K is taken from the argument, from HDF5 metadata, or inferred from the bid_px_* columns; for the long layout it is inferred from the largest |percentage| present.

Parameters:

Name Type Description Default
path 'str | Path'

File path (as written by save_book / BookData.save / record=).

required
symbol 'str | None'

Trading symbol. If None, read from HDF5 attrs when available.

None
levels 'int | None'

Number of book levels K (wide only). If None, from metadata or inferred.

None
format 'Literal["csv", "parquet", "hdf5", "npz"] | None'

File format ('csv', 'parquet', 'hdf5'). None -> auto-detect.

None
layout Literal['auto', 'wide', 'long']

On-disk layout ('auto', 'wide', 'long'). 'auto' detects from the columns (long if percentage/depth/notional present, else wide).

'auto'
hdf5_key str

Key inside the HDF5 file (default 'book').

'book'
col_datetime str

Datetime column name (when no 'ts' column is present).

'datetime'
tick_size float

Minimum price step propagated to BookData.

0.01

Returns:

Name Type Description
BookData BookData

Reconstructed order-book data (always the wide in-memory form).

Raises:

Type Description
DataError

If the level count cannot be determined.

ValueError

If the symbol cannot be resolved.

Source code in src/tradetropy/io/_book.py
def read_book(
    path: "str | Path",
    symbol: "str | None" = None,
    levels: "int | None" = None,
    format: 'Literal["csv", "parquet", "hdf5", "npz"] | None' = None,
    layout: Literal["auto", "wide", "long"] = "auto",
    hdf5_key: str = "book",
    col_datetime: str = "datetime",
    tick_size: float = 0.01,
) -> BookData:
    """
    Read L2 order-book rows and return a BookData (multi-format, multi-layout).

    Round-trips files written by save_book() / BookData.save() in any format
    (csv, parquet, hdf5) and the append-only HDF5 written by the live record=
    path (_append_book_hdf5). Two on-disk layouts are supported and normalized
    to the same wide BookData in memory:

    - 'wide' (tradetropy native): grouped bid_px_*/bid_sz_*/ask_px_*/ask_sz_*
      columns, one book event per row.
    - 'long' (Binance bookDepth-style): 'timestamp'/'percentage'/'depth'/
      'notional' columns, one row per price level per side, with cumulative
      depth/notional. De-cumulated back to per-level price/size on read (exact
      for tradetropy-written files, approximate per-band VWAP for a real Binance
      bookDepth file, which carries no explicit per-level price).

    The 'ts' column is accepted directly, or rebuilt from a 'datetime' /
    'timestamp' column. For the wide layout the level count K is taken from the
    argument, from HDF5 metadata, or inferred from the bid_px_* columns; for the
    long layout it is inferred from the largest |percentage| present.

    Args:
        path: File path (as written by save_book / BookData.save / record=).
        symbol: Trading symbol. If None, read from HDF5 attrs when available.
        levels: Number of book levels K (wide only). If None, from metadata or
            inferred.
        format: File format ('csv', 'parquet', 'hdf5'). None -> auto-detect.
        layout: On-disk layout ('auto', 'wide', 'long'). 'auto' detects from the
            columns (long if percentage/depth/notional present, else wide).
        hdf5_key: Key inside the HDF5 file (default 'book').
        col_datetime: Datetime column name (when no 'ts' column is present).
        tick_size: Minimum price step propagated to BookData.

    Returns:
        BookData: Reconstructed order-book data (always the wide in-memory form).

    Raises:
        DataError: If the level count cannot be determined.
        ValueError: If the symbol cannot be resolved.
    """
    from tradetropy.core.data_types import BookData, book_flat_columns, long_rows_to_wide

    path   = Path(path)
    format = format or _detect_format(path)

    if format in ("hdf5", "npz"):
        attrs = _read_attrs(path, format, hdf5_key)
        if symbol is None:
            symbol = attrs.get("tradetropy_symbol")
        if levels is None and attrs.get("tradetropy_levels") is not None:
            levels = int(attrs["tradetropy_levels"])
        tick_size = attrs.get("tradetropy_tick_size", tick_size)

    df = _read(path, format, hdf5_key)

    resolved_layout = layout if layout != "auto" else _detect_book_layout(df)

    if symbol is None:
        raise ValueError(
            "symbol is required. Pass it explicitly or use a file saved by "
            "BookData.save() with format='hdf5'."
        )

    if resolved_layout == "long":
        long_df = _normalize_long_book_df(df, col_datetime)
        data, levels = long_rows_to_wide(long_df)
        return BookData(symbol=symbol, data=data, levels=levels, tick_size=tick_size)

    if levels is None:
        n_bid = sum(1 for c in df.columns if str(c).startswith("bid_px_"))
        if n_bid <= 0:
            raise DataError(
                f"read_book(): could not determine 'levels' from {path}. "
                f"Pass levels=K explicitly."
            )
        levels = n_bid
    levels = int(levels)

    if "ts" not in df.columns and col_datetime in df.columns:
        ts_ms = _datetime_to_ts_ms(df[col_datetime])
        df = df.drop(columns=[col_datetime])
        df.insert(0, "ts", ts_ms)

    cols = book_flat_columns(levels)
    data = df[cols].to_numpy(dtype=np.float64)
    return BookData(symbol=symbol, data=data, levels=levels, tick_size=tick_size)

read_mbo

read_mbo(path: 'str | Path', symbol: 'str | None' = None, hdf5_key: str = 'mbo', tick_size: float = 0.01)

Read recorded L3 / MBO event rows and return an MboData.

Parameters:

Name Type Description Default
path 'str | Path'

HDF5 file path (as written by _append_mbo_hdf5).

required
symbol 'str | None'

Trading symbol. If None, read from HDF5 attrs (persisted by the live record= path). Required when the file carries no attrs.

None
hdf5_key str

Key inside the HDF5 file (default 'mbo').

'mbo'
tick_size float

Minimum price step propagated to MboData.

0.01

Returns:

Name Type Description
MboData

Reconstructed market-by-order data.

Raises:

Type Description
ValueError

If the symbol cannot be resolved from arg or attrs.

Source code in src/tradetropy/io/_mbo.py
def read_mbo(
    path: "str | Path",
    symbol: "str | None" = None,
    hdf5_key: str = "mbo",
    tick_size: float = 0.01,
):
    """
    Read recorded L3 / MBO event rows and return an MboData.

    Args:
        path: HDF5 file path (as written by _append_mbo_hdf5).
        symbol: Trading symbol. If None, read from HDF5 attrs (persisted by the
            live record= path). Required when the file carries no attrs.
        hdf5_key: Key inside the HDF5 file (default 'mbo').
        tick_size: Minimum price step propagated to MboData.

    Returns:
        MboData: Reconstructed market-by-order data.

    Raises:
        ValueError: If the symbol cannot be resolved from arg or attrs.
    """
    from tradetropy.core.data_types import MboData, MBO_COLS

    path = Path(path)
    format = _detect_format(path)
    if symbol is None:
        attrs = _read_attrs(path, format, hdf5_key)
        symbol = attrs.get("tradetropy_symbol")
        tick_size = attrs.get("tradetropy_tick_size", tick_size)
    if symbol is None:
        raise ValueError(
            "symbol is required. Pass it explicitly or use a file recorded by "
            "the live record= path (which persists it as HDF5 attrs)."
        )

    df = _read(path, format, hdf5_key)
    data = df[list(MBO_COLS)].to_numpy(dtype=np.float64)
    return MboData(symbol=symbol, data=data, tick_size=tick_size)

read_trades

read_trades(path: str | Path, symbol: str, source: str = 'binance', format: 'Literal["csv", "parquet", "hdf5", "npz"] | None' = None, hdf5_key: str = 'data', tick_size: float = 0.01, tick_value: float = 0.01, contract_size: float = 1.0, digits: int = 2, avg_spread: float = 0.0, volume_min: float = 0.01, volume_max: float = 100.0, volume_step: float = 0.01) -> 'TickData'

Read raw exchange trades (times and sales) and return TickData.

Normalizes a venue-specific trades export into the tradetropy tick array, filling bid/ask from the trade price (a trades file carries no quotes) and mapping the aggressor side onto the 'flags' column (+1 buy / -1 sell). The supported schemas live in the _TRADE_SCHEMAS registry, keyed by 'source'; 'binance' handles the columns id, price, qty, quote_qty, time, is_buyer_maker (the id and quote_qty columns are ignored).

The returned TickData is a standard object, so it is saved to any format with its usual .save() (parquet / hdf5 / csv) and re-read with read_ticks().

Parameters:

Name Type Description Default
path str | Path

File path to read from.

required
symbol str

Trading symbol (required; a trades file has no tradetropy attrs).

required
source str

Trades schema key. One of the keys in _TRADE_SCHEMAS.

'binance'
format 'Literal["csv", "parquet", "hdf5", "npz"] | None'

File format ('csv', 'parquet', 'hdf5'). None -> auto-detect.

None
hdf5_key str

Key inside the HDF5 file.

'data'
tick_size float

Minimum price move.

0.01
tick_value float

Value of one tick.

0.01
contract_size float

Size of contract.

1.0
digits int

Number of decimal places.

2
avg_spread float

Average bid-ask spread.

0.0
volume_min float

Minimum order volume.

0.01
volume_max float

Maximum order volume.

100.0
volume_step float

Minimum volume increment (lot step).

0.01

Returns:

Name Type Description
TickData 'TickData'

Normalized tick data object.

Raises:

Type Description
DataError

If the source is unknown or a required column is missing.

Example

ticks = read_trades('ADAUSDT-trades.csv', 'ADAUSD', source='binance') ticks.save('ada_ticks.parquet')

Source code in src/tradetropy/io/_ticks.py
def read_trades(
    path: str | Path,
    symbol: str,
    source: str = "binance",
    format: 'Literal["csv", "parquet", "hdf5", "npz"] | None' = None,
    hdf5_key: str = "data",
    tick_size: float = 0.01,
    tick_value: float = 0.01,
    contract_size: float = 1.0,
    digits: int = 2,
    avg_spread: float = 0.0,
    volume_min: float = 0.01,
    volume_max: float = 100.0,
    volume_step: float = 0.01,
) -> "TickData":
    """
    Read raw exchange trades (times and sales) and return TickData.

    Normalizes a venue-specific trades export into the tradetropy tick array,
    filling bid/ask from the trade price (a trades file carries no quotes) and
    mapping the aggressor side onto the 'flags' column (+1 buy / -1 sell). The
    supported schemas live in the _TRADE_SCHEMAS registry, keyed by 'source';
    'binance' handles the columns id, price, qty, quote_qty, time,
    is_buyer_maker (the id and quote_qty columns are ignored).

    The returned TickData is a standard object, so it is saved to any format
    with its usual .save() (parquet / hdf5 / csv) and re-read with read_ticks().

    Args:
        path: File path to read from.
        symbol: Trading symbol (required; a trades file has no tradetropy attrs).
        source: Trades schema key. One of the keys in _TRADE_SCHEMAS.
        format: File format ('csv', 'parquet', 'hdf5'). None -> auto-detect.
        hdf5_key: Key inside the HDF5 file.
        tick_size: Minimum price move.
        tick_value: Value of one tick.
        contract_size: Size of contract.
        digits: Number of decimal places.
        avg_spread: Average bid-ask spread.
        volume_min: Minimum order volume.
        volume_max: Maximum order volume.
        volume_step: Minimum volume increment (lot step).

    Returns:
        TickData: Normalized tick data object.

    Raises:
        DataError: If the source is unknown or a required column is missing.

    Example:
        ticks = read_trades('ADAUSDT-trades.csv', 'ADAUSD', source='binance')
        ticks.save('ada_ticks.parquet')
    """
    from tradetropy.core.data_types import TickData
    from tradetropy.data import normalize_ticks

    schema = _TRADE_SCHEMAS.get(source.lower())
    if schema is None:
        raise DataError(
            f"Unknown trades source {source!r}. "
            f"Available sources: {sorted(_TRADE_SCHEMAS)}."
        )

    path   = Path(path)
    format = format or _detect_format(path)
    df     = _read(path, format, hdf5_key)

    cols_map = {c.lower(): c for c in df.columns}

    def _need(field: str) -> pd.Series:
        real = cols_map.get(schema[field].lower())
        if real is None:
            raise DataError(
                f"{source!r} trades file is missing required column "
                f"{schema[field]!r} (for '{field}'). "
                f"Found columns: {list(df.columns)}."
            )
        return df[real]

    ts_ms  = _datetime_to_ts_ms(_need("time"))
    price  = _need("price").to_numpy(dtype=np.float64)
    volume = _need("volume").to_numpy(dtype=np.float64)
    flags  = schema["side_to_flags"](_need("side"))

    n = len(df)
    # Column order must match TICK_COLS: ts, bid, ask, volume, flags,
    # volume_real, price. bid/ask are left at 0.0 so normalize_ticks() fills
    # them from price (a trades file has no quotes); volume_real is NaN.
    data = np.column_stack([
        ts_ms.astype(np.float64),
        np.zeros(n, dtype=np.float64),
        np.zeros(n, dtype=np.float64),
        volume,
        flags,
        np.full(n, np.nan, dtype=np.float64),
        price,
    ])

    tick_data = TickData(
        symbol=symbol, data=data,
        tick_size=tick_size, tick_value=tick_value,
        contract_size=contract_size, digits=digits,
        avg_spread=avg_spread,
        volume_min=volume_min, volume_max=volume_max,
        volume_step=volume_step,
    )
    tick_data.data = normalize_ticks(tick_data.data)
    return tick_data

read_klines_csv

read_klines_csv(path, symbol, timeframe=None, **kwargs)

Compatibility alias for read_klines(format='csv'). Use read_klines() for new code.

Source code in src/tradetropy/io/_compat.py
def read_klines_csv(path, symbol, timeframe=None, **kwargs):
    """Compatibility alias for read_klines(format='csv'). Use read_klines() for new code."""
    return read_klines(path, symbol, timeframe, format="csv", **kwargs)

read_ticks_csv

read_ticks_csv(path, symbol, **kwargs)

Compatibility alias for read_ticks(format='csv'). Use read_ticks() for new code.

Source code in src/tradetropy/io/_compat.py
def read_ticks_csv(path, symbol, **kwargs):
    """Compatibility alias for read_ticks(format='csv'). Use read_ticks() for new code."""
    return read_ticks(path, symbol, format="csv", **kwargs)

save_ticks

save_ticks(data: 'TickProxy | np.ndarray | pd.DataFrame', path: str | Path, format: 'Literal["csv", "parquet", "hdf5", "npz"] | None' = None, ts_format: Literal['iso', 'ms', 's'] = 'iso', hdf5_key: str = 'data', compression: str = 'snappy', metadata: 'dict | None' = None) -> pd.DataFrame

Save ticks to file.

Parameters:

Name Type Description Default
data 'TickProxy | np.ndarray | pd.DataFrame'

TickProxy, ndarray [N×7] or DataFrame with standard tick columns.

required
path str | Path

Destination file path.

required
format 'Literal["csv", "parquet", "hdf5", "npz"] | None'

Output format ('csv', 'parquet', 'hdf5', 'npz'). None (default) infers from the extension, falling back to 'npz'.

None
ts_format Literal['iso', 'ms', 's']

Timestamp format for CSV ('iso', 'ms', 's').

'iso'
hdf5_key str

Key inside the HDF5 file.

'data'
compression str

Parquet compression method ('snappy', 'gzip', 'zstd', None).

'snappy'
metadata 'dict | None'

Optional dict of tradetropy metadata to store as HDF5 attrs.

None

Returns:

Type Description
DataFrame

pd.DataFrame: The saved tick data as DataFrame.

Example

save_ticks(self.btc_tick, 'ticks.npz') save_ticks(self.btc_tick, 'ticks.parquet', format='parquet') save_ticks(self.btc_tick, 'session.h5', format='hdf5', hdf5_key='btc/ticks') save_ticks(my_array, 'ticks.csv', format='csv')

Source code in src/tradetropy/io/_ticks.py
def save_ticks(
    data: "TickProxy | np.ndarray | pd.DataFrame",
    path: str | Path,
    format: 'Literal["csv", "parquet", "hdf5", "npz"] | None' = None,
    ts_format: Literal["iso", "ms", "s"] = "iso",
    hdf5_key: str = "data",
    compression: str = "snappy",
    metadata: "dict | None" = None,
) -> pd.DataFrame:
    """
    Save ticks to file.

    Args:
        data: TickProxy, ndarray [N×7] or DataFrame with standard tick columns.
        path: Destination file path.
        format: Output format ('csv', 'parquet', 'hdf5', 'npz'). None (default)
            infers from the extension, falling back to 'npz'.
        ts_format: Timestamp format for CSV ('iso', 'ms', 's').
        hdf5_key: Key inside the HDF5 file.
        compression: Parquet compression method ('snappy', 'gzip', 'zstd', None).
        metadata: Optional dict of tradetropy metadata to store as HDF5 attrs.

    Returns:
        pd.DataFrame: The saved tick data as DataFrame.

    Example:
        save_ticks(self.btc_tick, 'ticks.npz')
        save_ticks(self.btc_tick, 'ticks.parquet', format='parquet')
        save_ticks(self.btc_tick, 'session.h5', format='hdf5', hdf5_key='btc/ticks')
        save_ticks(my_array, 'ticks.csv', format='csv')
    """
    from tradetropy.core.constants import TICK_COLS, N_TICK_COLS

    format = _resolve_write_format(path, format)
    df = _source_to_df_ticks(data, N_TICK_COLS, TICK_COLS)
    if format == "csv":
        df = _ts_to_datetime(df, ts_format)
    elif format != "npz":
        df = _ts_to_datetime(df, "ms")
    # npz keeps the raw millisecond 'ts' column (read_ticks handles both).
    _write(df, path, format, hdf5_key, compression, metadata)
    if format == "hdf5" and metadata:
        _write_hdf5_attrs(Path(path), hdf5_key, metadata)
    return df

save_klines

save_klines(data: 'OhlcProxy | np.ndarray | pd.DataFrame', path: str | Path, format: 'Literal["csv", "parquet", "hdf5", "npz"] | None' = None, include_partial: bool = True, ts_format: Literal['iso', 'ms', 's'] = 'iso', hdf5_key: str = 'data', compression: str = 'snappy', metadata: 'dict | None' = None) -> pd.DataFrame

Save klines to file.

Parameters:

Name Type Description Default
data 'OhlcProxy | np.ndarray | pd.DataFrame'

OhlcProxy, ndarray [N×6] or DataFrame with standard OHLC columns.

required
path str | Path

Destination file path.

required
format 'Literal["csv", "parquet", "hdf5", "npz"] | None'

Output format ('csv', 'parquet', 'hdf5', 'npz'). None (default) infers from the extension, falling back to 'npz'.

None
include_partial bool

Include partial candle (partial=1) in OhlcProxy.

True
ts_format Literal['iso', 'ms', 's']

Timestamp format for CSV ('iso', 'ms', 's').

'iso'
hdf5_key str

Key inside the HDF5 file.

'data'
compression str

Parquet compression method ('snappy', 'gzip', 'zstd', None).

'snappy'
metadata 'dict | None'

Optional dict of tradetropy metadata to store as HDF5 attrs.

None

Returns:

Type Description
DataFrame

pd.DataFrame: The saved kline data as DataFrame.

Example

save_klines(self.btc_1m, 'ohlc.npz') save_klines(self.btc_1m, 'ohlc.parquet', format='parquet') save_klines(self.btc_1m, 'session.h5', format='hdf5', hdf5_key='btc/1m')

Source code in src/tradetropy/io/_klines.py
def save_klines(
    data: "OhlcProxy | np.ndarray | pd.DataFrame",
    path: str | Path,
    format: 'Literal["csv", "parquet", "hdf5", "npz"] | None' = None,
    include_partial: bool = True,
    ts_format: Literal["iso", "ms", "s"] = "iso",
    hdf5_key: str = "data",
    compression: str = "snappy",
    metadata: "dict | None" = None,
) -> pd.DataFrame:
    """
    Save klines to file.

    Args:
        data: OhlcProxy, ndarray [N×6] or DataFrame with standard OHLC columns.
        path: Destination file path.
        format: Output format ('csv', 'parquet', 'hdf5', 'npz'). None (default)
            infers from the extension, falling back to 'npz'.
        include_partial: Include partial candle (partial=1) in OhlcProxy.
        ts_format: Timestamp format for CSV ('iso', 'ms', 's').
        hdf5_key: Key inside the HDF5 file.
        compression: Parquet compression method ('snappy', 'gzip', 'zstd', None).
        metadata: Optional dict of tradetropy metadata to store as HDF5 attrs.

    Returns:
        pd.DataFrame: The saved kline data as DataFrame.

    Example:
        save_klines(self.btc_1m, 'ohlc.npz')
        save_klines(self.btc_1m, 'ohlc.parquet', format='parquet')
        save_klines(self.btc_1m, 'session.h5', format='hdf5', hdf5_key='btc/1m')
    """
    from tradetropy.core.constants import OHLC_COLS, N_OHLC_COLS

    format = _resolve_write_format(path, format)
    df = _source_to_df_klines(data, N_OHLC_COLS, OHLC_COLS, include_partial)
    if format == "csv":
        df = _ts_to_datetime(df, ts_format)
    elif format != "npz":
        df = _ts_to_datetime(df, "ms")
    # npz keeps the raw millisecond 'ts' column (read_klines handles both).
    _write(df, path, format, hdf5_key, compression, metadata)
    if format == "hdf5" and metadata:
        _write_hdf5_attrs(Path(path), hdf5_key, metadata)
    return df

save_book

save_book(data, path: str | Path, format: 'Literal["csv", "parquet", "hdf5", "npz"] | None' = None, *, levels: 'int | None' = None, layout: Literal['auto', 'wide', 'long'] = 'wide', ts_format: Literal['iso', 'ms', 's'] = 'iso', hdf5_key: str = 'book', compression: str = 'snappy', metadata: 'dict | None' = None) -> pd.DataFrame

Save L2 order-book rows to file (symmetric to save_ticks / save_klines).

Two on-disk layouts are supported (both round-trip through read_book):

  • layout='wide' (default, tradetropy native): grouped bid_px_/bid_sz_/ ask_px_/ask_sz_ columns, one book event per row.
  • layout='long' (Binance bookDepth-style): 'ts'/'percentage'/'depth'/ 'notional' columns, one row per price level per side with CUMULATIVE depth/notional (percentage = signed 1-based level index; negative = bid, positive = ask). This is a lossless re-encoding of the wide data that de-cumulates back exactly on read.

Parameters:

Name Type Description Default
data

BookData, ndarray [N x (2+4*levels)] or DataFrame with book cols.

required
path str | Path

Destination file path.

required
format 'Literal["csv", "parquet", "hdf5", "npz"] | None'

Output format ('csv', 'parquet', 'hdf5').

None
levels 'int | None'

Book levels K (required for a raw ndarray; taken from BookData).

None
layout Literal['auto', 'wide', 'long']

On-disk layout ('wide' or 'long').

'wide'
ts_format Literal['iso', 'ms', 's']

Timestamp format for CSV ('iso', 'ms', 's').

'iso'
hdf5_key str

Key inside the HDF5 file (default 'book').

'book'
compression str

Parquet compression method ('snappy', 'gzip', 'zstd', None).

'snappy'
metadata 'dict | None'

Optional dict of tradetropy metadata to store as HDF5 attrs (merged over the defaults derived from a BookData).

None

Returns:

Type Description
DataFrame

pd.DataFrame: The saved book data as DataFrame (in the chosen layout).

Example

book.save('book.h5') # via BookData.save() save_book(book, 'book.parquet', format='parquet') save_book(arr, 'book.csv', format='csv', levels=20) save_book(book, 'bookdepth.csv', layout='long')

Source code in src/tradetropy/io/_book.py
def save_book(
    data,
    path: str | Path,
    format: 'Literal["csv", "parquet", "hdf5", "npz"] | None' = None,
    *,
    levels: "int | None" = None,
    layout: Literal["auto", "wide", "long"] = "wide",
    ts_format: Literal["iso", "ms", "s"] = "iso",
    hdf5_key: str = "book",
    compression: str = "snappy",
    metadata: "dict | None" = None,
) -> pd.DataFrame:
    """
    Save L2 order-book rows to file (symmetric to save_ticks / save_klines).

    Two on-disk layouts are supported (both round-trip through read_book):

    - layout='wide' (default, tradetropy native): grouped bid_px_*/bid_sz_*/
      ask_px_*/ask_sz_* columns, one book event per row.
    - layout='long' (Binance bookDepth-style): 'ts'/'percentage'/'depth'/
      'notional' columns, one row per price level per side with CUMULATIVE
      depth/notional (percentage = signed 1-based level index; negative = bid,
      positive = ask). This is a lossless re-encoding of the wide data that
      de-cumulates back exactly on read.

    Args:
        data: BookData, ndarray [N x (2+4*levels)] or DataFrame with book cols.
        path: Destination file path.
        format: Output format ('csv', 'parquet', 'hdf5').
        levels: Book levels K (required for a raw ndarray; taken from BookData).
        layout: On-disk layout ('wide' or 'long').
        ts_format: Timestamp format for CSV ('iso', 'ms', 's').
        hdf5_key: Key inside the HDF5 file (default 'book').
        compression: Parquet compression method ('snappy', 'gzip', 'zstd', None).
        metadata: Optional dict of tradetropy metadata to store as HDF5 attrs
            (merged over the defaults derived from a BookData).

    Returns:
        pd.DataFrame: The saved book data as DataFrame (in the chosen layout).

    Example:
        book.save('book.h5')                        # via BookData.save()
        save_book(book, 'book.parquet', format='parquet')
        save_book(arr, 'book.csv', format='csv', levels=20)
        save_book(book, 'bookdepth.csv', layout='long')
    """
    from tradetropy.core.data_types import wide_rows_to_long, book_flat_columns

    format = _resolve_write_format(path, format)
    df, resolved_levels, default_meta = _source_to_df_book(data, levels)

    if layout == "long":
        wide_arr = df[book_flat_columns(resolved_levels)].to_numpy(dtype=np.float64)
        df = wide_rows_to_long(wide_arr, resolved_levels)

    # For CSV keep a human-readable 'datetime' column; for hdf5/parquet/npz keep
    # the raw 'ts' column (matching the record-path schema of _append_book, and
    # avoiding a datetime64 resolution round-trip).
    if format == "csv":
        df = _ts_to_datetime(df, ts_format)

    attrs = {**default_meta, "tradetropy_levels": int(resolved_levels)}
    if metadata:
        attrs.update(metadata)
    _write(df, path, format, hdf5_key, compression, attrs)
    if format == "hdf5":
        _write_hdf5_attrs(Path(path), hdf5_key, attrs)
    return df

save_proxy

save_proxy(proxy, path, format='parquet', **kwargs)

Save TickProxy or OhlcProxy to file.

Automatically dispatches to save_ticks() or save_klines() based on proxy type.

Parameters:

Name Type Description Default
proxy

TickProxy or OhlcProxy instance.

required
path

Destination file path.

required
format

Output format ('csv', 'parquet', 'hdf5').

'parquet'
**kwargs

Additional arguments passed to save_ticks() or save_klines().

{}

Raises:

Type Description
TradingError

If proxy type is not TickProxy or OhlcProxy.

Source code in src/tradetropy/io/_compat.py
def save_proxy(proxy, path, format="parquet", **kwargs):
    """
    Save TickProxy or OhlcProxy to file.

    Automatically dispatches to save_ticks() or save_klines() based on proxy type.

    Args:
        proxy: TickProxy or OhlcProxy instance.
        path: Destination file path.
        format: Output format ('csv', 'parquet', 'hdf5').
        **kwargs: Additional arguments passed to save_ticks() or save_klines().

    Raises:
        TradingError: If proxy type is not TickProxy or OhlcProxy.
    """

convert_book

convert_book(src: 'str | Path', dst: 'str | Path', *, symbol: 'str | None' = None, to_layout: Literal['wide', 'long'] = 'wide', src_layout: Literal['auto', 'wide', 'long'] = 'auto', src_format: 'Literal["csv", "parquet", "hdf5", "npz"] | None' = None, dst_format: 'Literal["csv", "parquet", "hdf5", "npz"] | None' = None, levels: 'int | None' = None, tick_size: float = 0.01, **save_kwargs)

Convert an order-book file between layouts and/or container formats.

Reads src (any supported layout/format) into a BookData - which is always the wide in-memory form - and writes it to dst in to_layout. Layout and container format are auto-detected from the file contents/extension unless overridden. This is thin sugar over read_book() + save_book().

Parameters:

Name Type Description Default
src 'str | Path'

Source order-book file path.

required
dst 'str | Path'

Destination file path.

required
symbol 'str | None'

Trading symbol (required if src carries no HDF5 metadata).

None
to_layout Literal['wide', 'long']

Output layout ('wide' or 'long').

'wide'
src_layout Literal['auto', 'wide', 'long']

Input layout ('auto', 'wide', 'long').

'auto'
src_format 'Literal["csv", "parquet", "hdf5", "npz"] | None'

Source format ('csv'/'parquet'/'hdf5'); None -> auto-detect.

None
dst_format 'Literal["csv", "parquet", "hdf5", "npz"] | None'

Destination format; None -> auto-detect from dst extension.

None
levels 'int | None'

Book levels K for the source (wide only; inferred otherwise).

None
tick_size float

Minimum price step propagated to the intermediate BookData.

0.01
**save_kwargs

Extra arguments forwarded to save_book (ts_format, hdf5_key, compression, metadata).

{}

Returns:

Name Type Description
BookData

The intermediate (wide) BookData, for convenience.

Example

convert_book('btc_bookdepth.csv', 'btc_book.h5', symbol='BTCUSDT') convert_book('btc_book.h5', 'btc_bookdepth.csv', to_layout='long')

Source code in src/tradetropy/io/_book.py
def convert_book(
    src: "str | Path",
    dst: "str | Path",
    *,
    symbol: "str | None" = None,
    to_layout: Literal["wide", "long"] = "wide",
    src_layout: Literal["auto", "wide", "long"] = "auto",
    src_format: 'Literal["csv", "parquet", "hdf5", "npz"] | None' = None,
    dst_format: 'Literal["csv", "parquet", "hdf5", "npz"] | None' = None,
    levels: "int | None" = None,
    tick_size: float = 0.01,
    **save_kwargs,
):
    """
    Convert an order-book file between layouts and/or container formats.

    Reads ``src`` (any supported layout/format) into a BookData - which is always
    the wide in-memory form - and writes it to ``dst`` in ``to_layout``. Layout
    and container format are auto-detected from the file contents/extension
    unless overridden. This is thin sugar over read_book() + save_book().

    Args:
        src: Source order-book file path.
        dst: Destination file path.
        symbol: Trading symbol (required if src carries no HDF5 metadata).
        to_layout: Output layout ('wide' or 'long').
        src_layout: Input layout ('auto', 'wide', 'long').
        src_format: Source format ('csv'/'parquet'/'hdf5'); None -> auto-detect.
        dst_format: Destination format; None -> auto-detect from dst extension.
        levels: Book levels K for the source (wide only; inferred otherwise).
        tick_size: Minimum price step propagated to the intermediate BookData.
        **save_kwargs: Extra arguments forwarded to save_book (ts_format,
            hdf5_key, compression, metadata).

    Returns:
        BookData: The intermediate (wide) BookData, for convenience.

    Example:
        convert_book('btc_bookdepth.csv', 'btc_book.h5', symbol='BTCUSDT')
        convert_book('btc_book.h5', 'btc_bookdepth.csv', to_layout='long')
    """
    book = read_book(
        src, symbol=symbol, levels=levels, format=src_format,
        layout=src_layout, tick_size=tick_size,
    )
    dst_format = dst_format or _detect_format(Path(dst))
    save_book(book, dst, format=dst_format, layout=to_layout, **save_kwargs)
    return book

ticks_to_file

ticks_to_file(data, path, **kwargs)

Compatibility alias for save_ticks(). Use save_ticks() for new code.

Source code in src/tradetropy/io/_compat.py
def ticks_to_file(data, path, **kwargs):
    """Compatibility alias for save_ticks(). Use save_ticks() for new code."""
    return save_ticks(data, path, **kwargs)

klines_to_file

klines_to_file(data, path, **kwargs)

Compatibility alias for save_klines(). Use save_klines() for new code.

Source code in src/tradetropy/io/_compat.py
def klines_to_file(data, path, **kwargs):
    """Compatibility alias for save_klines(). Use save_klines() for new code."""
    return save_klines(data, path, **kwargs)

book_to_file

book_to_file(data, path, **kwargs)

Compatibility alias for save_book(). Use save_book() for new code.

Source code in src/tradetropy/io/_compat.py
def book_to_file(data, path, **kwargs):
    """Compatibility alias for save_book(). Use save_book() for new code."""
    return save_book(data, path, **kwargs)

klines_from_file

klines_from_file(path, symbol, timeframe=None, **kwargs)

Compatibility alias for read_klines(). Use read_klines() for new code.

Source code in src/tradetropy/io/_compat.py
def klines_from_file(path, symbol, timeframe=None, **kwargs):
    """Compatibility alias for read_klines(). Use read_klines() for new code."""
    return read_klines(path, symbol, timeframe, **kwargs)

ticks_from_file

ticks_from_file(path, symbol, **kwargs)

Compatibility alias for read_ticks(). Use read_ticks() for new code.

Source code in src/tradetropy/io/_compat.py
def ticks_from_file(path, symbol, **kwargs):
    """Compatibility alias for read_ticks(). Use read_ticks() for new code."""
    return read_ticks(path, symbol, **kwargs)

book_from_file

book_from_file(path, symbol=None, **kwargs)

Compatibility alias for read_book(). Use read_book() for new code.

Source code in src/tradetropy/io/_compat.py
def book_from_file(path, symbol=None, **kwargs):
    """Compatibility alias for read_book(). Use read_book() for new code."""
    return read_book(path, symbol, **kwargs)