engine

package
v0.2.5 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 14, 2026 License: BSD-2-Clause Imports: 8 Imported by: 0

Documentation

Overview

Package engine is the low-level backtest/live execution mechanism: the Trader type, which drives an execution.Broker and drains its event queue while tracking open lots. It is pure mechanism with no notion of a "run" — the higher-level backtest package orchestrates runs on top of it (backtest -> engine; engine never imports backtest).

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func SnapshotLots

func SnapshotLots(src *execution.LotBook) *execution.LotBook

SnapshotLots returns a deep copy of the open/pending lots in src so callers can hand a stable view to a strategy without racing the broker.

Types

type CandleSource

type CandleSource interface {
	Candles(context.Context, datamanager.CandleRequest) (market.CandleIterator, error)
}

CandleSource provides candle iterators for backtest and replay execution. datamanager.DataManager satisfies this interface.

type Trader

type Trader struct {
	DataManager CandleSource
	*execution.Broker
}

Trader couples a candle source with the broker/account it drives. It owns the broker event loop; backtest and live orchestration call its exported primitives to run a session.

func (*Trader) BrokerEventError

func (t *Trader) BrokerEventError(errCh <-chan error) error

BrokerEventError returns the first pending broker-event error without blocking, or nil if none is queued.

func (*Trader) StartBrokerEventHandler

func (t *Trader) StartBrokerEventHandler(ctx context.Context, evtQ <-chan *execution.Event, processed *int64) (<-chan error, <-chan struct{})

StartBrokerEventHandler launches the goroutine that drains the broker event queue, processing each event and reporting the first error on the returned error channel. The done channel closes when the handler exits.

func (*Trader) WaitForBrokerIdle

func (t *Trader) WaitForBrokerIdle(errCh <-chan error, timeout time.Duration) error

WaitForBrokerIdle blocks until the broker's event queue is empty and no lot is in a pending open/close state, or until timeout elapses.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL