trader

package
v0.0.0-...-ab5ca81 Latest Latest
Warning

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

Go to latest
Published: Dec 17, 2023 License: MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type CandleSubscriber

type CandleSubscriber interface {
	OnCandle(candle ohlc.OHLC)
}

type Option

type Option func(*Trader)

func WithBroker

func WithBroker(broker broker.Broker) Option

func WithCandleSubscription

func WithCandleSubscription(subscriber CandleSubscriber) Option

func WithCurrencyCode

func WithCurrencyCode(currencyCode string) Option

func WithFeedStoredCandles

func WithFeedStoredCandles(strategy strategy.Strategy) Option

func WithPersistCandleData

func WithPersistCandleData(persist bool) Option

func WithPersistTickData

func WithPersistTickData(persist bool) Option

func WithPositionSubscription

func WithPositionSubscription(subscriber PositionSubscriber) Option

func WithStrategy

func WithStrategy(strategy strategy.Strategy) Option

type OrderSubscriber

type OrderSubscriber interface {
	OnOrder(order broker.Order)
}

type PerformanceRecord

type PerformanceRecord struct {
	gorm.Model
	BacktestingID              string
	StrategyName               string
	Strategy                   string
	Instrument                 string
	CandleDuration             time.Duration
	TargetInPips               float64
	StopLossInPips             float64
	PerformanceTrigger         float64
	TotalPerformanceInPips     float64
	AVGPerformanceInPips       float64
	MaxAggregateDrawdownInPips float64
	MaxLossInPips              float64
	MaxLossInPercent           float64
	MaxWinInPercent            float64
	MaxWinInPips               float64
	TradesWinRationInPercent   float64
	Trades                     int
	TradesWin                  int
	TradesLoss                 int
	TradesLossLong             int
	TradesLossShort            int
	TradesLong                 int
	TradesShort                int
	MaxConsecutiveTradesLoss   uint
	MaxConcurrentPositions     int
	GitRev                     string
	Duration                   string
	FirstTrade                 time.Time
	LastTrade                  time.Time
	AVGTradeDurationInSeconds  float64
	TotalExposureInPercent     float64
	ChartHTML                  string
	BacktestingConfigJSON      string
	ClosedPositions            []broker.Position `gorm:"-"`
	TotalTimeInMarket          time.Duration
	AVGTimeInMarket            time.Duration
}

type PositionSubscriber

type PositionSubscriber interface {
	OnPosition(position broker.Position)
}

type Trader

type Trader struct {
	StartTime  time.Time
	Instrument string
	TickChan   chan tick.Tick

	MaxAggregatedDrawdownInPips decimal.Decimal

	sync.Mutex
	// contains filtered or unexported fields
}

func New

func New(ctx context.Context, instrument, gitRev string, db *gorm.DB, options ...Option) *Trader

func (*Trader) GetClosedPositions

func (tr *Trader) GetClosedPositions() ([]broker.Position, error)

func (*Trader) GetPerformanceRecord

func (tr *Trader) GetPerformanceRecord(chartHTML string) (*PerformanceRecord, error)

func (*Trader) GetPerformanceRecordByID

func (tr *Trader) GetPerformanceRecordByID(backtestingID string) (PerformanceRecord, error)

func (*Trader) GetPerformanceRecords

func (tr *Trader) GetPerformanceRecords() ([]PerformanceRecord, error)

func (*Trader) ID

func (tr *Trader) ID() string

func (*Trader) SavePerformanceRecord

func (tr *Trader) SavePerformanceRecord(chartHTML string) error

func (*Trader) Start

func (tr *Trader) Start() error

func (*Trader) Stop

func (tr *Trader) Stop() error

func (*Trader) Summary

func (tr *Trader) Summary()

Jump to

Keyboard shortcuts

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