99 "context"
1010 "os"
1111 "strings"
12+ "time"
1213
1314 "buf.build/go/app/appcmd"
1415 "buf.build/go/app/appext"
@@ -18,6 +19,7 @@ import (
1819 "github.com/bufdev/ibctl/internal/ibctl/ibctlholdings"
1920 "github.com/bufdev/ibctl/internal/ibctl/ibctlmerge"
2021 "github.com/bufdev/ibctl/internal/ibctl/ibctlpath"
22+ "github.com/bufdev/ibctl/internal/ibctl/ibctlrealtime"
2123 "github.com/bufdev/ibctl/internal/ibctl/ibctltaxlot"
2224 "github.com/bufdev/ibctl/internal/pkg/cliio"
2325 "github.com/bufdev/ibctl/internal/pkg/mathpb"
@@ -32,6 +34,8 @@ const (
3234 downloadFlagName = "download"
3335 // baseCurrencyFlagName is the flag name for the base currency for value conversion.
3436 baseCurrencyFlagName = "base-currency"
37+ // realtimeFlagName is the flag name for fetching real-time quotes and FX rates.
38+ realtimeFlagName = "realtime"
3539)
3640
3741// NewCommand returns a new holdings overview command.
@@ -96,6 +100,8 @@ type flags struct {
96100 Download bool
97101 // BaseCurrency is the target currency for value conversion (e.g., "USD", "CAD").
98102 BaseCurrency string
103+ // Realtime fetches real-time quotes and FX rates from Yahoo Finance.
104+ Realtime bool
99105}
100106
101107func newFlags () * flags {
@@ -107,6 +113,7 @@ func (f *flags) Bind(flagSet *pflag.FlagSet) {
107113 flagSet .StringVar (& f .Format , formatFlagName , "table" , "Output format (table, csv, json)" )
108114 flagSet .BoolVar (& f .Download , downloadFlagName , false , "Download fresh data before displaying" )
109115 flagSet .StringVar (& f .BaseCurrency , baseCurrencyFlagName , "USD" , "Base currency for value conversion (e.g., USD, CAD)" )
116+ flagSet .BoolVar (& f .Realtime , realtimeFlagName , false , "Fetch real-time quotes and FX rates from Yahoo Finance" )
110117}
111118
112119func run (ctx context.Context , container appext.Container , flags * flags ) error {
@@ -154,6 +161,13 @@ func run(ctx context.Context, container appext.Container, flags *flags) error {
154161 }
155162 // Load FX rates for base currency conversion.
156163 fxStore := ibctlfxrates .NewStore (ibctlpath .CacheFXDirPath (config .DirPath ))
164+ // Override market prices and FX rates with real-time data from Yahoo Finance.
165+ if flags .Realtime {
166+ todayDate := time .Now ().Format ("2006-01-02" )
167+ if err := ibctlrealtime .ApplyOverrides (ctx , mergedData .Positions , fxStore , config , baseCurrency , todayDate ); err != nil {
168+ return err
169+ }
170+ }
157171 // Compute holdings via FIFO from all trade data, verified against IBKR positions.
158172 result , err := ibctlholdings .GetHoldingsOverview (mergedData .Trades , mergedData .Positions , mergedData .CashPositions , config , fxStore , baseCurrency )
159173 if err != nil {
0 commit comments