From f70f39fdde3e30fc8d6dc5eb61a7c4cd34235a7f Mon Sep 17 00:00:00 2001 From: c9s Date: Thu, 20 Jul 2023 18:08:57 +0800 Subject: [PATCH] common/strategy: add google sheet service configuration --- pkg/strategy/common/strategy.go | 30 +++++++++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) diff --git a/pkg/strategy/common/strategy.go b/pkg/strategy/common/strategy.go index 48a57a71f..65fc9dbe6 100644 --- a/pkg/strategy/common/strategy.go +++ b/pkg/strategy/common/strategy.go @@ -88,7 +88,8 @@ func (s *Strategy) Initialize(ctx context.Context, environ *bbgo.Environment, se }) if environ.GoogleSpreadSheetService != nil { - // allocate a google spread sheet for this strategy + // allocate a Google spread sheet for this strategy + s.configureSpreadSheet() } if !s.PositionHardLimit.IsZero() && !s.MaxPositionQuantity.IsZero() { @@ -105,3 +106,30 @@ func (s *Strategy) Initialize(ctx context.Context, environ *bbgo.Environment, se s.ProfitStats) } } + +func (s *Strategy) configureSpreadSheet() error { + sheetSrv := s.Environ.GoogleSpreadSheetService + // allocate a Google spread sheet for this strategy + spreadsheet, err := sheetSrv.Get(true) + if err != nil { + return err + } + + log.Infof("spreadsheet loaded: %+v", spreadsheet) + + profitStatsTitle := "profitStats-" + s.Position.StrategyInstanceID + sheet, err := sheetSrv.LookupOrNewSheet(profitStatsTitle) + if err != nil { + return err + } + + log.Infof("sheet loaded: %+v", sheet) + + column, err := sheetSrv.GetFirstColumn(sheet) + if err != nil { + return err + } + + log.Infof("column: %+v", column) + return nil +}