LOBSTER¶
Support for LOBSTER message files (event types 1–7), orderbook-backed depth, and round-trip writers.
Use via Pipeline(source=LobsterSource(...)) or
Pipeline.from_source("lobster", ...).
Key differences from Bitstamp:
- Executions in the message file —
LobsterTradeReaderbuilds trades directly from type 4/5 rows in the events DataFrame (no separate trades file). - Orderbook-backed depth —
LobsterSource.compute_depthreads the official orderbook file for ground-truth depth instead of reconstructing from events - Integer prices — raw prices are in ten-thousandths of a dollar
(
price_divisor=10000)
LobsterLoader ¶
LobsterLoader(
config: PipelineConfig | None = None,
*,
trading_date: str | Timestamp,
session_tz: str = LOBSTER_DEFAULT_TZ,
venue: str | None = None,
symbol: str | None = None,
)
Load raw limit-order events from LOBSTER message files.
Satisfies the :class:~ob_analytics.protocols.EventLoader protocol.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config
|
PipelineConfig
|
Pipeline configuration. |
None
|
trading_date
|
str or Timestamp
|
The calendar date of the trading session (LOBSTER timestamps are seconds after midnight and need a date anchor). |
required |
session_tz
|
str
|
The venue's local time zone, used to place the session's seconds after
midnight on the shared UTC clock. Defaults to
:data: |
LOBSTER_DEFAULT_TZ
|
venue
|
str
|
Optional instrument identity. When either is supplied, the loaded
frame gains per-row |
None
|
symbol
|
str
|
Optional instrument identity. When either is supplied, the loaded
frame gains per-row |
None
|
load ¶
Load LOBSTER message data and return a cleaned events DataFrame.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
source
|
str, Path, or directory
|
Path to a LOBSTER message CSV, or a directory containing message/orderbook file pairs. When a directory is given the loader auto-discovers files by the LOBSTER naming convention. |
required |
Returns:
| Type | Description |
|---|---|
DataFrame
|
|
LobsterTradeReader ¶
Build trades directly from LOBSTER execution events.
In LOBSTER, each execution event (type 4 or 5) represents the resting (maker) side of a trade. This reader builds trade records directly from those rows in the events frame; no matching is needed because the data already pairs maker rows with executions.
Satisfies the :class:~ob_analytics.protocols.TradeSource protocol.
load ¶
Build a trades DataFrame from LOBSTER execution events.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
events
|
DataFrame
|
Events with |
required |
source
|
Any
|
Unused; trade information is embedded in events. |
required |
Returns:
| Type | Description |
|---|---|
DataFrame
|
Trades with |
LobsterWriter ¶
LobsterWriter(
config: PipelineConfig | None = None,
*,
trading_date: str | Timestamp,
session_tz: str = LOBSTER_DEFAULT_TZ,
price_divisor: int | None = None,
)
Write a run as a LOBSTER message file and orderbook file.
The message file has one row per event. The orderbook file has one row
per message: the book after that event, taken from the run's depth table.
So the file holds the book the run computed, whatever source the run came
from. Reading the files back with :class:LobsterSource gives the run's
book after every event: the depth summary read back equals the run's, as
far as the written levels reach.
Satisfies the :class:~ob_analytics.protocols.DataWriter protocol.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config
|
PipelineConfig
|
The run's configuration: its |
None
|
trading_date
|
str or Timestamp
|
Calendar date of the session. |
required |
session_tz
|
str
|
The venue's local time zone, used to convert the shared UTC clock back
to LOBSTER's seconds after local midnight. Defaults to
:data: |
LOBSTER_DEFAULT_TZ
|
price_divisor
|
int
|
Multiplier to convert decimal prices back to LOBSTER integers. |
None
|
write ¶
write(
data: dict[str, DataFrame],
dest: str | Path,
*,
ticker: str = "DATA",
num_levels: int = 10,
**kwargs: Any,
) -> tuple[Path, Path]
Write a run to a LOBSTER message file and orderbook file.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
dict
|
The run's tables. |
required |
dest
|
str or Path
|
Output directory. |
required |
ticker
|
str
|
Ticker symbol for filename. |
'DATA'
|
num_levels
|
int
|
Number of price levels per side in the orderbook file. A book with fewer levels is padded with LOBSTER's dummy prices and zero sizes; a book with more is cut to the levels nearest the touch. |
10
|
Returns:
| Type | Description |
|---|---|
tuple of Path
|
|
Raises:
| Type | Description |
|---|---|
ConfigError
|
If the run has no events, the events lack a column, two events
share an |
LobsterSource
dataclass
¶
The LOBSTER source: offline replay of message/orderbook files (L3).
trading_date is taken from the per-run
:class:~ob_analytics.protocols.RunContext, not the source
constructor — so the same LobsterSource() instance can be reused
across runs with different sessions. Offline only: LOBSTER ships as data
files, so it satisfies :class:~ob_analytics.protocols.OfflineSource and
has no live capability.
lobster_depth_from_orderbook ¶
lobster_depth_from_orderbook(
events: DataFrame,
orderbook_path: Path,
config: PipelineConfig,
*,
message_rows: int | None = None,
) -> tuple[pd.DataFrame, pd.DataFrame]
Compute depth and depth summary from the LOBSTER orderbook file.
The LOBSTER orderbook file is ground truth: it records the complete
visible book state after every message event. This function converts
it into the (depth, depth_summary) pair the pipeline expects,
avoiding the need to reconstruct depth from message events (which
fails when events reference pre-market orders absent from the
message file).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
events
|
DataFrame
|
The events the :class: |
required |
orderbook_path
|
Path
|
Path to the LOBSTER orderbook CSV. |
required |
config
|
PipelineConfig
|
Pipeline configuration. The file's prices are read on
|
required |
message_rows
|
int
|
The number of rows in the message file, every event type included.
When given, the orderbook file must have exactly this many rows.
:class: |
None
|
Returns:
| Type | Description |
|---|---|
tuple of (depth DataFrame, depth_summary DataFrame)
|
Sizes in both are |
Raises:
| Type | Description |
|---|---|
ConfigError
|
If events lacks a column this needs, an |