actor

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jul 22, 2026 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ApplyName

func ApplyName(a Actor, name string)

ApplyName sets the actor's name from the config entry. If name is empty, the actor keeps its default name from construction. This works on any actor that embeds ActorBase (which provides SetName).

func Register

func Register(bus *msgbus.MsgBus, a Actor)

Register is a helper function that registers an Actor with the MsgBus. It creates a handler that calls the actor's Handle method with the MsgBus reference. If a Clock is attached to the MsgBus via SetTicker, it is automatically injected into the actor (available via ActorBase.Clock() in OnStart and Handle).

Types

type Actor

type Actor interface {
	// Identity
	// Name returns a unique identifier for this actor.
	// Used for sequence tracking and debugging.
	Name() string

	// Event subscription
	// SubscribedTypes returns the event types this actor wants to receive.
	// Return nil or empty slice to receive all event types.
	SubscribedTypes() []event.Topic

	// Event handling
	// Handle processes an event from the MsgBus.
	// The MsgBus reference is provided to allow reading the full event data
	// from the appropriate arena based on the event reference, and to send
	// commands via the command channel.
	Handle(ev msgbus.Event, bus *msgbus.MsgBus)

	// Lifecycle methods
	// OnInit is called once when the actor is initialized.
	OnInit(map[string]any)
	// OnStart is called once when the actor is started.
	OnStart()
	// OnStop is called once when the actor is stopped.
	OnStop()
}

Actor is the unified interface for all event-driven components. Both infrastructure actors (OrderBook, EMS) and trading strategies implement this.

Actors are the fundamental building blocks of the trading system: - OrderBook actor handles depth snapshots and updates - EMS actor handles order updates and fills - Strategy actors implement trading logic

type ActorBase

type ActorBase struct {
	// contains filtered or unexported fields
}

ActorBase provides a default implementation for the Actor interface. Embed this in infrastructure actors like OrderBook, EMS. For trading strategies, use StrategyBase instead which provides typed callbacks.

func NewActorBase

func NewActorBase(name string, topics []event.Topic) ActorBase

NewActorBase creates a new ActorBase with the given name and subscribed topics.

func (*ActorBase) Clock

func (a *ActorBase) Clock() *clock.Clock

Clock returns the injected Clock instance. Available after actor.Register().

func (*ActorBase) Handle

func (a *ActorBase) Handle(ev msgbus.Event, bus *msgbus.MsgBus)

Handle is a no-op default. Concrete actors should override this.

func (*ActorBase) Log

func (a *ActorBase) Log() *zerolog.Logger

Logger returns the actor's logger.

func (*ActorBase) Name

func (a *ActorBase) Name() string

Name returns the actor's unique identifier.

func (*ActorBase) OnInit

func (a *ActorBase) OnInit(config map[string]any)

OnInit is a no-op default lifecycle method.

func (*ActorBase) OnStart

func (a *ActorBase) OnStart()

OnStart is a no-op default lifecycle method.

func (*ActorBase) OnStop

func (a *ActorBase) OnStop()

OnStop is a no-op default lifecycle method.

func (*ActorBase) SetClock

func (a *ActorBase) SetClock(c *clock.Clock)

SetClock sets the clock on this actor. Called automatically by actor.Register().

func (*ActorBase) SetName

func (a *ActorBase) SetName(name string)

SetName overrides the actor's name and re-initializes its logger with the new name context. This is typically called by the engine after construction to apply the name from config. If name is empty, this is a no-op.

func (*ActorBase) SetTopics

func (a *ActorBase) SetTopics(topics []event.Topic)

SetTopics overrides the actor's subscribed topics. Typically called from OnInit when topics are configured via YAML.

func (*ActorBase) SubscribedTypes

func (a *ActorBase) SubscribedTypes() []event.Topic

SubscribedTypes returns the topics this actor handles.

type Entry

type Entry struct {
	Type   string         `yaml:"type"`
	Name   string         `yaml:"name"`
	Config map[string]any `yaml:"config"`
}

Entry is the universal config entry for an actor across all engines. Every engine config has an Actor []Entry field.

Jump to

Keyboard shortcuts

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