linregmaker

package
v1.43.0 Latest Latest
Warning

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

Go to latest
Published: Dec 23, 2022 License: AGPL-3.0 Imports: 11 Imported by: 1

Documentation

Overview

Linregmaker is a maker strategy depends on the linear regression baseline slopes

Linregmaker uses two linear regression baseline slopes for trading: 1) The fast linReg is to determine the short-term trend. It controls whether placing buy/sell orders or not. 2) The slow linReg is to determine the mid-term trend. It controls whether the creation of opposite direction position is allowed.

Index

Constants

View Source
const ID = "linregmaker"

Variables

This section is empty.

Functions

This section is empty.

Types

type Strategy

type Strategy struct {
	// Symbol is the market symbol you want to trade
	Symbol string `json:"symbol"`

	// Leverage uses the account net value to calculate the allowed margin
	Leverage fixedpoint.Value `json:"leverage"`

	types.IntervalWindow

	// ReverseEMA is used to determine the long-term trend.
	// Above the ReverseEMA is the long trend and vise versa.
	// All the opposite trend position will be closed upon the trend change
	ReverseEMA *indicator.EWMA `json:"reverseEMA"`

	// ReverseInterval is the interval to check trend reverse against ReverseEMA. Close price of this interval crossing
	// the ReverseEMA triggers main trend change.
	ReverseInterval types.Interval `json:"reverseInterval"`

	// FastLinReg is to determine the short-term trend.
	// Buy/sell orders are placed if the FastLinReg and the ReverseEMA trend are in the same direction, and only orders
	// that reduce position are placed if the FastLinReg and the ReverseEMA trend are in different directions.
	FastLinReg *indicator.LinReg `json:"fastLinReg"`

	// SlowLinReg is to determine the midterm trend.
	// When the SlowLinReg and the ReverseEMA trend are in different directions, creation of opposite position is
	// allowed.
	SlowLinReg *indicator.LinReg `json:"slowLinReg"`

	// AllowOppositePosition if true, the creation of opposite position is allowed when both fast and slow LinReg are in
	// the opposite direction to main trend
	AllowOppositePosition bool `json:"allowOppositePosition"`

	// FasterDecreaseRatio the quantity of decreasing position orders are multiplied by this ratio when both fast and
	// slow LinReg are in the opposite direction to main trend
	FasterDecreaseRatio fixedpoint.Value `json:"fasterDecreaseRatio,omitempty"`

	// NeutralBollinger is the smaller range of the bollinger band
	// If price is in this band, it usually means the price is oscillating.
	// If price goes out of this band, we tend to not place sell orders or buy orders
	NeutralBollinger types.IntervalWindowBandWidth `json:"neutralBollinger"`

	// TradeInBand
	// When this is on, places orders only when the current price is in the bollinger band.
	TradeInBand bool `json:"tradeInBand"`

	// Spread is the price spread from the middle price.
	// For ask orders, the ask price is ((bestAsk + bestBid) / 2 * (1.0 + spread))
	// For bid orders, the bid price is ((bestAsk + bestBid) / 2 * (1.0 - spread))
	// Spread can be set by percentage or floating number. e.g., 0.1% or 0.001
	Spread fixedpoint.Value `json:"spread"`

	// BidSpread overrides the spread setting, this spread will be used for the buy order
	BidSpread fixedpoint.Value `json:"bidSpread,omitempty"`

	// AskSpread overrides the spread setting, this spread will be used for the sell order
	AskSpread fixedpoint.Value `json:"askSpread,omitempty"`

	// DynamicSpread enables the automatic adjustment to bid and ask spread.
	// Overrides Spread, BidSpread, and AskSpread
	DynamicSpread dynamicrisk.DynamicSpread `json:"dynamicSpread,omitempty"`

	// MaxExposurePosition is the maximum position you can hold
	// 10 means you can hold 10 ETH long/short position by maximum
	MaxExposurePosition fixedpoint.Value `json:"maxExposurePosition"`

	// DynamicExposure is used to define the exposure position range with the given percentage.
	// When DynamicExposure is set, your MaxExposurePosition will be calculated dynamically
	DynamicExposure dynamicrisk.DynamicExposure `json:"dynamicExposure"`

	bbgo.QuantityOrAmount

	// DynamicQuantityIncrease calculates the increase position order quantity dynamically
	DynamicQuantityIncrease dynamicrisk.DynamicQuantitySet `json:"dynamicQuantityIncrease"`

	// DynamicQuantityDecrease calculates the decrease position order quantity dynamically
	DynamicQuantityDecrease dynamicrisk.DynamicQuantitySet `json:"dynamicQuantityDecrease"`

	// UseDynamicQuantityAsAmount calculates amount instead of quantity
	UseDynamicQuantityAsAmount bool `json:"useDynamicQuantityAsAmount"`

	// ExitMethods are various TP/SL methods
	ExitMethods bbgo.ExitMethodSet `json:"exits"`

	// persistence fields
	Position    *types.Position    `persistence:"position"`
	ProfitStats *types.ProfitStats `persistence:"profit_stats"`
	TradeStats  *types.TradeStats  `persistence:"trade_stats"`

	Environment          *bbgo.Environment
	StandardIndicatorSet *bbgo.StandardIndicatorSet
	Market               types.Market

	// StrategyController
	bbgo.StrategyController
	// contains filtered or unexported fields
}

func (*Strategy) ClosePosition

func (s *Strategy) ClosePosition(ctx context.Context, percentage fixedpoint.Value) error

func (*Strategy) CurrentPosition

func (s *Strategy) CurrentPosition() *types.Position

func (*Strategy) ID

func (s *Strategy) ID() string

func (*Strategy) InstanceID

func (s *Strategy) InstanceID() string

func (*Strategy) Run

func (s *Strategy) Run(ctx context.Context, orderExecutor bbgo.OrderExecutor, session *bbgo.ExchangeSession) error

func (*Strategy) Subscribe

func (s *Strategy) Subscribe(session *bbgo.ExchangeSession)

func (*Strategy) Validate

func (s *Strategy) Validate() error

Validate basic config parameters

Jump to

Keyboard shortcuts

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