From e6ff204a54365bb57b45341860684595b5cc0f9a Mon Sep 17 00:00:00 2001 From: Emil Lerch Date: Wed, 11 Mar 2026 11:26:09 -0700 Subject: [PATCH] Change candle TTL to 23h, 45m for cron jitter/update README --- README.md | 32 ++++++++++++++++---------------- src/cache/store.zig | 4 ++-- 2 files changed, 18 insertions(+), 18 deletions(-) diff --git a/README.md b/README.md index ae5e0af..571d078 100644 --- a/README.md +++ b/README.md @@ -35,7 +35,7 @@ zfin aggregates data from multiple free-tier APIs. Each provider is used for the | Data type | Provider | Auth | Free-tier limit | Cache TTL | |-----------------------|---------------|------------------------|----------------------------|--------------| -| Daily candles (OHLCV) | TwelveData | `TWELVEDATA_API_KEY` | 8 req/min, 800/day | 24 hours | +| Daily candles (OHLCV) | TwelveData | `TWELVEDATA_API_KEY` | 8 req/min, 800/day | 23h45m | | Real-time quotes | TwelveData | `TWELVEDATA_API_KEY` | 8 req/min, 800/day | Never cached | | Dividends | Polygon | `POLYGON_API_KEY` | 5 req/min | 14 days | | Splits | Polygon | `POLYGON_API_KEY` | 5 req/min | 14 days | @@ -75,10 +75,9 @@ zfin aggregates data from multiple free-tier APIs. Each provider is used for the **Used for:** earnings calendar (historical and upcoming). -- Endpoint: `https://finnhub.io/api/v1/calendar/earnings` +- Endpoint: `https://api.finnhub.io/api/v1/calendar/earnings` - Free tier: 60 requests per minute. - Fetches 5 years back and 1 year forward from today. -- Note: Finnhub requires TLS 1.2. Since Zig's HTTP client only supports TLS 1.3, requests to Finnhub automatically fall back to system `curl`. ### Alpha Vantage @@ -123,7 +122,7 @@ Cache files use [SRF](https://github.com/lobo/srf) (Simple Record Format), a lin | Data type | TTL | Rationale | |---------------|--------------|--------------------------------------------------| -| Daily candles | 24 hours | Only changes once per trading day | +| Daily candles | 23h45m | Slightly under 24h for cron jitter tolerance | | Dividends | 14 days | Declared well in advance | | Splits | 14 days | Rare corporate events | | Options | 1 hour | Prices change continuously during market hours | @@ -495,9 +494,7 @@ src/ portfolio.zig Lots, positions, and portfolio aggregation classification.zig Classification metadata parser quote.zig Real-time quote data - ticker_info.zig Security metadata providers/ - provider.zig Type-erased provider interface (vtable) twelvedata.zig TwelveData: candles, quotes polygon.zig Polygon: dividends, splits finnhub.zig Finnhub: earnings @@ -511,13 +508,16 @@ src/ analysis.zig Portfolio analysis engine (breakdowns by class/sector/geo/account/tax) cache/ store.zig SRF file cache with TTL freshness checks - net/ - http.zig HTTP client with retries and TLS 1.2 fallback - rate_limiter.zig Token-bucket rate limiter - cli/ - main.zig CLI entry point and all commands + net/ + http.zig HTTP client with retries and server error retry + rate_limiter.zig Token-bucket rate limiter + commands/ + common.zig Shared CLI helpers (progress, formatting) + perf.zig Trailing returns command + quote.zig Quote command + ... (14 command files) + tui.zig Interactive TUI application tui/ - main.zig Interactive TUI application chart.zig z2d pixel chart renderer (Kitty graphics) keybinds.zig Configurable keybinding system theme.zig Configurable color theme @@ -532,10 +532,10 @@ accounts.srf Account to tax type mapping for analysis ### Dependencies -| Dependency | Source | Purpose | -|----------------------------------------------------|---------------------|--------------------------------------------------| -| [SRF](https://github.com/lobo/srf) | Local (`../../srf`) | Cache file format and portfolio/watchlist parsing | -| [libvaxis](https://github.com/rockorager/libvaxis) | Git (v0.5.1) | Terminal UI rendering | +| Dependency | Source | Purpose | +|----------------------------------------------------|---------------------|---------------------------------------------------| +| [SRF](https://git.lerch.org/lobo/srf) | Git | Cache file format and portfolio/watchlist parsing | +| [libvaxis](https://github.com/rockorager/libvaxis) | Git (v0.5.1) | Terminal UI rendering | ## Building diff --git a/src/cache/store.zig b/src/cache/store.zig index 9311d3d..a50f53c 100644 --- a/src/cache/store.zig +++ b/src/cache/store.zig @@ -21,8 +21,8 @@ pub const Ttl = struct { const s_per_day = std.time.s_per_day; /// Historical candles older than 1 day never expire pub const candles_historical: i64 = -1; // infinite - /// Latest day's candle refreshes every 24h - pub const candles_latest: i64 = s_per_day; + /// Latest day's candle refreshes every 23h45m (15-min buffer for cron jitter) + pub const candles_latest: i64 = s_per_day - 15 * std.time.s_per_min; /// Dividend data refreshes biweekly pub const dividends: i64 = 14 * s_per_day; /// Split data refreshes biweekly