common/strategy: add google sheet service configuration

This commit is contained in:
c9s 2023-07-20 18:08:57 +08:00
parent eb9b3563da
commit f70f39fdde
No known key found for this signature in database
GPG Key ID: 7385E7E464CB0A54

View File

@ -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
}