strategy

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Jun 16, 2026 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

View Source
const (
	TopicExecution  = "execution"
	TopicMarketData = "market.data"
	TopicTimer      = "timer"
	TopicError      = "error"
)

Variables

View Source
var ErrInvalidIndicator = fmt.Errorf("invalid indicator")
View Source
var ErrInvalidStrategyConfig = fmt.Errorf("invalid strategy config")
View Source
var ErrInvalidTimer = errors.New("invalid timer")

Functions

func ValidateTimer

func ValidateTimer(name string, interval time.Duration) error

Types

type AverageTrueRange

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

func NewAverageTrueRange

func NewAverageTrueRange(period int) (*AverageTrueRange, error)

func (*AverageTrueRange) Count

func (a *AverageTrueRange) Count() int

func (*AverageTrueRange) Initialized

func (a *AverageTrueRange) Initialized() bool

func (*AverageTrueRange) Name

func (a *AverageTrueRange) Name() string

func (*AverageTrueRange) Reset

func (a *AverageTrueRange) Reset()

func (*AverageTrueRange) UpdateBar

func (a *AverageTrueRange) UpdateBar(bar model.Bar) error

func (*AverageTrueRange) Value

func (a *AverageTrueRange) Value() decimal.Decimal

type Clock

type Clock interface {
	Now() time.Time
}

type Engine

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

func NewEngine

func NewEngine(b *bus.Bus, opts ...Option) *Engine

func (*Engine) Add

func (e *Engine) Add(s Strategy) error

func (*Engine) Errors

func (e *Engine) Errors() <-chan error

func (*Engine) Process

func (e *Engine) Process(ctx context.Context, env bus.Envelope) error

func (*Engine) Start

func (e *Engine) Start(ctx context.Context) error

func (*Engine) Stop

func (e *Engine) Stop(ctx context.Context) error

type ErrorEvent

type ErrorEvent struct {
	Source string
	Err    error
}

type ExponentialMovingAverage

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

func NewExponentialMovingAverage

func NewExponentialMovingAverage(period int) (*ExponentialMovingAverage, error)

func (*ExponentialMovingAverage) Count

func (e *ExponentialMovingAverage) Count() int

func (*ExponentialMovingAverage) Initialized

func (e *ExponentialMovingAverage) Initialized() bool

func (*ExponentialMovingAverage) Name

func (e *ExponentialMovingAverage) Name() string

func (*ExponentialMovingAverage) Reset

func (e *ExponentialMovingAverage) Reset()

func (*ExponentialMovingAverage) Update

func (e *ExponentialMovingAverage) Update(value decimal.Decimal) error

func (*ExponentialMovingAverage) Value

type Indicator

type Indicator interface {
	Name() string
	Initialized() bool
	Count() int
	Value() decimal.Decimal
	Reset()
}

type Option

type Option func(*Engine)

func WithRuntime

func WithRuntime(runtime Runtime) Option

func WithSynchronousDispatch

func WithSynchronousDispatch() Option

func WithTraderID

func WithTraderID(traderID model.TraderID) Option

type Runtime

type Runtime interface {
	Cache() *cache.Cache
	Portfolio() *portfolio.Portfolio
	Clock() Clock
	Logger() *slog.Logger
	SetTimer(context.Context, string, time.Duration) error
	CancelTimer(context.Context, string) error
	OrderFactory(model.AccountID) *model.OrderFactory
	SubscribeMarketData(context.Context, model.SubscribeMarketData) error
	UnsubscribeMarketData(context.Context, model.SubscribeMarketData) error
	SubscribeTicker(context.Context, model.InstrumentID) error
	UnsubscribeTicker(context.Context, model.InstrumentID) error
	SubscribeTradeTicks(context.Context, model.InstrumentID) error
	UnsubscribeTradeTicks(context.Context, model.InstrumentID) error
	SubscribeQuoteTicks(context.Context, model.InstrumentID) error
	UnsubscribeQuoteTicks(context.Context, model.InstrumentID) error
	SubscribeFundingRates(context.Context, model.InstrumentID) error
	UnsubscribeFundingRates(context.Context, model.InstrumentID) error
	SubscribeBars(context.Context, model.BarType) error
	UnsubscribeBars(context.Context, model.BarType) error
	SubscribeOrderBookDepth(context.Context, model.InstrumentID, int) error
	UnsubscribeOrderBookDepth(context.Context, model.InstrumentID, int) error
	RequestData(context.Context, model.DataRequest) (model.DataResponse, error)
	SubmitOrder(context.Context, model.SubmitOrder) (model.OrderStatusReport, error)
	SubmitOrderList(context.Context, model.OrderList) ([]model.OrderStatusReport, error)
	ModifyOrder(context.Context, model.ModifyOrder) (model.OrderStatusReport, error)
	CancelOrder(context.Context, model.CancelOrder) (model.OrderStatusReport, error)
	BatchCancelOrders(context.Context, model.BatchCancelOrders) ([]model.OrderStatusReport, error)
	CancelAllOrders(context.Context, model.CancelAllOrders) ([]model.OrderStatusReport, error)
	QueryOrder(context.Context, model.QueryOrder) (model.OrderStatusReport, error)
	QueryAccount(context.Context, model.QueryAccount) (model.AccountSnapshot, error)
}

type Strategy

type Strategy interface {
	ID() string
	OnStart(context.Context, Runtime) error
	OnEvent(context.Context, bus.Envelope) error
	OnStop(context.Context) error
}

type StrategyConfig

type StrategyConfig struct {
	ID model.StrategyID
}

func (StrategyConfig) Validate

func (c StrategyConfig) Validate() error

type TimerEvent

type TimerEvent struct {
	Name      string
	Timestamp time.Time
}

type TypedStrategy

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

func NewTyped

func NewTyped(id string, handler any) *TypedStrategy

func NewTypedWithConfig

func NewTypedWithConfig(cfg StrategyConfig, handler any) (*TypedStrategy, error)

func (*TypedStrategy) ID

func (s *TypedStrategy) ID() string

func (*TypedStrategy) OnEvent

func (s *TypedStrategy) OnEvent(ctx context.Context, env bus.Envelope) error

func (*TypedStrategy) OnStart

func (s *TypedStrategy) OnStart(ctx context.Context, rt Runtime) error

func (*TypedStrategy) OnStop

func (s *TypedStrategy) OnStop(ctx context.Context) error

type WallClock

type WallClock struct{}

func (WallClock) Now

func (WallClock) Now() time.Time

Jump to

Keyboard shortcuts

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