Skip to content

feat: add 1h and 1d lowest available price candles#12

Draft
us-oyster wants to merge 4 commits into
dimthink:mainfrom
us-oyster:agent/product-price-candles
Draft

feat: add 1h and 1d lowest available price candles#12
us-oyster wants to merge 4 commits into
dimthink:mainfrom
us-oyster:agent/product-price-candles

Conversation

@us-oyster

@us-oyster us-oyster commented Jul 21, 2026

Copy link
Copy Markdown

Summary

Adds end-to-end 1-hour and 1-day OHLC price candles for canonical products. PriceAI now records the lowest eligible purchasable price every 15 minutes, serves cached public chart APIs, renders compact candles on /channels, and renders an interactive detail chart on /products/[id].

Price definition

  • Lowest CNY offer that is visible, positive-priced, fresh, available, in stock or low stock, unexpired, and has a purchase URL.
  • Includes only offers with no bulk restriction or min_order_quantity <= 1.
  • Requires two consecutive valid confirmations at the same canonical product and price.
  • Excludes shared_access, web_only_account, and domestic_mirror_site.
  • Uses deterministic updated-time and offer-ID tie-breaking.
  • This is an observed public asking price, not an actual transaction price.

Data model

  • Adds idempotent 15-minute product_price_samples.
  • Adds product_price_candles for 1h and Asia/Shanghai calendar-day 1d OHLC.
  • Extends raw-offer confirmations with canonical product and valid-confirmation streak tracking.
  • Reaggregates affected candles from samples, so delayed sampling preserves correct open/close ordering.
  • Keeps samples for 180 days, hourly candles for 365 days, and daily candles without automatic expiry.
  • Retention defaults to dry-run and only removes samples whose hourly and daily aggregates exist.
  • Tables, internal view, and maintenance RPCs remain service_role only.

UI

  • /channels: one global 1小时 / 1天 switch and one batch request for all matching products, with lightweight SVG candles on desktop and mobile.
  • /products/[id]: dynamically imports lightweight-charts@5.2.0 after mount and supports crosshair, touch/mouse interaction, zoom, drag, reset, and OHLC/sample tooltips.
  • Covers loading, retry, no-history, accumulating-data, and current-price-missing states.
  • Uses red for up, green for down, gray for flat, plus explicit signed text and a fixed non-transaction disclaimer.

Performance

  • Summary reads use two batched RPCs for all filtered products; there is no database or HTTP N+1.
  • Both public APIs use the existing Cloudflare edge cache policy with a 300-second TTL and complete query-parameter cache keys.
  • The channels view uses custom SVG and does not load the charting library.
  • The full chart library is client-only and dynamically imported on product detail pages.

Validation

  • npm run test:price-history
  • npm run test:price-history-db (Docker PostgreSQL with the real schema.sql)
  • npm run test:price-history-api
  • npm run lint (one pre-existing warning)
  • npm run typecheck
  • npm test
  • npm run check:performance
  • npm run check:recovery-baseline
  • node scripts/verify-supabase-recovery-baseline.mjs --docker
  • npm run audit:licenses
  • npm run build
  • npm run build:cloudflare

Database coverage includes eligibility filters, two confirmations, multi/single-sample OHLC, delayed and duplicate sampling, product/currency isolation, gaps, Asia/Shanghai day boundaries, historical reads without a current quote, and protected retention.

Screenshots

Validated with deterministic local fixtures. No production data is included.

Channels desktop - 1-day candles

channels-desktop-1d-viewport

Channels mobile - 1-hour candles

channels-mobile-1h

Product detail desktop - 1-day chart and tooltip

product-desktop-1d-tooltip

Product detail mobile - 1-hour chart and tooltip

product-mobile-1h-tooltip

Additional states validated locally: no-history and current-price-missing.

Limitations

  • CNY only.
  • No historical backfill; candles begin accumulating after deployment.
  • Supports only 1h and 1d.
  • No transaction volume, executed-price claim, or prediction.
  • Does not bypass login walls, CAPTCHA, WAF, or other collection restrictions.

Rollout

  1. Apply 20260720220000_product_price_history.sql.
  2. Deploy the application.
  3. Manually trigger one action=sample run and verify samples/candles/API output.
  4. Enable the 15-minute sampling workflow and daily retention step.

Rollback should stop the scheduled jobs first and roll back the application. Keep the new history tables in place; no destructive down migration is required.

@us-oyster
us-oyster force-pushed the agent/product-price-candles branch from 12d08e6 to c63c9c4 Compare July 21, 2026 07:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant