fix(indexer): CG/CMC orderbook depth — Openware total-across-book semantics #221
Labels
No labels
agent:fix_bugfix
agent:fix_conflicts
agent:fix_security
agent:gap_analysis
agent:implement
agent:implement
agent:implement
agent:open_issues
agent:ready
agent:research
agent:security_audit
agent:verify
architecture
backend
blocker:hybrid
blocker:launch
blocker:limit-orders
blocker:v2
block:log_only
block:security
bug
ci
contracts
correctness
deploy
dev
devops
docs
documentation
duplicate
e2e
enhancement
epic
feature
frontend
functional-completion
gas
good first issue
governance
help wanted
high-risk
hooks
hybrid
indexer
infra
infrastructure
integrators
invalid
launch-blocker
limit-orders
localnet
localterra
low priority
missing-implementation
needs-design
ops
performance
priority
high
priority
medium
product
qa
QA
question
ready
ready
research
scripts
security
security-hardening
smartcontracts
tech-debt
testing
ux
UX
v2
verification
wontfix
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
code/cl8y-dex-terraclassic#221
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Summary
Align
depthquery parameter semantics on/cg/orderbookand/cmc/orderbook/*with Openware / CoinMarketCap exchange integration wording:depthis total levels across the book, split equally per side (e.g.depth=100→ 50 bids + 50 asks), not Kujira-style “levels per side.”Related: #210, spot-check on Openware CMC spec.
Current codebase
indexer/src/api/cg.rscg_orderbooklet depth = q.depth.unwrap_or(20).min(100);passed to sim → N levels per sideindexer/src/api/cmc.rscmc_orderbookindexer/src/api/orderbook_sim.rswalk_amm_bookfor step in 1..=depth→depthbids anddepthasksindexer/tests/api_orderbook_lcd_mock.rsdepth=50asserts 50 bids and 50 asksdocs/CG_CMC_COMPLIANCE.mdReference (Openware):
depth∈[0,5,10,20,50,100,500]; “Depth = 100 means 50 for each bid/ask side.”Reference (Kujira FIN — different):
depth=200→ 200 per side (Kujira Coingecko API).CL8Y currently implements Kujira-style per-side depth, not Openware total-across-book.
Why this is needed
depth=100⇒ 50+50, not 100+100 (2× expected payload).Constraints and guardrails
levels_per_side = depth / 2(integer floor);depth=1→ document behavior (0 or 1 per side — must not panic)depthquery ≤ 100 (perdocs/indexer-invariants.md); at most 50+50 levels at cap[5,10,20,50,100]or accept any integer 1–100 with computed per-side count — document choicedepth=21→ 10+10 or 11+10 — pick rule, test, documentdepthquery param, not internal per-side countdepthquery — note in changelog for listing teamsRelevant files
indexer/src/api/cg.rs,cmc.rsdepth, compute per-sideindexer/src/api/orderbook_sim.rswalk_amm_book(..., levels_per_side, ...)indexer/tests/api_orderbook_lcd_mock.rsdepth=50→ 25+25)indexer/tests/api_cg.rs,api_cmc.rsdocs/CG_CMC_COMPLIANCE.md,docs/indexer-invariants.mdRecommended direction
fn levels_per_side(requested_depth: usize) -> usizewithmax(1, requested_depth / 2)or stricter Openware mapping.walk_amm_book/ future hybrid merge.depth— total levels across book (split evenly between bids and asks); max 100.”?depth_style=kujira|openwareonly if listing team insists — otherwise one rule for both.Acceptance criteria
depth=100returns at most 50 bids and 50 asks.depth=20returns 10 bids and 10 asks.depth=1defined and tested (no panic).depth=9999still capped at 100 total → 50+50.docs/CG_CMC_COMPLIANCE.mddescribes Openware semantics explicitly.Test plan — functional paths
depth=100depth=50depth=1depthomittedTest plan — attack vectors / abuse
depth=100payload DoSdepthconfusiondepthVerification criteria
levels_per_sidemapping.depth=50(expect half).marked as related to #210
mentioned in issue #210
mentioned in commit
70e4b1a0c2mentioned in commit
de01bd5acdImplementation complete (merged to
main)@brouie — please verify when you have a moment.
Summary
CG/CMC
depthnow follows Openware / CMC exchange integration semantics: the query value is total levels across the book, split evenly per side (levels_per_side = max(1, depth / 2)).Examples:
depth=100(cap) → 50 bids + 50 asks (was 100+100)depth=20(default) → 10 + 10depth=1→ 1 + 1 (no panic)depth=21→ 10+10)Cache keys still use the requested
depthquery param (not per-side count).Code / docs
indexer/src/api/orderbook_sim.rs—cap_orderbook_depth,levels_per_sideindexer/src/api/cg.rs,cmc.rs— handlers use cap + cached simapi_orderbook_lcd_mock.rs,api_cg.rs,api_cmc.rsdocs/CG_CMC_COMPLIANCE.md,docs/indexer-invariants.mdskills/AGENTS_INDEXER_AMM_ORDERBOOK_SIM.mdVerification checklist
GET /cg/orderbook?ticker_id=<pair>&depth=100→ ≤50 bids and ≤50 asksGET /cg/orderbook?...&depth=50→ ≤25 each sideGET /cg/orderbook?...&depth=1→ 1 bid + 1 askdepth→ 10 bids + 10 asks (default total 20)depth=9999capped at 100 total → ≤50 per side/cmc/orderbook/<pair>?depth=15→ 7+7 (floor split)Tests run
Issue left open pending your sign-off.
mentioned in issue #220
mentioned in commit
8b595c89f3Verification complete (agent, 2026-05-30)
Verified GitLab #221 on
main@9f78dcdusing worktreeverify/issue-221(no code delta vsorigin/main). LocalTerra indexer athttp://127.0.0.1:3001left running; no infra restart.Implementation (already on main)
indexer/src/api/orderbook_sim.rs—cap_orderbook_depth,levels_per_side(max(1, depth/2))indexer/src/api/cg.rs,cmc.rs— capped total depth passed to hybrid simdocs/CG_CMC_COMPLIANCE.md§ AMM Orderbook Simulation,docs/indexer-invariants.mdskills/AGENTS_INDEXER_AMM_ORDERBOOK_SIM.md§ Depth query (#221)Tests (worktree)
All #221-scoped tests passed (19 unit + 10 lcd_mock + 2 cg orderbook).
Live checks (
ticker_id=EMBER_CORAL)depth=100depth=50depth=1depth=9999(cap 100)depth=15depth=50Checklist for @brouie (spot-check)
GET /cg/orderbook?ticker_id=<pair>&depth=100→ ≤50 bids, ≤50 asksGET /cg/orderbook?...&depth=50→ ≤25 each sideGET /cg/orderbook?...&depth=1→ 1+1depth→ 10+10depth=9999→ ≤50 per sideGET /cmc/orderbook/<pair>?depth=15→ 7+7All acceptance criteria from the issue body satisfied in this pass — closing.
mentioned in issue #224