Crates.io | tvi |
lib.rs | tvi |
version | 0.1.1-alpha |
created_at | 2025-09-06 12:04:09.421067+00 |
updated_at | 2025-09-08 01:53:47.468728+00 |
description | A π₯fastπ₯ parser for historical TotalView-ITCH data |
homepage | https://github.com/princeton-ddss/totalview-itch.rs |
repository | https://github.com/princeton-ddss/totalview-itch.rs |
max_upload_size | |
id | 1826998 |
size | 205,229 |
A π₯fastπ₯ parser for historical TotalView-ITCH data.
Nasdaq TotalView-ITCH (βTotalViewβ) is a data feed used by professional traders to maintain a real-time view of market conditions. TotalView disseminates all quote and order activity for securities traded on the Nasdaq exchangeβseveral billion messages per dayβallowing users to reconstruct the limit order book for any security up to arbitrary depth with nanosecond precision. It is a unique data source for financial economists and engineers examining topics such as information flows through lit exchanges, optimal trading strategies, and the development of macro-level indicators from micro-level signals (e.g., a market turbulence warning).
While TotalView data is provided at no charge to academic researchers via the Historical TotalView-ITCH offering, the historical data offering uses a binary file specification that poses challenges for researchers. TotalView-ITCH.rs is a pure Rust package developed to efficiently process and store historical data files for academic research purposes.
curl -sSL https://github.com/princeton-ddss/totalview-itch.rs/install.sh | sh
git clone https://github.com/princeton-ddss/totalview-itch.rs
cd totalview-itch.rs
cargo install --path .
Usage is straightforward:
tvi data/S031413-v41.txt --tickers AAPL --depth 3
This example parses a raw ITCH file, S031413-v41.txt
, which happens to have
v4.1
formatting, and stores the extracted data for the specified ticker (message, orderbooks,
etc.) to CSV files in ./data
. To process multiple tickers, simply add the additional tickers to the
list:
tvi data/S031413-v41.txt --tickers AAPL,MSFT --depth 3
Processing of multiple files (i.e., dates) can be performed using multiple processes or multiple jobs on a high-performance computing cluster.
The processed data can be loaded using your favorite data processing tools, e.g., Polars.
Totalview-ITCH.rs aims to support a variety data storage options. We currently support writing to CSV and aim to support Parquet and Postgres in the need future.
The default writer stores data in CSV format. Output has the following directory structure:
test
|- messages
|- date=2013-03-14
|- partition.csv
|- date=2013-03-15
|- partition.csv
|- orderbooks
|- noii
|- trades
This structure is convenient for parallelizing analyses performed at the ticker-date level.
Under construction π§
Under construction π§
The default parsing method creates four tables/collections:
messages
: messages that reflect order book updates,orderbooks
: order book snapshots following each message,noii
: net order imbalance indicator messages,trades
: messages that indicate trades involving non-displayed orders,All records are stored in ascending temporal order.
messages
Each row of the messages
table indicates an update to the order book. The types of updates are:
A
or F
)X
)D
)U
)E
or C
)Note that replace orders are split into their constituent add and delete orders in the database.
Field | Type | Description | Required? | Default |
---|---|---|---|---|
date | string |
The file date (YYYY-MM-DD ). |
β | |
nanoseconds | u64 |
The number of seconds since midnight. | β | |
kind | char |
The message type symbol as defined in TotalView specification. | β | |
ticker | string |
The stock ticker associated with the message. | β | |
side | char |
The side of the order book affected by the message (B or S ). |
β | |
price | u32 |
The price associated with an order update. | β | |
shares | u32 |
The number of shares associated with the order or update. | β | |
refno | u64 |
A day-unique reference number associated with an original limit order. | β | |
from_replace | bool |
An indicator that is True if message is part of a replacemnet order. |
β | |
mpid | string |
An optional market participant identifier. | None |
|
printable | char |
Indicates if an execution should be included in volume calculations. | None |
|
execution_price | u32 |
The price at which an execution occurred (if different from original) | None |
orderbooks
Each row the orderbooks
table represents a snapshot of the order book associated with an order book update. That is, the n
-th row of the orderbooks
table represents the state of the order book immediately following the update indicated by the n
-th row of the messages
table. The exact fields available depend on the number of levels of levels tracked during parsing, N
. For a given N
, prices and shares are recorded in order from best to worst offer for bids and asks, respectively.
Field | Type | Description | Required? | Default |
---|---|---|---|---|
date | string |
The file date (YYYY-MM-DD ). |
β | |
nanoseconds | u64 |
The number of nanoseconds since the most recent second. | β | None |
ticker | string |
The stock ticker associated with the order book. | β | None |
bid_price_n |
u32 |
The offer price of the n -th best bid (N=1,..., N ). |
β | None |
ask_price_n |
u32 |
The offer price of the n -th best ask (N=1,..., N ). |
β | None |
bid_shares_n |
u32 |
The offer volume at the n -th best bid (N=1,..., N ). |
β | None |
ask_shares_n |
u32 |
The offer volume at the n -th best ask (N=1,..., N ). |
β | None |
noii
Net Order Imbalance Indicator (NOII) messages are disseminated prior to market open and close as well as during quote only periods. The noii
collection stores these messages for all tickers in a single file for each date.
Field | Type | Description | Required? | Default |
---|---|---|---|---|
date | string |
The file date (YYYY-MM-DD ). |
β | |
nanoseconds | Int |
The number of nanoseconds since the most recent second. | β | |
type | char |
The cross type: opening (O ), close (C ) or halted (H ). |
β | |
ticker | string |
The stock ticker associated with the message. | β | |
paired | u32 |
The number of shares matched at the current reference price. | β | |
imbalance | u32 |
The number of shares not paired at the current reference price. | β | |
direction | char |
The side of the imbalance (B , S , N or O ). |
β | |
far | u32 |
A hypothetical clearing price for cross orders only. | β | |
near | u32 |
A hypothetical clearing price for cross and continuous orders. | β | |
current | u32 |
The price at which the imbalance is calculated. | β |
trades
Rows of the trades
collection reflect two types of trades that are not captured in the order book update: cross and non-cross trades. Non-cross trade messages "provide details for normal match events involving non-displayable order type"βi.e., hidden orders. Cross trade message (type=='Q'
) "indicate that Nasdaq has completed its cross process for a specific security". Neither trade type affects the state of the (visible) order book, but both should be included in volume calculations.
Field | Type | Description | Required? | Default |
---|---|---|---|---|
date | string |
The file date (YYYY-MM-DD ). |
β | |
nanoseconds | u64 |
The number of nanoseconds since the most recent second. | β | |
type | char |
The type of trade: hidden (P ) or cross (Q ). |
β | |
ticker | string |
The stock ticker associated with the trade. | β | |
refno | u64 |
A day-unique reference number associated with an original limit order. | Hidden trades only. | None |
matchno | u64 |
A day-unique reference number associated with the trade or cross. | β | |
side | char |
The type of non-display order matched (B of S ). |
Hidden trades only. | None |
price | u32 |
The price of the cross. | Cross trades only. | None |
shares | u32 |
The number of shares traded. | β | |
cross | char |
The cross type: opening (O ), close (C ), halted (H ) or intrday (I ). |
β |
TotalView-ITCH.rs
supports versions 4.1
and 5.0
of the TotalView-ITCH file
specificiation. The parser processes all message types required to reconstruct
limit order books as well as several types that do not impact the order book.
Message Type | Symbol | Supported? | Notes |
---|---|---|---|
Timestamp | T | 4.1 | Message type only exists for v4.1 . |
System | S | β | |
Market Participant | L | ||
Trade Action | H | β | |
Reg SHO | Y | ||
Stock Directory | R | ||
Add | A | β | |
Add w/ MPID | F | β | |
Execute | E | β | |
Execute w/ Price | C | β | |
Cancel | X | β | |
Delete | D | β | |
Replace | U | β | |
Cross Trade | Q | β | Ignored by order book updates. |
Trade | P | β | Ignored by order book updates. |
Broken Trade | B | β | Ignored by order book updates. |
NOII | I | β | |
RPII | N |
We plan to process and record the following additional message types:
[!WARNING] Note that the format of the database is not stable and may change in the future.
There are no plans to support the following message categories:
retail price improvement indicator (RPII) messages (4.8),
market-wide circuit breaker messages (4.2.5)
IPO quoting period updates (4.2.6),
Limit up/down (LULD) aution collar messages (4.2.7),
Operational halt messages (4.2.8),
This package is intended to be a community resource for researchers working with TotalViewITCH. If you find a bug, have a suggestion or otherwise wish to contribute to the package, please feel free to create an issue or open a pull request.