The CLOB API does not expose 24h volume or order-book liquidity, so the
size_anomaly detector currently has no real ratio to compare a trade
against and falls back to the niche-base 0.2 confidence floor. That makes
the volume_impact / book_impact thresholds essentially dead code.
This change adds a small client for the public gamma-api markets endpoint
and merges its volume24hr / liquidityNum snapshot into MarketMetadata
during the existing periodic sync. The detector can now compute real
volume and book impact ratios.
Notes on the gamma client:
- gamma-api enforces a server-side max of 100 markets per page and caps
`offset` around 10000. The client paginates with bounded concurrency,
sorted by `volume24hr desc`, so the most-traded markets (which is where
size anomalies actually matter) are always covered. Markets beyond that
window have negligible recent volume and the niche path handles them
fine without a ratio.
- Failures are swallowed: a degraded gamma endpoint must not stop CLOB
metadata from being cached, since size_anomaly + the niche path remain
functional with `daily_volume=None`.
MarketMetadata gains three optional Decimal fields (daily_volume,
weekly_volume, liquidity); to_dict / from_dict round-trip is preserved
and older cache entries without these keys deserialize cleanly.
Tests: 12 new tests for GammaClient (parsing, single-page, short-page
stop, offset-cap clean stop, retry, malformed responses); existing
metadata_sync tests updated to inject a mocked GammaClient so they don't
hit the real network.
Co-authored-by: schrodinger01 <schrodinger01@users.noreply.github.com>