Documentation ¶
Index ¶
- Constants
- Variables
- func Keys[K comparable, V any](in map[K]V) []K
- func MapKeys[K comparable, V any, R comparable](in map[K]V, iteratee func(value V, key K) R) map[R]V
- func Plot(line *vite.Slice, args ...any)
- func Values[K comparable, V any](in map[K]V) []V
- type LimtStop
- type Options
- type Side
- type Strategy
- func (s *Strategy) AddKline(kline types.KLine)
- func (s *Strategy) CalcAssetValue(price fixedpoint.Value) fixedpoint.Value
- func (s *Strategy) Cancel(id string, direction Side, args ...any)
- func (s *Strategy) CancelAll(id string, direction Side, args ...any)
- func (s *Strategy) CheckLimitStop()
- func (s *Strategy) CheckStopLoss() bool
- func (s *Strategy) Close(args ...any)
- func (s *Strategy) CloseAll(id string, direction Side, args ...any)
- func (s *Strategy) CloseOrder(percentage fixedpoint.Value) error
- func (s *Strategy) ClosePosition(ctx context.Context, percentage fixedpoint.Value) error
- func (s *Strategy) CurrentPosition() *types.Position
- func (s *Strategy) Engine()
- func (s *Strategy) Entry(id string, side Side, data map[string]interface{})
- func (s *Strategy) Exit(tag string) error
- func (s *Strategy) ID() string
- func (s *Strategy) InitEngine()
- func (s *Strategy) InstanceID() string
- func (s *Strategy) OpenOrder(side Side, options *Options)
- func (s *Strategy) Order(id string, direction Side, args ...any)
- func (s *Strategy) Print(f io.Writer, pretty bool, withColor ...bool)
- func (s *Strategy) Rebalance(ctx context.Context)
- func (s *Strategy) RestStopPrice(price float64) fixedpoint.Value
- func (s *Strategy) Run(ctx context.Context, orderExecutor bbgo.OrderExecutor, ...) error
- func (s *Strategy) RunCode(file string, options map[string]interface{}) (goja.Value, error)
- func (s *Strategy) Subscribe(session *bbgo.ExchangeSession)
- func (s *Strategy) UpdateBalance()
Constants ¶
View Source
const ( SideShort = Side("Short") SideLong = Side("Long") )
View Source
const ID = "u8"
Variables ¶
View Source
var Delta fixedpoint.Value = fixedpoint.NewFromFloat(0.01)
View Source
var Fee = 0.0008 // taker fee % * 2, for upper bound
View Source
var Four fixedpoint.Value = fixedpoint.NewFromInt(4)
View Source
var Three fixedpoint.Value = fixedpoint.NewFromInt(3)
View Source
var Two fixedpoint.Value = fixedpoint.NewFromInt(2)
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 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 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) CalcAssetValue ¶
func (s *Strategy) CalcAssetValue(price fixedpoint.Value) fixedpoint.Value
func (*Strategy) CheckStopLoss ¶
func (*Strategy) Close ¶
*strategy.close(id, comment, qty, qty_percent, alert_message, immediately) → void
func (*Strategy) CloseOrder ¶
func (s *Strategy) CloseOrder(percentage fixedpoint.Value) error
func (*Strategy) ClosePosition ¶
func (*Strategy) CurrentPosition ¶
func (*Strategy) InitEngine ¶
func (s *Strategy) InitEngine()
func (*Strategy) InstanceID ¶
func (*Strategy) Rebalance ¶
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) Subscribe ¶
func (s *Strategy) Subscribe(session *bbgo.ExchangeSession)
func (*Strategy) UpdateBalance ¶
func (s *Strategy) UpdateBalance()
Click to show internal directories.
Click to hide internal directories.