Skip to content

Streaming and C ABI

The dependency-free ctypes bridge packs normalized records into the arrays accepted by PineForge strategy libraries. Providers remain responsible for ordering and provenance before the handoff.

PfBar

Bases: Structure

ctypes mirror of PineForge's pf_bar_t.

PfTradeTick

Bases: Structure

ctypes mirror of PineForge's pf_trade_tick_t.

pack_bars

pack_bars(
    bars: Sequence[Bar],
    *,
    instrument: Instrument | None = None,
) -> Array[PfBar]

Pack normalized bars into one contiguous pf_bar_t array.

pack_trade_ticks

pack_trade_ticks(
    ticks: Sequence[TradeTick],
    *,
    instrument: Instrument | None = None,
) -> Array[PfTradeTick]

Pack normalized trades into one contiguous pf_trade_tick_t array.

EngineStreamSink

EngineStreamSink(
    library: CDLL,
    state: int | c_void_p,
    instrument: Instrument,
)

Send normalized records to an existing PineForge strategy instance.

The caller owns both library and state. This adapter configures and invokes only the streaming functions; it never creates or frees a strategy.

begin

begin(
    warmup_bars: Sequence[Bar],
    *,
    input_timeframe: str,
    script_timeframe: str,
) -> None

Warm the strategy on confirmed bars and start realtime streaming.

push_tick

push_tick(tick: TradeTick) -> None

Push one normalized executed trade.

push_ticks

push_ticks(ticks: Sequence[TradeTick]) -> None

Push normalized executed trades in one contiguous ABI call.

advance_time

advance_time(timestamp_ms: int) -> None

Advance the stream clock so elapsed input bars can close.

end

end(*, finalize_partial_input_bar: bool = False) -> None

End the stream, optionally dispatching its partial input bar.

EngineStreamError

Bases: RuntimeError

A PineForge streaming C ABI call failed.