fix: ensure that orders.tsv are rendered in local timezone

This commit is contained in:
c9s 2022-08-26 19:06:52 +08:00
parent f17249ba89
commit 179a9b1ddb
No known key found for this signature in database
GPG Key ID: 7385E7E464CB0A54
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)
// 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())

View File

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

View File

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