trader

package
v0.0.26 Latest Latest
Warning

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

Go to latest
Published: Jun 19, 2022 License: MIT Imports: 4 Imported by: 0

Documentation

Overview

Package trader provides an API for building trading bots. A bot receives prices and execute orders with a broker. Child packages offer specific bot implementations.

Index

Constants

This section is empty.

Variables

View Source
var ErrInvalidConfig = errors.New("invalid bot config")

ErrInvalidConfig is returned by MakeFromConfig.

Functions

This section is empty.

Types

type Bot

type Bot interface {
	// Warmup the indicators used by the bot with historical data prior to active trading.
	// The amount of price data required is typically equivalent to the longest lookback.
	Warmup(context.Context, []market.Kline) error

	// Sets the dealer to be used for order execution.
	SetDealer(broker.Dealer)

	// Sets the asset to trade.
	SetAsset(market.Asset)

	// Receive gives the bot the next market price and evaluates the algo,
	// potentially generating new broker orders.
	market.Receiver

	// Clean-up the bot before close down, e.g. close open positions.
	Close(context.Context) error
}

Bot is the primary interface for a trading algo.

type MakeFromConfig

type MakeFromConfig func(config map[string]any) (Bot, error)

MakeFromConfig is a factory for building a tailored bot from a given config. Used by the optimize package to mint new bots for backtesting.

type Predicter

type Predicter interface {
	market.Receiver

	// Predict gives a confidence score between -1 (short) and +1 (long) that a
	// bot uses to generate buy and sell signals.
	Predict() float64

	// Valid indicates readiness for prediction.
	Valid() bool
}

Predicter is used by a bot to indicate price direction. Child packages provide specific prediction implementations.

type StubBot

type StubBot struct {
}

StubBot is a testing double.

func (*StubBot) Close

func (b *StubBot) Close(ctx context.Context) error

Close not implemented.

func (*StubBot) ReceivePrice

func (b *StubBot) ReceivePrice(ctx context.Context, price market.Kline) error

ReceivePrice not implemented.

func (*StubBot) SetAsset added in v0.0.20

func (b *StubBot) SetAsset(asset market.Asset)

SetAsset not implemented.

func (*StubBot) SetDealer

func (b *StubBot) SetDealer(dealer broker.Dealer)

SetDealer not implemented.

func (*StubBot) Warmup

func (b *StubBot) Warmup(ctx context.Context, prices []market.Kline) error

Warmup not implemented.

Directories

Path Synopsis
Package hodl offers a buy and hold trading algo.
Package hodl offers a buy and hold trading algo.
Package trend offers classic trend following algos.
Package trend offers classic trend following algos.

Jump to

Keyboard shortcuts

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