From 9666676766bf21364f4fc4d0d1d336e72f2a91b4 Mon Sep 17 00:00:00 2001 From: historia <[not public]> Date: Tue, 6 Oct 2026 12:57:23 -0400 Subject: refactor: split casino.go, dedup helpers, remove audit docs --- internal/cryptomarket/client.go | 44 ++++++++++++++++++++--------------------- 1 file changed, 22 insertions(+), 22 deletions(-) (limited to 'internal/cryptomarket/client.go') diff --git a/internal/cryptomarket/client.go b/internal/cryptomarket/client.go index 4d6d0a8..8445f4a 100644 --- a/internal/cryptomarket/client.go +++ b/internal/cryptomarket/client.go @@ -95,16 +95,16 @@ func (s Snapshot) Expiry(symbol string, expiry int64) (string, bool) { } type Client struct { - HTTP *http.Client - Base string - once sync.Once - gate chan struct{} - cache Snapshot - fetchedAt map[string]time.Time - historyDay int64 - history map[string][]Candle - retryAfter time.Time - lastError error + HTTP *http.Client + Base string + once sync.Once + gate chan struct{} + cache Snapshot + attemptedAt map[string]time.Time + historyDay int64 + history map[string][]Candle + retryAfter time.Time + lastError error } func NewClient() *Client { @@ -179,27 +179,27 @@ func (c *Client) Fetch(ctx context.Context, symbols []string) (Snapshot, error) c.retryAfter = time.Now().Add(15 * time.Second) return result, err } - if c.fetchedAt == nil { - c.fetchedAt = map[string]time.Time{} + if c.attemptedAt == nil { + c.attemptedAt = map[string]time.Time{} } c.cache = c.cache.merge(result) now := time.Now() - for sym := range result.Quotes { - c.fetchedAt[sym] = now + for _, sym := range symbols { + c.attemptedAt[sym] = now } return result, nil } -// fresh reports whether every requested symbol has a recent quote. Each -// symbol ages independently, so another currency's fetch cannot make a stale -// quote look usable. No background work runs: only an explicit interaction -// refreshes anything. +// fresh reports whether every requested symbol has a recent fetch attempt. A +// symbol that was attempted but produced no quote (halted/delisted, or a +// missing/empty ticker) is still considered fresh: without this, every crypto +// command would re-run the full request chain for a permanently-unavailable +// pair. No background work runs: only an explicit interaction refreshes +// anything. func (c *Client) fresh(symbols []string) bool { for _, sym := range symbols { - if _, ok := c.cache.Quotes[sym]; !ok { - return false - } - if at, ok := c.fetchedAt[sym]; !ok || time.Since(at) >= 15*time.Second { + at, ok := c.attemptedAt[sym] + if !ok || time.Since(at) >= 15*time.Second { return false } } -- cgit v1.2.3