From 8c850c71a2e0e232ce694feb1f58e4013252375d Mon Sep 17 00:00:00 2001 From: c9s Date: Wed, 22 Jun 2022 18:24:34 +0800 Subject: [PATCH] cmd/pnl: add --sync option --- pkg/cmd/pnl.go | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/pkg/cmd/pnl.go b/pkg/cmd/pnl.go index ddebea06a..3474b2b34 100644 --- a/pkg/cmd/pnl.go +++ b/pkg/cmd/pnl.go @@ -21,6 +21,7 @@ func init() { PnLCmd.Flags().StringArray("session", []string{}, "target exchange sessions") PnLCmd.Flags().String("symbol", "", "trading symbol") PnLCmd.Flags().Bool("include-transfer", false, "convert transfer records into trades") + PnLCmd.Flags().Bool("sync", false, "sync before loading trades") PnLCmd.Flags().String("since", "", "query trades from a time point") PnLCmd.Flags().Uint64("limit", 0, "number of trades") RootCmd.AddCommand(PnLCmd) @@ -43,6 +44,11 @@ var PnLCmd = &cobra.Command{ return errors.New("--session [SESSION] is required") } + wantSync, err := cmd.Flags().GetBool("sync") + if err != nil { + return err + } + symbol, err := cmd.Flags().GetString("symbol") if err != nil { return err @@ -96,8 +102,10 @@ var PnLCmd = &cobra.Command{ return fmt.Errorf("session %s not found", sessionName) } - if err := environ.SyncSession(ctx, session, symbol); err != nil { - return err + if wantSync { + if err := environ.SyncSession(ctx, session, symbol); err != nil { + return err + } } if includeTransfer {