Skip to content

glacez-soa-findata

Lane: backend · Repo: glacez/glacez-soa-findata · Editing rules: Glacez/SOAs/glacez-soa-findata/AGENTS.md

The platform's single source of market and reference data. Every other service reads prices, currencies, news and indicators through this one — nobody calls a venue or a price provider directly.

Responsibility

  • OHLCV candles and currency metadata (rank, start date, tags) — the venue's candle is authoritative for every field of an instrument it serves; CoinMarketCap fills only what no venue can serve
  • daily OHLCV history, derived on read or on revision (EUR/USD/BTC/ETH quotes with ratio-derived cross rates)
  • market metrics, fear & greed, halving events
  • news ingestion and retention
  • derived indicators: ATHs, changes, moving averages

It does not own: exchange connectivity for trading (worker), the user-facing API (webservice), portfolio math (portfolio).

Data it writes

Currency, Ohlcv, MarketMetrics, FearAndGreed, HalvingEvent, News (collection news_articles), ExternalApiKey. One ohlcv collection serves both full-series and close-only reads, and every row declares which kind it is: Ohlcv.Type.DAILY for a candle stamped at UTC midnight, Ohlcv.Type.CURRENT for the run covering the day in progress — "latest" means the CURRENT rows, never a timestamp shape. A DAILY row is one complete, closed day from the venue that served it: the day in progress only ever lives in its CURRENT row, so low ≤ open/close ≤ high holds on every daily candle and no row is a snapshot stub. The row carries the indexes its reads need: {_id.instrument, _id.timestamp} for a symbol's series, {_id.timestamp, _id.instrument} for a day's book, and a partial {type, _id.instrument} over the CURRENT rows only, so a latest read touches one key per instrument instead of the whole collection.

A currency's full create / update / delete chain — including the synchronous price fetch on create, the OHLCV rewrite on a symbol rename and the halving cascade on delete — is in Currency lifecycle.

External providers

Provider Supplies
CoinMarketCap close prices for instruments no venue serves, currency metadata, fear & greed, market metrics
CoinDesk Data API news only (keys of type CRYPTOCOMPARE, retention default 6 months)
Gate.io → Binance → KuCoin → Kraken daily candles, one USD candle per instrument per day, venues tried in that order — except the USD stablecoins, which route to Kraken first
European Central Bank (frankfurter) EUR/USD and EUR/CHF reference rates — the cross rate of every derived quote, and the fiat instruments' own close

CoinMarketCap is not a venue. It answers one bulk call for every currency with a single close — no open/high/low, no volume, no historical series — while the Venue contract is per-instrument with a pair catalogue and a book, so wrapping it would mean a hidden bulk cache behind supports() and a fabricated range. What it is good for is the reverse seam: if a second close provider arrives, the fallback belongs behind a bulk CloseSources injected as a list, not inside the snapshot and not in the venue router.

Provider credentials are Mongo documents (ExternalApiKey), never config, and a key is picked at random per call. A quote whose cross rate is missing is left out, never zeroed. A venue's silence is data, not an error. An empty candle response means "no data for this window" — a frozen or delisted pair still answers 200 with zero rows — so it moves the symbol to the next venue rather than raising a failure, and the other shape of the same answer (400 INVALID_CURRENCY_PAIR) means the venue does not list it at all. A pair catalogue is asked before a per-symbol call and is necessary but not sufficient: a venue can list a pair it serves no rows for. A replacement provider is judged on the call volume measured in prod first (185 currencies × 1/min plus the revision windows), then on limits read from its response headers, never from its pricing page.

A close for one instant is the venue first, the stored row second (get-in-timestamp): the venue's daily candle for the day containing the timestamp, then that day's stored DAILY close when the venue cannot serve it (a pair it no longer lists, a rate-limited call, a series older than its history). The order is not interchangeable — a trade booked today has no stored daily row yet, and the venue does have today's day. Both empty is a warning naming the instrument and the day.

One record describes one book: a venue-served instrument takes all five fields and all four quotes from that venue's candle, and a CoinMarketCap close is never filled into it — mixing the two is what made a stored close disagree with its own open/high/low by up to 1.3 %. An instrument no source priced keeps its previous row. Fiat (USD, EUR, CHF) are priced flat from the ECB reference series — open = high = low = close, because a reference rate is a single daily number: no venue lists an EUR/USD pair and CoinMarketCap does not quote fiat, so neither price source can supply them. Pegged wrappers (WETH, WBTC) are the mirror case: no venue lists them either, but their value is their underlying's at 1:1 — the peg is the wrap, not a market rate — so their candle is that underlying's own candle re-keyed onto the wrapper, same range, same four quotes, same volume, with no ratio applied. Neither source is asked for them, and a wrapper whose underlying is unpriced that day keeps its previous row.

The USD stablecoins are ordinary instruments, not a pegged special case: USDC, USDT and RLUSD each trade a USD pair on a venue we already consume, so they carry a real open/high/low/close and a real volume like anything else, from the book above rather than from parity. USDT itself is priced from the same Kraken series the drift is loaded from, so the instrument and the multiplier can never disagree. A candle quoted in USDT (most of Gate's) is converted to true USD by that drift before the four quotes are derived; a candle quoted in a stablecoin we hold no rate for stays unpriced instead of being read at parity.

Surface

Feign contracts in api/ ({Domain}Resource), versioned root /v2 — the only service whose clients carry a path version. Full OHLCV, close-only, indicators, currencies, fear & greed, market metrics, news, external API keys.

Downstream: nothing. findata is a leaf, and that is why it can be scaled and restarted without caring about order.

Jobs

Nine bodyless POST endpoints under /v2/jobs: seven snapshot/* (daily + latest for OHLCV, fear & greed and market metrics, plus latest-news) and two revise/* (daily-ohlcv, daily-ohlcv-random).

The service schedules nothing — ScheduleConfig only drives cache eviction. The triggers live in glacez-infra-cron, and ctlq deliberately runs a much quieter file:

Job ctlq prod
snapshot/latest-ohlcv every 10 min every minute
snapshot/daily-ohlcv daily 00:01 daily 00:01
revise/daily-ohlcv commented out 01:33 and 19:33
revise/daily-ohlcv-random commented out every odd hour 03–23
snapshot/latest-fear-and-greed daily 12:30 every 21 min
snapshot/latest-news Wednesdays every 2 h every 2 h

The revision and the snapshot share one per-IP budget, and the snapshot has a single point of failure. Its ETH_USDT cross candle decides the ETH quote of every record, so a revision burst that eats the venue's rate limit marks the whole minute invalid (121 currencies had no valid close price from the feed) while the venue line still reports a healthy served={…}, and the revision itself recovers on the retry. Cadence is only half the answer — a shared cross-rate fetch has to be cached or prioritised, not left to compete.

Revision only fills: an existing value is replaced only when it is non-positive or carries a lower scale. A provider cutover therefore changes new candles only — an unchanged historical series afterwards is correct, not a bug.

The single exception is the rewrite, used by the daily job for the day that just closed: the same closed day, with every quote taken from the venue's candle as it is. Fill-only cannot repair a stitched row (positive values, some carrying more decimals than the candle), which is why the repair is an explicit pass rather than a heuristic — the one-off year-long backfill of that shape was the updater's leg, and it ran (Updaters). A year costs one request per instrument, the same as a day — the venue is asked with limit = days + 2, and the revision crons already fetch 300 and 500 days per instrument. The daily snapshot rewrites the day that just closed (replaces the row, never fills it), so in every environment — ctlq included, where both revise crons are commented out — a daily candle is complete and consistent the day after it closes, even when the deploy landed mid-day.