mirror of
https://github.com/D-Modem/bbs.git
synced 2026-11-28 17:38:04 -08:00
Merge remote-tracking branch 'origin/main' into claude/project-thread-xg08zu
# Conflicts: # internal/quotes/alpaca.go # internal/quotes/alpaca_test.go
This commit is contained in:
2 files changed
+5
-9
No files matched your search
@@ -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 == "" {
|
||||
|
||||
@@ -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())
|
||||
|
||||
Reference in new issue
Block a user