From 40d44078dc8e7b41aafcb37539fedb55d03e4f6a Mon Sep 17 00:00:00 2001 From: c9s Date: Sat, 4 Jun 2022 00:14:13 +0800 Subject: [PATCH] explain ID and strategy struct --- doc/topics/developing-strategy.md | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/doc/topics/developing-strategy.md b/doc/topics/developing-strategy.md index 4fe89b086..c28f590a1 100644 --- a/doc/topics/developing-strategy.md +++ b/doc/topics/developing-strategy.md @@ -41,12 +41,32 @@ To use the Symbol setting, you can get the value from the Run method of the stra ``` func (s *Strategy) Run(ctx context.Context, session *bbgo.ExchangeSession) error { + // you need to import the "log" package log.Println("%s", s.Symbol) return nil } ``` +Now you have the Go struct and the Go package, but BBGO does not know your strategy, +so you need to register your strategy. +Define an ID const in your package: + +``` +const ID = "short" +``` + +Then call bbgo.RegisterStrategy with the ID you just defined and a struct reference: + +``` +func init() { + bbgo.RegisterStrategy(ID, &Strategy{}) +} +``` + +Note that you don't need to fill the fields in the struct, BBGO just need to know the type of struct. + +(BBGO use reflect to parse the fields from the given struct and allocate a new struct object from the given struct type internally) ## Built-in Strategy