hftbacktest.data.utils.databento module

convert(input_file, symbol, output_filename=None, base_latency=0, file_type='mbo')[source]

Converts a DataBento L3 Market-By-Order data file into a format compatible with HftBacktest.

DataBento’s historical data includes a Start-of-Day (SOD) snapshot for CME data. In the snapshot, the exchange timestamp represents the original time when the order was submitted, and the data is sorted in chronological order. This ensures that orders are built with the correct price-time priority. However, since these timestamps are in the past (before the clear message), the exchange timestamp is artificially set to the local timestamp to indicate the snapshot. This adjustment maintains the chronological order of exchange timestamps during multi-day backtesting.

Parameters:
  • input_file (str) – DataBento’s DBN file. e.g. *.mbo.dbn.zst

  • symbol (str | None) – Specify the symbol to process in the given file. If the file contains multiple symbols, the symbol should be provided; otherwise, the output file will contain mixed symbols.

  • output_filename (str | None) – If provided, the converted data will be saved to the specified filename in npz format.

  • base_latency (float) – The value to be added to the feed latency. See correct_local_timestamp().

  • file_type (Literal['mbo']) – Currently, only ‘mbo’ is supported.

Returns:

Converted data compatible with HftBacktest.

Return type:

ndarray[Any, dtype[_ScalarType_co]]