Data
The data subpackage groups components relating to the data stack and data tooling for the platform.
The layered architecture of the data stack somewhat mirrors the execution stack with a central engine, cache layer beneath, database layer beneath, with alternative implementations able to be written on top.
Due to the high-performance, the core components are reusable between both backtest and live implementations - helping to ensure consistent logic for trading operations.
Aggregation
class BarAggregator
Bases: object
BarAggregator(Instrument instrument, BarType bar_type, handler: Callable[[Bar], None], bool await_partial=False)
Provides a means of aggregating specified bars and sending to a registered handler.
- Parameters:
- instrument (Instrument) – The instrument for the aggregator.
- bar_type (BarType) – The bar type for the aggregator.
- handler (Callable [ [Bar ] , None ]) – The bar handler for the aggregator.
- await_partial (bool , default False) – If the aggregator should await an initial partial bar prior to aggregating.
- Raises: ValueError – If instrument.id != bar_type.instrument_id.
bar_type
The aggregators bar type.
- Returns: BarType
handle_bar(self, Bar bar) → void
Update the aggregator with the given bar.
- Parameters: bar (Bar) – The bar for the update.
handle_quote_tick(self, QuoteTick tick) → void
Update the aggregator with the given tick.
- Parameters: tick (QuoteTick) – The tick for the update.
handle_trade_tick(self, TradeTick tick) → void
Update the aggregator with the given tick.
- Parameters: tick (TradeTick) – The tick for the update.
set_await_partial(self, bool value)
set_partial(self, Bar partial_bar) → void
Set the initial values for a partially completed bar.
This method can only be called once per instance.
- Parameters: partial_bar (Bar) – The partial bar with values to set.
start_batch_update(self, handler: Callable[[Bar], None], uint64_t time_ns) → None
stop_batch_update(self) → None
class BarBuilder
Bases: object
BarBuilder(Instrument instrument, BarType bar_type)
Provides a generic bar builder for aggregation.
- Parameters:
- instrument (Instrument) – The instrument for the builder.
- bar_type (BarType) – The bar type for the builder.
- Raises: ValueError – If instrument.id != bar_type.instrument_id.
build(self, uint64_t ts_event, uint64_t ts_init) → Bar
Return the aggregated bar with the given closing timestamp, and reset.
- Parameters:
- ts_event (uint64_t) – UNIX timestamp (nanoseconds) for the bar event.
- ts_init (uint64_t) – UNIX timestamp (nanoseconds) for the bar initialization.
- Return type: Bar
build_now(self) → Bar
Return the aggregated bar and reset.
- Return type: Bar
count
The builders current update count.
- Returns: int
initialized
If the builder is initialized.
- Returns: bool
price_precision
The price precision for the builders instrument.
- Returns: uint8
reset(self) → void
Reset the bar builder.
All stateful fields are reset to their initial value.
set_partial(self, Bar partial_bar) → void
Set the initial values for a partially completed bar.
This method can only be called once per instance.
- Parameters: partial_bar (Bar) – The partial bar with values to set.
size_precision
The size precision for the builders instrument.
- Returns: uint8
ts_last
UNIX timestamp (nanoseconds) when the builder last updated.
- Returns: uint64_t
update(self, Price price, Quantity size, uint64_t ts_event) → void
Update the bar builder.
- Parameters:
- price (Price) – The update price.
- size (Decimal) – The update size.
- ts_event (uint64_t) – UNIX timestamp (nanoseconds) of the update.
update_bar(self, Bar bar, Quantity volume, uint64_t ts_init) → void
Update the bar builder.
- Parameters: bar (Bar) – The update Bar.
class TickBarAggregator
Bases: BarAggregator
TickBarAggregator(Instrument instrument, BarType bar_type, handler: Callable[[Bar], None])
Provides a means of building tick bars from ticks.
When received tick count reaches the step threshold of the bar specification, then a bar is created and sent to the handler.
- Parameters:
- instrument (Instrument) – The instrument for the aggregator.
- bar_type (BarType) – The bar type for the aggregator.
- handler (Callable [ [Bar ] , None ]) – The bar handler for the aggregator.
- Raises: ValueError – If instrument.id != bar_type.instrument_id.
bar_type
The aggregators bar type.
- Returns: BarType
handle_bar(self, Bar bar) → void
Update the aggregator with the given bar.
- Parameters: bar (Bar) – The bar for the update.
handle_quote_tick(self, QuoteTick tick) → void
Update the aggregator with the given tick.
- Parameters: tick (QuoteTick) – The tick for the update.
handle_trade_tick(self, TradeTick tick) → void
Update the aggregator with the given tick.
- Parameters: tick (TradeTick) – The tick for the update.
set_await_partial(self, bool value)
set_partial(self, Bar partial_bar) → void
Set the initial values for a partially completed bar.
This method can only be called once per instance.
- Parameters: partial_bar (Bar) – The partial bar with values to set.