From 179a9b1ddbcc41116ef1d6736e5eec503be2a19c Mon Sep 17 00:00:00 2001 From: c9s Date: Fri, 26 Aug 2022 19:06:52 +0800 Subject: [PATCH] fix: ensure that orders.tsv are rendered in local timezone --- pkg/bbgo/exit_roi_stop_loss.go | 1 + pkg/cmd/backtest.go | 12 +++++++++--- pkg/types/order.go | 4 ++-- 3 files changed, 12 insertions(+), 5 deletions(-) diff --git a/pkg/bbgo/exit_roi_stop_loss.go b/pkg/bbgo/exit_roi_stop_loss.go index 4dab15a1c..606002218 100644 --- a/pkg/bbgo/exit_roi_stop_loss.go +++ b/pkg/bbgo/exit_roi_stop_loss.go @@ -46,6 +46,7 @@ func (s *RoiStopLoss) checkStopPrice(closePrice fixedpoint.Value, position *type } 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 { // stop loss Notify("[RoiStopLoss] %s stop loss triggered by ROI %s/%s, price: %f", position.Symbol, roi.Percentage(), s.Percentage.Neg().Percentage(), closePrice.Float64()) diff --git a/pkg/cmd/backtest.go b/pkg/cmd/backtest.go index 4ad019106..3183f8a1a 100644 --- a/pkg/cmd/backtest.go +++ b/pkg/cmd/backtest.go @@ -148,7 +148,11 @@ var BacktestCmd = &cobra.Command{ 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() if err := BootstrapBacktestEnvironment(ctx, environ); err != nil { @@ -200,6 +204,8 @@ var BacktestCmd = &cobra.Command{ if syncFromTime.After(startTime) { return fmt.Errorf("sync-from time %s can not be latter than the backtest start time %s", syncFromTime, startTime) } + + syncFromTime = syncFromTime.Local() } else { // we need at least 1 month backward data for EMA and last prices syncFromTime = startTime.AddDate(0, -1, 0) @@ -208,13 +214,13 @@ var BacktestCmd = &cobra.Command{ if wantSync { 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 } log.Info("synchronization done") if shouldVerify { - err := verify(userConfig, backtestService, sourceExchanges, syncFromTime.Local(), endTime.Local()) + err := verify(userConfig, backtestService, sourceExchanges, syncFromTime, endTime) if err != nil { return err } diff --git a/pkg/types/order.go b/pkg/types/order.go index 97587f9e1..b206ace82 100644 --- a/pkg/types/order.go +++ b/pkg/types/order.go @@ -281,8 +281,8 @@ func (o Order) CsvRecords() [][]string { string(o.Status), o.Price.String(), o.Quantity.String(), - o.CreationTime.Time().Format(time.RFC1123), - o.UpdateTime.Time().Format(time.RFC1123), + o.CreationTime.Time().Local().Format(time.RFC1123), + o.UpdateTime.Time().Local().Format(time.RFC1123), o.Tag, }, }