cmd/pnl: add --sync option

This commit is contained in:
c9s 2022-06-22 18:24:34 +08:00
parent fa7177426f
commit 8c850c71a2
No known key found for this signature in database
GPG Key ID: 7385E7E464CB0A54

View File

@ -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,9 +102,11 @@ var PnLCmd = &cobra.Command{
return fmt.Errorf("session %s not found", sessionName)
}
if wantSync {
if err := environ.SyncSession(ctx, session, symbol); err != nil {
return err
}
}
if includeTransfer {
exchange := session.Exchange