u8

package
v0.0.0-...-8d88297 Latest Latest
Warning

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

Go to latest
Published: Mar 21, 2023 License: AGPL-3.0 Imports: 22 Imported by: 1

Documentation

Index

Constants

View Source
const (
	SideShort = Side("Short")
	SideLong  = Side("Long")
)
View Source
const ID = "u8"

Variables

View Source
var Fee = 0.0008 // taker fee % * 2, for upper bound

Functions

func Keys

func Keys[K comparable, V any](in map[K]V) []K

func MapKeys

func MapKeys[K comparable, V any, R comparable](in map[K]V, iteratee func(value V, key K) R) map[R]V

func Plot

func Plot(line *vite.Slice, args ...any)

func Values

func Values[K comparable, V any](in map[K]V) []V

Values creates an array of the map values. Play: https://go.dev/play/p/nnRTQkzQfF6

Types

type LimtStop

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

type Options

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

type Side

type Side string

type Strategy

type Strategy struct {
	Symbol string `json:"symbol"`
	Gvm    *engine.Gvm
	bbgo.OpenPositionOptions
	bbgo.StrategyController
	types.Market
	types.IntervalWindow
	bbgo.SourceSelector

	*bbgo.Environment
	*types.Position    `persistence:"position"`
	*types.ProfitStats `persistence:"profit_stats"`
	*types.TradeStats  `persistence:"trade_stats"`

	MinInterval   types.Interval `json:"minInterval"`                   // minimum interval referred for doing stoploss/trailing exists and updating highest/lowest
	Debug         bool           `json:"debug" modifiable:"true"`       // to print debug message or not
	UseStopLoss   bool           `json:"useStopLoss" modifiable:"true"` // whether to use stoploss rate to do stoploss
	UseHighLow    bool           `json:"useHighLow" modifiable:"true"`  // whether to use stoploss rate to do stoploss
	HighLowWindow int            `json:"highLowWindow"`                 // trendLine is used for rebalancing the position. When trendLine goes up, hold base, otherwise hold quote

	UseAtr    bool `json:"useAtr" modifiable:"true"` // use atr as stoploss
	WindowATR int  `json:"windowATR"`

	StopLoss fixedpoint.Value `json:"stoploss" modifiable:"true"` // stoploss rate

	Price fixedpoint.Value // the midPrice is the average of bestBid and bestAsk in public orderbook

	PredictOffset             int     `json:"predictOffset"`                          // the lookback length for the prediction using linear regression
	HighLowVarianceMultiplier float64 `json:"hlVarianceMultiplier" modifiable:"true"` // modifier to set the limit order price
	NoTrailingStopLoss        bool    `json:"noTrailingStopLoss" modifiable:"true"`   // turn off the trailing exit and stoploss

	HLRangeWindow         int `json:"hlRangeWindow"`         // ma window for kline high/low changes
	SmootherWindow        int `json:"smootherWindow"`        // window that controls the smoothness of drift
	FisherTransformWindow int `json:"fisherTransformWindow"` // fisher transform window to filter drift's negative signals
	ATRWindow             int `json:"atrWindow"`

	// window for atr indicator
	PendingMinInterval int `json:"pendingMinInterval" modifiable:"true"` // if order not be traded for pendingMinInterval of time, cancel it.

	NoRebalance bool `json:"noRebalance" modifiable:"true"` // disable rebalance

	TrendWindow             int       `json:"trendWindow"`                       // trendLine is used for rebalancing the position. When trendLine goes up, hold base, otherwise hold quote
	RebalanceFilter         float64   `json:"rebalanceFilter" modifiable:"true"` // beta filter on the Linear Regression of trendLine
	TrailingCallbackRate    []float64 `json:"trailingCallbackRate" modifiable:"true"`
	TrailingActivationRatio []float64 `json:"trailingActivationRatio" modifiable:"true"`

	ExitMethods bbgo.ExitMethodSet `json:"exits"`
	Session     *bbgo.ExchangeSession
	*bbgo.GeneralOrderExecutor

	LongLeverage  fixedpoint.Value `json:"longLeverage"`
	ShortLeverage fixedpoint.Value `json:"shortLeverage"`
	StopPrice     fixedpoint.Value

	Running          bool
	OpenningBalances fixedpoint.Value `json:"openningBalances"`
	// contains filtered or unexported fields
}

func (*Strategy) AddKline

func (s *Strategy) AddKline(kline types.KLine)

func (*Strategy) CalcAssetValue

func (s *Strategy) CalcAssetValue(price fixedpoint.Value) fixedpoint.Value

func (*Strategy) Cancel

func (s *Strategy) Cancel(id string, direction Side, args ...any)

func (*Strategy) CancelAll

func (s *Strategy) CancelAll(id string, direction Side, args ...any)

* strategy.cancel_all() → void

func (*Strategy) CheckLimitStop

func (s *Strategy) CheckLimitStop()

* 处理止赢止损

func (*Strategy) CheckStopLoss

func (s *Strategy) CheckStopLoss() bool

func (*Strategy) Close

func (s *Strategy) Close(args ...any)

*strategy.close(id, comment, qty, qty_percent, alert_message, immediately) → void

func (*Strategy) CloseAll

func (s *Strategy) CloseAll(id string, direction Side, args ...any)

func (*Strategy) CloseOrder

func (s *Strategy) CloseOrder(percentage fixedpoint.Value) error

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) Engine

func (s *Strategy) Engine()

func (*Strategy) Entry

func (s *Strategy) Entry(id string, side Side, data map[string]interface{})

func (*Strategy) Exit

func (s *Strategy) Exit(tag string) error

func (*Strategy) ID

func (s *Strategy) ID() string

func (*Strategy) InitEngine

func (s *Strategy) InitEngine()

func (*Strategy) InstanceID

func (s *Strategy) InstanceID() string

func (*Strategy) OpenOrder

func (s *Strategy) OpenOrder(side Side, options *Options)

多单处理

func (*Strategy) Order

func (s *Strategy) Order(id string, direction Side, args ...any)

func (*Strategy) Print

func (s *Strategy) Print(f io.Writer, pretty bool, withColor ...bool)

func (*Strategy) Rebalance

func (s *Strategy) Rebalance(ctx context.Context)

Sending new rebalance orders cost too much. Modify the position instead to expect the strategy itself rebalance on Close

func (*Strategy) RestStopPrice

func (s *Strategy) RestStopPrice(price float64) fixedpoint.Value

func (*Strategy) Run

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

func (*Strategy) RunCode

func (s *Strategy) RunCode(file string, options map[string]interface{}) (goja.Value, error)

func (*Strategy) Subscribe

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

func (*Strategy) UpdateBalance

func (s *Strategy) UpdateBalance()

Jump to

Keyboard shortcuts

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