Merge pull request #899 from c9s/fix/local-timezone

fix: fix localtime zone issue for the web-based backtest report
This commit is contained in:
Yo-An Lin 2022-08-30 00:57:24 +08:00 committed by GitHub
commit 251d1b7095
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 12 additions and 5 deletions

View File

@ -46,6 +46,7 @@ func (s *RoiStopLoss) checkStopPrice(closePrice fixedpoint.Value, position *type
} }
roi := position.ROI(closePrice) roi := position.ROI(closePrice)
// logrus.Debugf("ROIStopLoss: price=%f roi=%s stop=%s", closePrice.Float64(), roi.Percentage(), s.Percentage.Neg().Percentage())
if roi.Compare(s.Percentage.Neg()) < 0 { if roi.Compare(s.Percentage.Neg()) < 0 {
// stop loss // stop loss
Notify("[RoiStopLoss] %s stop loss triggered by ROI %s/%s, price: %f", position.Symbol, roi.Percentage(), s.Percentage.Neg().Percentage(), closePrice.Float64()) Notify("[RoiStopLoss] %s stop loss triggered by ROI %s/%s, price: %f", position.Symbol, roi.Percentage(), s.Percentage.Neg().Percentage(), closePrice.Float64())

View File

@ -148,7 +148,11 @@ var BacktestCmd = &cobra.Command{
endTime = now endTime = now
} }
log.Infof("starting backtest with startTime %s", startTime.Format(time.ANSIC)) // ensure that we're using local time
startTime = startTime.Local()
endTime = endTime.Local()
log.Infof("starting backtest with startTime %s", startTime.Format(time.RFC3339))
environ := bbgo.NewEnvironment() environ := bbgo.NewEnvironment()
if err := BootstrapBacktestEnvironment(ctx, environ); err != nil { if err := BootstrapBacktestEnvironment(ctx, environ); err != nil {
@ -200,6 +204,8 @@ var BacktestCmd = &cobra.Command{
if syncFromTime.After(startTime) { if syncFromTime.After(startTime) {
return fmt.Errorf("sync-from time %s can not be latter than the backtest start time %s", syncFromTime, startTime) return fmt.Errorf("sync-from time %s can not be latter than the backtest start time %s", syncFromTime, startTime)
} }
syncFromTime = syncFromTime.Local()
} else { } else {
// we need at least 1 month backward data for EMA and last prices // we need at least 1 month backward data for EMA and last prices
syncFromTime = startTime.AddDate(0, -1, 0) syncFromTime = startTime.AddDate(0, -1, 0)
@ -208,13 +214,13 @@ var BacktestCmd = &cobra.Command{
if wantSync { if wantSync {
log.Infof("starting synchronization: %v", userConfig.Backtest.Symbols) log.Infof("starting synchronization: %v", userConfig.Backtest.Symbols)
if err := sync(ctx, userConfig, backtestService, sourceExchanges, syncFromTime.Local(), endTime.Local()); err != nil { if err := sync(ctx, userConfig, backtestService, sourceExchanges, syncFromTime, endTime); err != nil {
return err return err
} }
log.Info("synchronization done") log.Info("synchronization done")
if shouldVerify { if shouldVerify {
err := verify(userConfig, backtestService, sourceExchanges, syncFromTime.Local(), endTime.Local()) err := verify(userConfig, backtestService, sourceExchanges, syncFromTime, endTime)
if err != nil { if err != nil {
return err return err
} }

View File

@ -281,8 +281,8 @@ func (o Order) CsvRecords() [][]string {
string(o.Status), string(o.Status),
o.Price.String(), o.Price.String(),
o.Quantity.String(), o.Quantity.String(),
o.CreationTime.Time().Format(time.RFC1123), o.CreationTime.Time().Local().Format(time.RFC1123),
o.UpdateTime.Time().Format(time.RFC1123), o.UpdateTime.Time().Local().Format(time.RFC1123),
o.Tag, o.Tag,
}, },
} }