diff --git a/internal/quotes/alpaca.go b/internal/quotes/alpaca.go index 0c34927..a67cab1 100644 --- a/internal/quotes/alpaca.go +++ b/internal/quotes/alpaca.go @@ -40,9 +40,7 @@ type Alpaca struct { StreamURL string // AlpacaStream if "" (the feed is added) DataURL string // AlpacaData if "" Log func(format string, args ...any) - // Now is the time, by which the session is open or over (nil: - // time.Now; a test's clock) - Now func() time.Time + Now func() time.Time // the clock (time.Now if nil): what session it is, how fresh a snapshot is mu sync.Mutex wanted map[string]time.Time // when each symbol was last wanted @@ -52,7 +50,6 @@ type Alpaca struct { err error // the stream's last failure (nil: connected) } -// now is the time by a's clock. func (a *Alpaca) now() time.Time { if a.Now != nil { return a.Now() @@ -111,7 +108,7 @@ func (a *Alpaca) Err() error { func (a *Alpaca) Want(ctx context.Context, syms []string) { a.mu.Lock() a.init() - now := time.Now() + now := a.now() var fetch []string for _, s := range syms { if s = Normalize(s); s == "" { diff --git a/internal/quotes/alpaca_test.go b/internal/quotes/alpaca_test.go index c28fb92..2b05b0a 100644 --- a/internal/quotes/alpaca_test.go +++ b/internal/quotes/alpaca_test.go @@ -117,13 +117,12 @@ func TestAlpacaSnapshots(t *testing.T) { // TestAlpacaStream: Friday's quote from the snapshot, then Monday's trades // on the stream begin the quote again, with Friday's close the change is -// from. +// from. The clock is Monday 9:33, just after the open, whatever day the +// test runs (later, with no clock tick since, the session would be closed). func TestAlpacaStream(t *testing.T) { srv, subs := fakeAlpaca(t) ws := "ws" + strings.TrimPrefix(srv.URL, "http") + "/v2/" - // Monday before the open, whenever the test is run: the session not - // over, so no close yet - monday := time.Date(2026, 11, 9, 9, 0, 0, 0, eastern) + monday := time.Date(2026, 11, 9, 9, 33, 0, 0, eastern) a := &Alpaca{Key: "KEY", Secret: "SECRET", Book: NewBook(nil), Pinned: []string{"AAPL"}, DataURL: srv.URL + "/v2/", StreamURL: ws, Now: func() time.Time { return monday }} ctx, cancel := context.WithCancel(context.Background())