fix(market): support CoinGecko free Demo API keys#4313
Conversation
|
@guhyun9454 is attempting to deploy a commit to the World Monitor Team on Vercel. A member of the Team first needs to authorize it. |
CoinGecko's free Demo plan and paid Pro plan share the CG- key prefix but require different hosts and auth headers. The code assumed any key was a Pro key and always called pro-api.coingecko.com with x-cg-pro-api-key, so a free Demo key failed with HTTP 400 (error 10011) across all 4 crypto seeders and the server market RPC fetcher. Add an explicit COINGECKO_DEMO_API_KEY env var that routes to api.coingecko.com with x-cg-demo-api-key. Pro takes precedence when both are set, so existing Pro deployments are unaffected; no key still falls back to the public endpoint. Extracted the tier resolution into a shared coingeckoEndpoint() helper (scripts) and a typed local helper (server).
8b5dfda to
4d8f078
Compare
Greptile SummaryThis PR fixes CoinGecko API routing so that free Demo keys (
Confidence Score: 3/5The functional fix is correct and well-tested, but the PR brings along 33+ internal agent state files and a runtime PID file that must be removed before merging — they permanently enter git history if merged as-is. The CoinGecko tier-routing logic is sound and the All files under Important Files Changed
Flowchart%%{init: {'theme': 'neutral'}}%%
flowchart TD
A["coingeckoEndpoint() called"] --> B{COINGECKO_API_KEY set?}
B -- Yes --> C["tier = pro\nbaseUrl = pro-api.coingecko.com/api/v3\nheader: x-cg-pro-api-key"]
B -- No --> D{COINGECKO_DEMO_API_KEY set?}
D -- Yes --> E["tier = demo\nbaseUrl = api.coingecko.com/api/v3\nheader: x-cg-demo-api-key"]
D -- No --> F["tier = keyless\nbaseUrl = api.coingecko.com/api/v3\nno auth header"]
C --> G["fetch /coins/markets"]
E --> G
F --> G
|
Summary
CoinGecko's free Demo plan and paid Pro plan share the
CG-key prefix but require different hosts and auth headers:api.coingecko.com/api/v3x-cg-demo-api-keypro-api.coingecko.com/api/v3x-cg-pro-api-keyThe current code assumes any
COINGECKO_API_KEYis a Pro key and unconditionally callspro-api.coingecko.comwithx-cg-pro-api-key. So a free Demo key fails with HTTP 400 (error_code: 10011— "change your root URL from pro-api.coingecko.com to api.coingecko.com"). Since theCG-prefix is identical, the tier can't be auto-detected from the key string.This affects 5 call sites (4 seeders + the server market RPC fetcher):
scripts/seed-crypto-quotes.mjsscripts/seed-crypto-sectors.mjsscripts/seed-stablecoin-markets.mjsscripts/seed-token-panels.mjsserver/worldmonitor/market/v1/_shared.ts→fetchCoinGeckoMarkets()Fix
Add an explicit
COINGECKO_DEMO_API_KEYenv var that routes toapi.coingecko.comwithx-cg-demo-api-key. Tier resolution is extracted into a sharedcoingeckoEndpoint()helper (scripts/_seed-utils.mjs) and a typed local helper (server_shared.ts):COINGECKO_API_KEYset → Pro (unchanged — existing Pro deployments unaffected)COINGECKO_DEMO_API_KEYset → DemoFully backward compatible — no behavior change for existing Pro or keyless setups.
Type of change
Affected areas
/api/*)Verification
Tested against the live CoinGecko API with a real free Demo key (key redacted in all logs).
1. Tier resolution (unit) — all 4 cases route correctly:
2. Before / after (same free Demo key, one endpoint):
3. Live demo-tier call for the exact query each of the 5 call sites builds (real Demo key):
Checklist
.env.exampleplaceholders are empty)npm run typecheck)biome lintpasses on changed files