@pencil-agent/nano-pencil 2.0.1 → 2.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (188) hide show
  1. package/README.md +267 -267
  2. package/dist/build-meta.json +3 -3
  3. package/dist/core/export-html/AGENT.md +11 -11
  4. package/dist/core/export-html/template.css +971 -971
  5. package/dist/core/export-html/template.html +54 -54
  6. package/dist/core/model/custom-providers.js +1 -1
  7. package/dist/core/model-registry.js +5 -5
  8. package/dist/extensions/builtin/AGENT.md +115 -115
  9. package/dist/extensions/builtin/browser/AGENT.md +17 -17
  10. package/dist/extensions/builtin/browser/agent-workspace/agent_helpers.py +12 -12
  11. package/dist/extensions/builtin/browser/agent-workspace/domain-skills/amazon/product-search.md +198 -198
  12. package/dist/extensions/builtin/browser/agent-workspace/domain-skills/archive-org/scraping.md +341 -341
  13. package/dist/extensions/builtin/browser/agent-workspace/domain-skills/arxiv/scraping.md +311 -311
  14. package/dist/extensions/builtin/browser/agent-workspace/domain-skills/arxiv-bulk/scraping.md +333 -333
  15. package/dist/extensions/builtin/browser/agent-workspace/domain-skills/atlas/overview.md +70 -70
  16. package/dist/extensions/builtin/browser/agent-workspace/domain-skills/booking-com/scraping.md +578 -578
  17. package/dist/extensions/builtin/browser/agent-workspace/domain-skills/capterra/scraping.md +440 -440
  18. package/dist/extensions/builtin/browser/agent-workspace/domain-skills/centilebrain/generate-estimates.md +110 -110
  19. package/dist/extensions/builtin/browser/agent-workspace/domain-skills/coingecko/scraping.md +325 -325
  20. package/dist/extensions/builtin/browser/agent-workspace/domain-skills/coinmarketcap/scraping.md +463 -463
  21. package/dist/extensions/builtin/browser/agent-workspace/domain-skills/coursera/scraping.md +360 -360
  22. package/dist/extensions/builtin/browser/agent-workspace/domain-skills/craigslist/scraping.md +390 -390
  23. package/dist/extensions/builtin/browser/agent-workspace/domain-skills/crossref/scraping.md +568 -568
  24. package/dist/extensions/builtin/browser/agent-workspace/domain-skills/dev-to/scraping.md +323 -323
  25. package/dist/extensions/builtin/browser/agent-workspace/domain-skills/duckduckgo/scraping.md +349 -349
  26. package/dist/extensions/builtin/browser/agent-workspace/domain-skills/ebay/scraping.md +435 -435
  27. package/dist/extensions/builtin/browser/agent-workspace/domain-skills/etsy/scraping.md +506 -506
  28. package/dist/extensions/builtin/browser/agent-workspace/domain-skills/eventbrite/scraping.md +363 -363
  29. package/dist/extensions/builtin/browser/agent-workspace/domain-skills/expedia/automation.md +168 -168
  30. package/dist/extensions/builtin/browser/agent-workspace/domain-skills/facebook/groups.md +236 -236
  31. package/dist/extensions/builtin/browser/agent-workspace/domain-skills/facebook/pages.md +295 -295
  32. package/dist/extensions/builtin/browser/agent-workspace/domain-skills/framer/editor.md +108 -108
  33. package/dist/extensions/builtin/browser/agent-workspace/domain-skills/fred/scraping.md +493 -493
  34. package/dist/extensions/builtin/browser/agent-workspace/domain-skills/g2/scraping.md +580 -580
  35. package/dist/extensions/builtin/browser/agent-workspace/domain-skills/genius/scraping.md +511 -511
  36. package/dist/extensions/builtin/browser/agent-workspace/domain-skills/github/repo-actions.md +65 -65
  37. package/dist/extensions/builtin/browser/agent-workspace/domain-skills/github/scraping.md +184 -184
  38. package/dist/extensions/builtin/browser/agent-workspace/domain-skills/glassdoor/scraping.md +543 -543
  39. package/dist/extensions/builtin/browser/agent-workspace/domain-skills/gmail/compose.md +122 -122
  40. package/dist/extensions/builtin/browser/agent-workspace/domain-skills/goodreads/scraping.md +461 -461
  41. package/dist/extensions/builtin/browser/agent-workspace/domain-skills/gutenberg/scraping.md +383 -383
  42. package/dist/extensions/builtin/browser/agent-workspace/domain-skills/hackernews/scraping.md +243 -243
  43. package/dist/extensions/builtin/browser/agent-workspace/domain-skills/howlongtobeat/scraping.md +473 -473
  44. package/dist/extensions/builtin/browser/agent-workspace/domain-skills/imdb/scraping.md +271 -271
  45. package/dist/extensions/builtin/browser/agent-workspace/domain-skills/itch-io/scraping.md +436 -436
  46. package/dist/extensions/builtin/browser/agent-workspace/domain-skills/job-boards/indeed-glassdoor.md +1021 -1021
  47. package/dist/extensions/builtin/browser/agent-workspace/domain-skills/letterboxd/scraping.md +349 -349
  48. package/dist/extensions/builtin/browser/agent-workspace/domain-skills/linkedin/invitation-manager.md +109 -109
  49. package/dist/extensions/builtin/browser/agent-workspace/domain-skills/loom/folder-enumeration.md +170 -170
  50. package/dist/extensions/builtin/browser/agent-workspace/domain-skills/macrotrends/scraping.md +537 -537
  51. package/dist/extensions/builtin/browser/agent-workspace/domain-skills/medium/article-hydration.md +120 -120
  52. package/dist/extensions/builtin/browser/agent-workspace/domain-skills/medium/scraping.md +414 -414
  53. package/dist/extensions/builtin/browser/agent-workspace/domain-skills/metacritic/scraping.md +477 -477
  54. package/dist/extensions/builtin/browser/agent-workspace/domain-skills/musicbrainz/scraping.md +478 -478
  55. package/dist/extensions/builtin/browser/agent-workspace/domain-skills/nasa/scraping.md +339 -339
  56. package/dist/extensions/builtin/browser/agent-workspace/domain-skills/news-aggregation/multi-source.md +205 -205
  57. package/dist/extensions/builtin/browser/agent-workspace/domain-skills/open-library/scraping.md +472 -472
  58. package/dist/extensions/builtin/browser/agent-workspace/domain-skills/openalex/scraping.md +470 -470
  59. package/dist/extensions/builtin/browser/agent-workspace/domain-skills/openstreetmap/scraping.md +490 -490
  60. package/dist/extensions/builtin/browser/agent-workspace/domain-skills/package-registries/npm-pypi.md +478 -478
  61. package/dist/extensions/builtin/browser/agent-workspace/domain-skills/polymarket/scraping.md +234 -234
  62. package/dist/extensions/builtin/browser/agent-workspace/domain-skills/producthunt/scraping.md +307 -307
  63. package/dist/extensions/builtin/browser/agent-workspace/domain-skills/pubmed/scraping.md +421 -421
  64. package/dist/extensions/builtin/browser/agent-workspace/domain-skills/quora/scraping.md +364 -364
  65. package/dist/extensions/builtin/browser/agent-workspace/domain-skills/rawg/scraping.md +352 -352
  66. package/dist/extensions/builtin/browser/agent-workspace/domain-skills/reddit/scraping.md +124 -124
  67. package/dist/extensions/builtin/browser/agent-workspace/domain-skills/rest-countries/scraping.md +233 -233
  68. package/dist/extensions/builtin/browser/agent-workspace/domain-skills/sec-edgar/scraping.md +361 -361
  69. package/dist/extensions/builtin/browser/agent-workspace/domain-skills/shopify-admin/README.md +36 -36
  70. package/dist/extensions/builtin/browser/agent-workspace/domain-skills/shopify-admin/embedded-apps.md +72 -72
  71. package/dist/extensions/builtin/browser/agent-workspace/domain-skills/shopify-admin/knowledge-base.md +109 -109
  72. package/dist/extensions/builtin/browser/agent-workspace/domain-skills/shopify-admin/polaris-inputs.md +137 -137
  73. package/dist/extensions/builtin/browser/agent-workspace/domain-skills/soundcloud/scraping.md +362 -362
  74. package/dist/extensions/builtin/browser/agent-workspace/domain-skills/spotify/scraping.md +339 -339
  75. package/dist/extensions/builtin/browser/agent-workspace/domain-skills/stackoverflow/scraping.md +435 -435
  76. package/dist/extensions/builtin/browser/agent-workspace/domain-skills/steam/scraping.md +575 -575
  77. package/dist/extensions/builtin/browser/agent-workspace/domain-skills/substack/scraping.md +338 -338
  78. package/dist/extensions/builtin/browser/agent-workspace/domain-skills/thetechgeeks/pricing.md +52 -52
  79. package/dist/extensions/builtin/browser/agent-workspace/domain-skills/tiktok/upload.md +107 -107
  80. package/dist/extensions/builtin/browser/agent-workspace/domain-skills/tradingview/scraping.md +309 -309
  81. package/dist/extensions/builtin/browser/agent-workspace/domain-skills/trello/boards-and-lists.md +88 -88
  82. package/dist/extensions/builtin/browser/agent-workspace/domain-skills/trustpilot/scraping.md +375 -375
  83. package/dist/extensions/builtin/browser/agent-workspace/domain-skills/walmart/scraping.md +444 -444
  84. package/dist/extensions/builtin/browser/agent-workspace/domain-skills/wayback-machine/scraping.md +306 -306
  85. package/dist/extensions/builtin/browser/agent-workspace/domain-skills/weather/scraping.md +398 -398
  86. package/dist/extensions/builtin/browser/agent-workspace/domain-skills/wellfound/scraping.md +596 -596
  87. package/dist/extensions/builtin/browser/agent-workspace/domain-skills/world-bank/scraping.md +356 -356
  88. package/dist/extensions/builtin/browser/agent-workspace/domain-skills/xiaohongshu/scraping.md +84 -84
  89. package/dist/extensions/builtin/browser/agent-workspace/domain-skills/youtube/scraping.md +418 -418
  90. package/dist/extensions/builtin/browser/agent-workspace/domain-skills/zillow/scraping.md +433 -433
  91. package/dist/extensions/builtin/browser/browser.md +73 -73
  92. package/dist/extensions/builtin/browser/install.md +142 -142
  93. package/dist/extensions/builtin/browser/interaction-skills/connection.md +48 -48
  94. package/dist/extensions/builtin/browser/interaction-skills/cookies.md +3 -3
  95. package/dist/extensions/builtin/browser/interaction-skills/cross-origin-iframes.md +3 -3
  96. package/dist/extensions/builtin/browser/interaction-skills/dialogs.md +64 -64
  97. package/dist/extensions/builtin/browser/interaction-skills/downloads.md +3 -3
  98. package/dist/extensions/builtin/browser/interaction-skills/drag-and-drop.md +3 -3
  99. package/dist/extensions/builtin/browser/interaction-skills/dropdowns.md +3 -3
  100. package/dist/extensions/builtin/browser/interaction-skills/iframes.md +3 -3
  101. package/dist/extensions/builtin/browser/interaction-skills/network-requests.md +3 -3
  102. package/dist/extensions/builtin/browser/interaction-skills/print-as-pdf.md +3 -3
  103. package/dist/extensions/builtin/browser/interaction-skills/profile-sync.md +90 -90
  104. package/dist/extensions/builtin/browser/interaction-skills/screenshots.md +17 -17
  105. package/dist/extensions/builtin/browser/interaction-skills/scrolling.md +3 -3
  106. package/dist/extensions/builtin/browser/interaction-skills/shadow-dom.md +3 -3
  107. package/dist/extensions/builtin/browser/interaction-skills/tabs.md +69 -69
  108. package/dist/extensions/builtin/browser/interaction-skills/uploads.md +1 -1
  109. package/dist/extensions/builtin/browser/interaction-skills/viewport.md +3 -3
  110. package/dist/extensions/builtin/browser/src/browser_harness/AGENT.md +15 -15
  111. package/dist/extensions/builtin/browser/src/browser_harness/__init__.py +8 -8
  112. package/dist/extensions/builtin/browser/src/browser_harness/_ipc.py +90 -90
  113. package/dist/extensions/builtin/browser/src/browser_harness/admin.py +722 -722
  114. package/dist/extensions/builtin/browser/src/browser_harness/daemon.py +328 -328
  115. package/dist/extensions/builtin/browser/src/browser_harness/helpers.py +396 -396
  116. package/dist/extensions/builtin/browser/src/browser_harness/run.py +103 -103
  117. package/dist/extensions/builtin/debug/index.js +9 -9
  118. package/dist/extensions/builtin/discipline/skills/brainstorming/SKILL.md +33 -33
  119. package/dist/extensions/builtin/discipline/skills/executing-plans/SKILL.md +25 -25
  120. package/dist/extensions/builtin/discipline/skills/finishing-development-branch/SKILL.md +25 -25
  121. package/dist/extensions/builtin/discipline/skills/receiving-code-review/SKILL.md +22 -22
  122. package/dist/extensions/builtin/discipline/skills/requesting-code-review/SKILL.md +31 -31
  123. package/dist/extensions/builtin/discipline/skills/systematic-debugging/SKILL.md +28 -28
  124. package/dist/extensions/builtin/discipline/skills/test-driven-development/SKILL.md +32 -32
  125. package/dist/extensions/builtin/discipline/skills/using-git-worktrees/SKILL.md +25 -25
  126. package/dist/extensions/builtin/discipline/skills/verification-before-completion/SKILL.md +27 -27
  127. package/dist/extensions/builtin/discipline/skills/writing-plans/SKILL.md +26 -26
  128. package/dist/extensions/builtin/goal/README.md +67 -67
  129. package/dist/extensions/builtin/goal/index.js +6 -6
  130. package/dist/extensions/builtin/grub/README.md +112 -112
  131. package/dist/extensions/builtin/link-world/agent-workspace/README.md +16 -16
  132. package/dist/extensions/builtin/link-world/internet-search/internet-search.md +65 -65
  133. package/dist/extensions/builtin/link-world/link-world-agent.md +82 -82
  134. package/dist/extensions/builtin/link-world/linkworld.md +313 -313
  135. package/dist/extensions/builtin/link-world/network-routing/network-routing.md +67 -67
  136. package/dist/extensions/builtin/loop/README.md +92 -92
  137. package/dist/extensions/builtin/mcp/figma-design.md +68 -68
  138. package/dist/extensions/builtin/mcp/mcp-management.md +85 -85
  139. package/dist/extensions/builtin/recap/AGENT.md +15 -15
  140. package/dist/extensions/builtin/sal/README.md +72 -72
  141. package/dist/extensions/builtin/security-audit/README.md +289 -289
  142. package/dist/extensions/builtin/team/AGENT.md +112 -112
  143. package/dist/extensions/builtin/team/TESTING.md +299 -299
  144. package/dist/extensions/builtin/token-save/README.md +56 -56
  145. package/dist/extensions/optional/AGENT.md +10 -10
  146. package/dist/modes/interactive/controllers/input-submit-controller.js +2 -2
  147. package/dist/modes/interactive/controllers/stream-render-controller.js +2 -2
  148. package/dist/modes/interactive/interactive-mode.js +19 -19
  149. package/dist/modes/interactive/theme/dark.json +85 -85
  150. package/dist/modes/interactive/theme/light.json +84 -84
  151. package/dist/modes/interactive/theme/theme-schema.json +335 -335
  152. package/dist/modes/interactive/theme/warm.json +81 -81
  153. package/dist/node_modules/@pencil-agent/ai/dist/cli.js +0 -0
  154. package/dist/node_modules/@pencil-agent/ai/dist/models.generated.js +1 -1
  155. package/docs/ACP/345/215/217/350/256/256/351/233/206/346/210/220/345/274/200/345/217/221/346/226/207/346/241/243.md +851 -0
  156. package/docs/SDK-TESTING.md +364 -0
  157. package/docs/codex-goal-command-impl.md +1055 -1055
  158. package/docs/codex-goal-vs-grub.md +500 -500
  159. package/docs/custom-provider.md +27 -27
  160. package/docs/extensions.md +27 -27
  161. package/docs/keybindings.md +27 -27
  162. package/docs/loop /351/207/215/346/236/204/345/256/214/346/210/220/346/200/273/347/273/223.md" +250 -250
  163. package/docs/loop /351/207/215/346/236/204/345/256/214/346/210/220/346/212/245/345/221/212.md" +122 -122
  164. package/docs/loop /351/207/215/346/236/204/346/226/271/346/241/210.md" +1222 -1222
  165. package/docs/loop /351/207/215/346/236/204/346/226/271/346/241/210/345/256/236/347/216/260/346/212/245/345/221/212.md" +158 -158
  166. package/docs/loop /351/207/215/346/236/204/346/226/271/346/241/210/345/257/271/346/257/224/345/210/206/346/236/220.md" +128 -128
  167. package/docs/loop /351/207/215/346/236/204/350/256/241/345/210/222.md" +320 -320
  168. package/docs/loop-usage-examples.md +214 -214
  169. package/docs/mem-core/346/212/200/346/234/257/346/226/207/346/241/243.md +593 -0
  170. package/docs/models.md +27 -27
  171. package/docs/packages.md +27 -27
  172. package/docs/pi-design-philosophy.md +457 -457
  173. package/docs/planmode.md +1987 -1987
  174. package/docs/prompt-templates.md +27 -27
  175. package/docs/providers.md +27 -27
  176. package/docs/sdk.md +27 -27
  177. package/docs/skills.md +27 -27
  178. package/docs/startup-performance-optimization.md +301 -0
  179. package/docs/themes.md +27 -27
  180. package/docs/tui.md +27 -27
  181. package/docs//350/256/244/347/237/245/345/234/260/345/233/276.md +47 -0
  182. package/package.json +190 -190
  183. package/docs/cc-agent-design.md +0 -1297
  184. package/docs/cc-tui-design.md +0 -1333
  185. package/docs/nanoPencil-/345/255/246/344/271/240/350/256/241/345/210/222.md +0 -170
  186. package/docs/scan-report.md +0 -3820
  187. package/docs//345/257/271/346/240/207Claude-Code.md +0 -1775
  188. package/docs//351/230/277/351/207/214/345/267/264/345/267/264/350/264/242/346/212/245/345/210/206/346/236/220/344/271/246.md +0 -261
@@ -1,463 +1,463 @@
1
- # CoinMarketCap — Data Extraction
2
-
3
- `https://coinmarketcap.com` — crypto market data. Three access paths tested: internal JSON API (fastest, no auth required), `__NEXT_DATA__` from HTML pages, and browser DOM. All real-money price data confirmed accurate against displayed UI values.
4
-
5
- ## Do this first: pick your access path
6
-
7
- | Goal | Best approach | Latency |
8
- |------|--------------|---------|
9
- | Top N coins by market cap | Internal listing API | ~200ms |
10
- | Single coin price/stats/ATH | Internal detail API | ~100ms |
11
- | Global market metrics | Internal global-metrics API | ~65ms |
12
- | All coins on homepage (101 items) | `__NEXT_DATA__` main page | ~700ms |
13
- | Coin detail + full stats | `__NEXT_DATA__` currency page | ~700ms |
14
- | Historical OHLCV | Internal historical API | ~160ms |
15
- | Exchange pairs for a coin | Internal market-pairs API | ~200ms |
16
- | News/articles | Internal content API | ~220ms |
17
-
18
- **Never use the browser for read-only CMC tasks.** The internal API at `api.coinmarketcap.com` is accessible with no API key, no special headers, no auth — plain `http_get` works.
19
-
20
- **Do NOT use `pro-api.coinmarketcap.com`** — that is the paid API requiring a key.
21
-
22
- ---
23
-
24
- ## Path 1: Internal listing API (fastest for ranked coins)
25
-
26
- Returns CMC-ranked coins with full price data in one call. No auth needed.
27
-
28
- ```python
29
- import json
30
-
31
- resp = json.loads(http_get(
32
- "https://api.coinmarketcap.com/data-api/v3/cryptocurrency/listing"
33
- "?start=1&limit=100&sortBy=market_cap&sortType=desc&convert=USD"
34
- ))
35
-
36
- coins = resp['data']['cryptoCurrencyList'] # list of coin objects
37
- total_available = resp['data']['totalCount'] # 8374 as of 2026-04-18
38
-
39
- for c in coins:
40
- usd = next(q for q in c['quotes'] if q['name'] == 'USD')
41
- print(
42
- f"#{c['cmcRank']} {c['symbol']}: "
43
- f"${usd['price']:,.2f} | "
44
- f"MCap ${usd['marketCap']/1e9:.1f}B | "
45
- f"Vol24h ${usd['volume24h']/1e9:.1f}B | "
46
- f"24h {usd['percentChange24h']:+.2f}% | "
47
- f"CS {c['circulatingSupply']:,.0f}"
48
- )
49
- ```
50
-
51
- ### Coin object fields
52
-
53
- Top-level (`c` in the loop above):
54
- ```
55
- id, name, symbol, slug, cmcRank, marketPairCount,
56
- circulatingSupply, selfReportedCirculatingSupply,
57
- totalSupply, maxSupply, isActive, lastUpdated, dateAdded,
58
- quotes, isAudited, auditInfoList, badges
59
- ```
60
-
61
- Per-quote fields (inside `c['quotes']`, filtered by `name == 'USD'`):
62
- ```
63
- name, price, volume24h, volumePercentChange, marketCap,
64
- percentChange1h, percentChange24h, percentChange7d,
65
- percentChange30d, percentChange60d, percentChange90d,
66
- percentChange1y, ytdPriceChangePercentage,
67
- fullyDilluttedMarketCap, marketCapByTotalSupply,
68
- dominance, turnover, lastUpdated
69
- ```
70
-
71
- ### Query parameters
72
-
73
- ```python
74
- # Pagination
75
- "?start=1&limit=100" # page 1 of 100
76
- "?start=101&limit=100" # page 2
77
-
78
- # Sort
79
- "sortBy=market_cap" # default
80
- "sortBy=volume_24h"
81
- "sortBy=percent_change_24h"
82
- "sortBy=price"
83
- "sortBy=circulating_supply"
84
- "sortType=desc" # or asc
85
-
86
- # Currency conversion (affects quote prices returned)
87
- "convert=USD" # USD prices
88
- "convert=BTC" # BTC-denominated
89
-
90
- # Filter by type
91
- "cryptoType=all" # default — coins + tokens
92
- "cryptoType=coins" # layer-1s only (633 results)
93
- "cryptoType=tokens" # ERC-20 etc.
94
-
95
- # Filter by tag (DeFi, NFT, etc.)
96
- "tagSlugs=defi" # 2698 results
97
- "tagSlugs=nft"
98
- ```
99
-
100
- ---
101
-
102
- ## Path 2: Internal detail API (single coin, full stats)
103
-
104
- Best for fetching one coin's complete data including ATH, ATL, 52-week high/low, volume ranks.
105
-
106
- ```python
107
- import json
108
-
109
- # Look up by CMC coin ID (BTC=1, ETH=1027, XRP=52, SOL=5426, BNB=1839)
110
- resp = json.loads(http_get(
111
- "https://api.coinmarketcap.com/data-api/v3/cryptocurrency/detail?id=1"
112
- ))
113
- data = resp['data']
114
- s = data['statistics']
115
-
116
- print(f"Price: ${s['price']:,.2f}")
117
- print(f"Rank: #{s['rank']}")
118
- print(f"Market Cap: ${s['marketCap']:,.0f}")
119
- print(f"Volume 24h: ${s['volume24h']:,.0f}")
120
- print(f"Circulating Supply:{s['circulatingSupply']:,.0f}")
121
- print(f"Total Supply: {s['totalSupply']:,.0f}")
122
- print(f"Max Supply: {s['maxSupply']:,.0f}")
123
- print(f"24h Change: {s['priceChangePercentage24h']:+.2f}%")
124
- print(f"7d Change: {s['priceChangePercentage7d']:+.2f}%")
125
- print(f"ATH: ${s['highAllTime']:,.2f} on {s['highAllTimeTimestamp']}")
126
- print(f"ATL: ${s['lowAllTime']:,.4f} on {s['lowAllTimeTimestamp']}")
127
- print(f"52w High: ${s['high52w']:,.2f}")
128
- print(f"52w Low: ${s['low52w']:,.2f}")
129
- print(f"MCap Dominance: {s['marketCapDominance']:.2f}%")
130
- ```
131
-
132
- ### All statistics fields
133
-
134
- ```
135
- price, priceChangePercentage1h, priceChangePercentage24h,
136
- priceChangePercentage7d, priceChangePercentage30d,
137
- priceChangePercentage60d, priceChangePercentage90d,
138
- priceChangePercentage1y, priceChangePercentageAll,
139
- marketCap, marketCapChangePercentage24h,
140
- fullyDilutedMarketCap, mintedMarketCap,
141
- circulatingSupply, totalSupply, maxSupply,
142
- marketCapDominance, rank, roi,
143
- low24h, high24h, low7d, high7d, low30d, high30d,
144
- low52w, high52w, low90d, high90d,
145
- lowAllTime, highAllTime,
146
- lowAllTimeChangePercentage, highAllTimeChangePercentage,
147
- lowAllTimeTimestamp, highAllTimeTimestamp,
148
- lowYesterday, highYesterday, openYesterday, closeYesterday,
149
- priceChangePercentageYesterday, volumeYesterday,
150
- ytdPriceChangePercentage, volumeRank, volumeMcRank,
151
- volume24h, volume24hReported, volume7d, volume7d Reported,
152
- volume30d, volume30dReported, turnover
153
- ```
154
-
155
- ### Top-level data fields (beyond statistics)
156
-
157
- ```
158
- id, name, symbol, slug, category, description, dateAdded,
159
- volume, volumeChangePercentage24h, cexVolume, dexVolume,
160
- urls (website, explorer, twitter, reddit, etc.),
161
- tags, platforms, relatedCoins, wallets,
162
- holders, watchCount, watchListRanking
163
- ```
164
-
165
- ---
166
-
167
- ## Path 3: Global market metrics
168
-
169
- ```python
170
- import json
171
-
172
- resp = json.loads(http_get(
173
- "https://api.coinmarketcap.com/data-api/v3/global-metrics/quotes/latest"
174
- ))
175
- data = resp['data']
176
- q = data['quotes'][0] # USD quote (cryptoId=2781)
177
-
178
- print(f"Total Market Cap: ${q['totalMarketCap']/1e12:.2f}T")
179
- print(f"Total Volume 24h: ${q['totalVolume24H']/1e9:.1f}B")
180
- print(f"Altcoin MCap: ${q['altcoinMarketCap']/1e12:.2f}T")
181
- print(f"DeFi MCap: ${q['defiMarketCap']/1e9:.1f}B")
182
- print(f"DeFi Vol 24h: ${q['defiVolume24H']/1e9:.1f}B")
183
- print(f"Stablecoin MCap: ${q['stablecoinMarketCap']/1e9:.1f}B")
184
- print(f"Derivatives Vol: ${q['derivativesVolume24H']/1e9:.1f}B")
185
- print(f"BTC Dominance: {data['btcDominance']:.2f}%")
186
- print(f"ETH Dominance: {data['ethDominance']:.2f}%")
187
- print(f"Active Cryptos: {data['activeCryptoCurrencies']}")
188
- print(f"Total Cryptos: {data['totalCryptoCurrencies']}")
189
- print(f"Active Exchanges: {data['activeExchanges']}")
190
- print(f"Active Pairs: {data['activeMarketPairs']}")
191
-
192
- # Yesterday comparison
193
- print(f"\nMCap Yesterday: ${q['totalMarketCapYesterday']/1e12:.2f}T")
194
- print(f"MCap Change: {q['totalMarketCapYesterdayPercentageChange']:+.2f}%")
195
- ```
196
-
197
- ---
198
-
199
- ## Path 4: Historical OHLCV (candlestick data)
200
-
201
- ```python
202
- import json, time
203
-
204
- now = int(time.time())
205
-
206
- # Daily candles for BTC over last 7 days
207
- resp = json.loads(http_get(
208
- "https://api.coinmarketcap.com/data-api/v3/cryptocurrency/historical"
209
- f"?id=1&convertId=2781&timeStart={now - 7*86400}&timeEnd={now}&interval=daily"
210
- ))
211
- candles = resp['data']['quotes'] # list of OHLCV dicts
212
-
213
- for candle in candles:
214
- q = candle['quote']
215
- print(
216
- f"{candle['timeOpen'][:10]} "
217
- f"O={q['open']:,.0f} H={q['high']:,.0f} "
218
- f"L={q['low']:,.0f} C={q['close']:,.0f} "
219
- f"V=${q['volume']/1e9:.1f}B MCap=${q['marketCap']/1e12:.2f}T"
220
- )
221
- ```
222
-
223
- Candle quote fields: `open, high, low, close, volume, marketCap, circulatingSupply, timestamp`
224
-
225
- Supported intervals: `daily`, `1h` (hourly). `5m` returns HTTP 500 — not supported.
226
-
227
- `convertId=2781` = USD. `timeStart`/`timeEnd` are Unix timestamps.
228
-
229
- ---
230
-
231
- ## Path 5: Exchange market pairs for a coin
232
-
233
- ```python
234
- import json
235
-
236
- resp = json.loads(http_get(
237
- "https://api.coinmarketcap.com/data-api/v3/cryptocurrency/market-pairs/latest"
238
- "?id=1&start=1&limit=10&sort=volume"
239
- ))
240
- data = resp['data']
241
- print(f"Total pairs for {data['name']}: {data['numMarketPairs']}")
242
-
243
- for pair in data['marketPairs']:
244
- print(
245
- f" {pair['exchangeName']:20} {pair['marketPair']:12} "
246
- f"${pair['price']:,.2f} Vol=${pair['volumeUsd']/1e6:.1f}M"
247
- )
248
- ```
249
-
250
- Pair fields: `rank, exchangeId, exchangeName, exchangeSlug, marketId, marketPair, category (spot/futures), baseSymbol, quoteSymbol, baseCurrencyId, quoteCurrencyId, price, volumeUsd, effectiveLiquidity, lastUpdated, volumeBase, volumeQuote, depthUsdNegativeTwo, depthUsdPositiveTwo, feeType, isVerified, type (cex/dex)`
251
-
252
- ---
253
-
254
- ## Path 6: Exchange listings
255
-
256
- ```python
257
- import json
258
-
259
- resp = json.loads(http_get(
260
- "https://api.coinmarketcap.com/data-api/v3/exchange/listing"
261
- "?start=1&limit=20&sortBy=score&sortType=desc"
262
- ))
263
- exchanges = resp['data']['exchanges']
264
- for ex in exchanges:
265
- print(f" {ex['name']:30} score={ex.get('score')} trafficScore={ex.get('trafficScore')}")
266
- ```
267
-
268
- Exchange fields: `id, name, slug, dexStatus, platformId, status, score, trafficScore, countries, fiats, filteredTotalVol24h`
269
-
270
- ---
271
-
272
- ## Path 7: Price conversion (cross-rate)
273
-
274
- ```python
275
- import json
276
-
277
- # Convert 1 BTC → USD
278
- resp = json.loads(http_get(
279
- "https://api.coinmarketcap.com/data-api/v3/tools/price-conversion"
280
- "?amount=1&id=1&convert_id=2781"
281
- ))
282
- result = resp['data']
283
- usd_price = result['quote'][0]['price']
284
- print(f"1 {result['symbol']} = ${usd_price:,.2f} USD")
285
-
286
- # Convert ETH → BTC
287
- resp2 = json.loads(http_get(
288
- "https://api.coinmarketcap.com/data-api/v3/tools/price-conversion"
289
- "?amount=1&id=1027&convert_id=1"
290
- ))
291
- btc_price = resp2['data']['quote'][0]['price']
292
- print(f"1 ETH = {btc_price:.6f} BTC")
293
- ```
294
-
295
- `id` = source coin CMC ID, `convert_id` = target currency CMC ID (2781=USD, 1=BTC, 1027=ETH, 825=USDT)
296
-
297
- ---
298
-
299
- ## Path 8: News / articles
300
-
301
- ```python
302
- import json
303
-
304
- # News for a specific coin
305
- resp = json.loads(http_get(
306
- "https://api.coinmarketcap.com/content/v3/news?coins=1&limit=10"
307
- ))
308
- for article in resp['data']:
309
- meta = article['meta']
310
- print(f" [{meta['sourceName']}] {meta['title']}")
311
- print(f" {article['createdAt'][:10]} — {meta['sourceUrl']}")
312
- ```
313
-
314
- Article fields: `slug, cover, assets, createdAt` + nested `meta` with `title, subtitle, sourceName, sourceUrl, language, type, status, id, createdAt, updatedAt, releasedAt`
315
-
316
- Omit `coins=` param for general crypto news. Supports `limit` up to observed 50+ without errors.
317
-
318
- ---
319
-
320
- ## Path 9: __NEXT_DATA__ from HTML pages
321
-
322
- Use when you need data that isn't in the API (e.g. Fear & Greed index, CMC100 index, trending categories).
323
-
324
- ### Main page (`coinmarketcap.com/`)
325
-
326
- ```python
327
- import json, re
328
-
329
- html = http_get("https://coinmarketcap.com/")
330
- m = re.search(r'<script id="__NEXT_DATA__"[^>]+>([\s\S]*?)</script>', html)
331
- nd = json.loads(m.group(1))
332
- props = nd['props']
333
-
334
- # Global market metrics (same data as global-metrics API, faster from HTML)
335
- gm = props['pageProps']['globalMetrics']
336
- print(f"Total cryptos: {gm['numCryptocurrencies']}")
337
- print(f"BTC dominance: {gm['btcDominance']:.2f}%")
338
- print(f"Total MCap: ${gm['marketCap']/1e12:.2f}T")
339
- print(f"Total Vol 24h: ${gm['totalVol']/1e9:.1f}B")
340
-
341
- # Spot prices for BTC/ETH/USD/SATS/BITS (the "ticker bar" data)
342
- # props['quotesLatestData'] — 5 items with short field names
343
- for q in props['quotesLatestData']:
344
- print(f" {q['symbol']}: p={q['p']} p24h={q['p24h']:+.3f}%")
345
- # fields: id, symbol, p (price), p1h, p24h, p7d, p30d, p60d, p90d, pytd, t
346
-
347
- # Top 101 coins with full USD quotes — from dehydratedState
348
- queries = props['dehydratedState']['queries']
349
- homepage_q = next(q for q in queries if q['queryKey'] == ['homepage-data', 1, 100])
350
- listing = homepage_q['state']['data']['data']['listing']
351
- coins = listing['cryptoCurrencyList'] # 101 coins
352
- total = listing['totalCount']
353
-
354
- for c in coins:
355
- if c['symbol'] == 'BTC':
356
- usd = next(q for q in c['quotes'] if q['name'] == 'USD')
357
- print(f"BTC: #{c['cmcRank']} ${usd['price']:,.2f}")
358
- break
359
-
360
- # Page-level shared data (Fear & Greed index, CMC20, altcoin index)
361
- psd = props['pageProps']['pageSharedData']
362
- print("pageSharedData keys:", list(psd.keys()))
363
- # keys: topCategories, fearGreedIndexData, cmc100, cmc20, faqData, altcoinIndex, halvingInfo, deviceInfo
364
- ```
365
-
366
- **Gotcha — regex pattern**: Use `[^>]+` to match the `crossorigin="anonymous"` attribute on the script tag. `type="application/json"` alone will miss it:
367
- ```python
368
- # CORRECT
369
- m = re.search(r'<script id="__NEXT_DATA__"[^>]+>([\s\S]*?)</script>', html)
370
-
371
- # WRONG — returns None because of crossorigin attr
372
- m = re.search(r'<script id="__NEXT_DATA__" type="application/json">(.*?)</script>', html, re.DOTALL)
373
- ```
374
-
375
- **`quotesLatestData` has only 5 entries** (SATS, BITS, BTC, ETH, USD) — it's the currency selector bar, not the full market ranking. For the full ranked listing use `dehydratedState`.
376
-
377
- **`cmcRank` is at coin top level**, not inside the USD quote object. The `cmcRank` field inside the quote dict is `None`.
378
-
379
- ### Individual coin page (`/currencies/{slug}/`)
380
-
381
- ```python
382
- import json, re
383
-
384
- html = http_get("https://coinmarketcap.com/currencies/bitcoin/")
385
- m = re.search(r'<script id="__NEXT_DATA__"[^>]+>([\s\S]*?)</script>', html)
386
- nd = json.loads(m.group(1))
387
-
388
- # All stats under props.pageProps.detailRes.detail.statistics
389
- stats = nd['props']['pageProps']['detailRes']['detail']['statistics']
390
-
391
- print(f"Price: ${stats['price']:,.2f}")
392
- print(f"Rank: #{stats['rank']}")
393
- print(f"MCap: ${stats['marketCap']:,.0f}")
394
- print(f"Vol 24h: ${stats['volume24h']:,.0f}")
395
- print(f"Circ Sup: {stats['circulatingSupply']:,.0f}")
396
- print(f"24h: {stats['priceChangePercentage24h']:+.2f}%")
397
- print(f"ATH: ${stats['highAllTime']:,.2f} ({stats['highAllTimeTimestamp']})")
398
- print(f"ATL: ${stats['lowAllTime']:.4f}")
399
- ```
400
-
401
- `detailRes.detail` also contains: `name, symbol, slug, description, tags, urls (website/explorer/twitter/reddit), platforms, relatedCoins, holders, watchCount`
402
-
403
- **Note**: The currency page has no JSON-LD blocks — zero `<script type="application/ld+json">` elements.
404
-
405
- ---
406
-
407
- ## Common coin IDs
408
-
409
- | ID | Symbol | Name |
410
- |----|--------|------|
411
- | 1 | BTC | Bitcoin |
412
- | 1027 | ETH | Ethereum |
413
- | 52 | XRP | XRP |
414
- | 825 | USDT | Tether |
415
- | 1839 | BNB | BNB |
416
- | 3408 | USDC | USD Coin |
417
- | 5426 | SOL | Solana |
418
- | 74 | DOGE | Dogecoin |
419
- | 2781 | USD | US Dollar (for convert_id) |
420
-
421
- Find IDs from the listing API: `c['id']` or from the detail API URL by looking up a slug first via the listing API's `c['slug']` field.
422
-
423
- ---
424
-
425
- ## Anti-bot / rate limits
426
-
427
- **Main site (`coinmarketcap.com`):**
428
- - `http_get` works with the default `Mozilla/5.0` UA — no Cloudflare, no bot detection triggered.
429
- - Page loads are ~700ms for 690–710KB of HTML+`__NEXT_DATA__`.
430
-
431
- **Internal API (`api.coinmarketcap.com`):**
432
- - No auth headers required. No `X-Request-Id` or `X-Forwarded-For` needed.
433
- - 25 rapid sequential calls with zero rate limiting or errors — no throttle observed at that volume.
434
- - Typical latency: 65–250ms per call.
435
- - `error_code: '0'` and `error_message: 'SUCCESS'` in every response; no `credit_count` consumed.
436
-
437
- **v2 API (`api.coinmarketcap.com/v2/`):**
438
- - Returns HTTP 401 Unauthorized — requires API key. Do not use.
439
-
440
- **Pro API (`pro-api.coinmarketcap.com`):**
441
- - Paid, requires `X-CMC_PRO_API_KEY` header. Do not test or call.
442
-
443
- ---
444
-
445
- ## Gotchas
446
-
447
- - **No JSON-LD on any page tested** — coin pages have zero `<script type="application/ld+json">` elements. Don't look for schema.org markup.
448
-
449
- - **`__NEXT_DATA__` regex**: Must use `[^>]+` between `__NEXT_DATA__"` and `>` — the tag has `crossorigin="anonymous"` which breaks a naive `type="application/json">` match.
450
-
451
- - **`cmcRank` location on homepage listing**: It's `c['cmcRank']` (top-level), NOT inside `c['quotes'][n]['cmcRank']` (that field is always `None`).
452
-
453
- - **5m/sub-hourly OHLCV not available**: Interval `5m` returns HTTP 500. Use `1h` for sub-daily and `daily` for longer ranges.
454
-
455
- - **v2 API is auth-only**: `api.coinmarketcap.com/v2/...` requires API key (401). The equivalent data is available via `data-api/v3/` without auth.
456
-
457
- - **`convert` param accepts symbols not just IDs** in the listing API, but `convert_id` in the price-conversion API requires numeric IDs (e.g. `2781` not `USD`).
458
-
459
- - **Circulating supply**: `c['circulatingSupply']` at the coin top level in the listing response — not inside the quote. The quote has `marketCap` which equals `price * circulatingSupply`.
460
-
461
- - **Multiple quotes per coin**: The listing API returns multiple quote objects when you request multiple convert currencies. Always filter by `q['name'] == 'USD'` (or your target currency) before reading price fields.
462
-
463
- - **Pagination**: `start` is 1-indexed (not 0-indexed). `start=1&limit=100` returns items 1–100, `start=101&limit=100` returns items 101–200.
1
+ # CoinMarketCap — Data Extraction
2
+
3
+ `https://coinmarketcap.com` — crypto market data. Three access paths tested: internal JSON API (fastest, no auth required), `__NEXT_DATA__` from HTML pages, and browser DOM. All real-money price data confirmed accurate against displayed UI values.
4
+
5
+ ## Do this first: pick your access path
6
+
7
+ | Goal | Best approach | Latency |
8
+ |------|--------------|---------|
9
+ | Top N coins by market cap | Internal listing API | ~200ms |
10
+ | Single coin price/stats/ATH | Internal detail API | ~100ms |
11
+ | Global market metrics | Internal global-metrics API | ~65ms |
12
+ | All coins on homepage (101 items) | `__NEXT_DATA__` main page | ~700ms |
13
+ | Coin detail + full stats | `__NEXT_DATA__` currency page | ~700ms |
14
+ | Historical OHLCV | Internal historical API | ~160ms |
15
+ | Exchange pairs for a coin | Internal market-pairs API | ~200ms |
16
+ | News/articles | Internal content API | ~220ms |
17
+
18
+ **Never use the browser for read-only CMC tasks.** The internal API at `api.coinmarketcap.com` is accessible with no API key, no special headers, no auth — plain `http_get` works.
19
+
20
+ **Do NOT use `pro-api.coinmarketcap.com`** — that is the paid API requiring a key.
21
+
22
+ ---
23
+
24
+ ## Path 1: Internal listing API (fastest for ranked coins)
25
+
26
+ Returns CMC-ranked coins with full price data in one call. No auth needed.
27
+
28
+ ```python
29
+ import json
30
+
31
+ resp = json.loads(http_get(
32
+ "https://api.coinmarketcap.com/data-api/v3/cryptocurrency/listing"
33
+ "?start=1&limit=100&sortBy=market_cap&sortType=desc&convert=USD"
34
+ ))
35
+
36
+ coins = resp['data']['cryptoCurrencyList'] # list of coin objects
37
+ total_available = resp['data']['totalCount'] # 8374 as of 2026-04-18
38
+
39
+ for c in coins:
40
+ usd = next(q for q in c['quotes'] if q['name'] == 'USD')
41
+ print(
42
+ f"#{c['cmcRank']} {c['symbol']}: "
43
+ f"${usd['price']:,.2f} | "
44
+ f"MCap ${usd['marketCap']/1e9:.1f}B | "
45
+ f"Vol24h ${usd['volume24h']/1e9:.1f}B | "
46
+ f"24h {usd['percentChange24h']:+.2f}% | "
47
+ f"CS {c['circulatingSupply']:,.0f}"
48
+ )
49
+ ```
50
+
51
+ ### Coin object fields
52
+
53
+ Top-level (`c` in the loop above):
54
+ ```
55
+ id, name, symbol, slug, cmcRank, marketPairCount,
56
+ circulatingSupply, selfReportedCirculatingSupply,
57
+ totalSupply, maxSupply, isActive, lastUpdated, dateAdded,
58
+ quotes, isAudited, auditInfoList, badges
59
+ ```
60
+
61
+ Per-quote fields (inside `c['quotes']`, filtered by `name == 'USD'`):
62
+ ```
63
+ name, price, volume24h, volumePercentChange, marketCap,
64
+ percentChange1h, percentChange24h, percentChange7d,
65
+ percentChange30d, percentChange60d, percentChange90d,
66
+ percentChange1y, ytdPriceChangePercentage,
67
+ fullyDilluttedMarketCap, marketCapByTotalSupply,
68
+ dominance, turnover, lastUpdated
69
+ ```
70
+
71
+ ### Query parameters
72
+
73
+ ```python
74
+ # Pagination
75
+ "?start=1&limit=100" # page 1 of 100
76
+ "?start=101&limit=100" # page 2
77
+
78
+ # Sort
79
+ "sortBy=market_cap" # default
80
+ "sortBy=volume_24h"
81
+ "sortBy=percent_change_24h"
82
+ "sortBy=price"
83
+ "sortBy=circulating_supply"
84
+ "sortType=desc" # or asc
85
+
86
+ # Currency conversion (affects quote prices returned)
87
+ "convert=USD" # USD prices
88
+ "convert=BTC" # BTC-denominated
89
+
90
+ # Filter by type
91
+ "cryptoType=all" # default — coins + tokens
92
+ "cryptoType=coins" # layer-1s only (633 results)
93
+ "cryptoType=tokens" # ERC-20 etc.
94
+
95
+ # Filter by tag (DeFi, NFT, etc.)
96
+ "tagSlugs=defi" # 2698 results
97
+ "tagSlugs=nft"
98
+ ```
99
+
100
+ ---
101
+
102
+ ## Path 2: Internal detail API (single coin, full stats)
103
+
104
+ Best for fetching one coin's complete data including ATH, ATL, 52-week high/low, volume ranks.
105
+
106
+ ```python
107
+ import json
108
+
109
+ # Look up by CMC coin ID (BTC=1, ETH=1027, XRP=52, SOL=5426, BNB=1839)
110
+ resp = json.loads(http_get(
111
+ "https://api.coinmarketcap.com/data-api/v3/cryptocurrency/detail?id=1"
112
+ ))
113
+ data = resp['data']
114
+ s = data['statistics']
115
+
116
+ print(f"Price: ${s['price']:,.2f}")
117
+ print(f"Rank: #{s['rank']}")
118
+ print(f"Market Cap: ${s['marketCap']:,.0f}")
119
+ print(f"Volume 24h: ${s['volume24h']:,.0f}")
120
+ print(f"Circulating Supply:{s['circulatingSupply']:,.0f}")
121
+ print(f"Total Supply: {s['totalSupply']:,.0f}")
122
+ print(f"Max Supply: {s['maxSupply']:,.0f}")
123
+ print(f"24h Change: {s['priceChangePercentage24h']:+.2f}%")
124
+ print(f"7d Change: {s['priceChangePercentage7d']:+.2f}%")
125
+ print(f"ATH: ${s['highAllTime']:,.2f} on {s['highAllTimeTimestamp']}")
126
+ print(f"ATL: ${s['lowAllTime']:,.4f} on {s['lowAllTimeTimestamp']}")
127
+ print(f"52w High: ${s['high52w']:,.2f}")
128
+ print(f"52w Low: ${s['low52w']:,.2f}")
129
+ print(f"MCap Dominance: {s['marketCapDominance']:.2f}%")
130
+ ```
131
+
132
+ ### All statistics fields
133
+
134
+ ```
135
+ price, priceChangePercentage1h, priceChangePercentage24h,
136
+ priceChangePercentage7d, priceChangePercentage30d,
137
+ priceChangePercentage60d, priceChangePercentage90d,
138
+ priceChangePercentage1y, priceChangePercentageAll,
139
+ marketCap, marketCapChangePercentage24h,
140
+ fullyDilutedMarketCap, mintedMarketCap,
141
+ circulatingSupply, totalSupply, maxSupply,
142
+ marketCapDominance, rank, roi,
143
+ low24h, high24h, low7d, high7d, low30d, high30d,
144
+ low52w, high52w, low90d, high90d,
145
+ lowAllTime, highAllTime,
146
+ lowAllTimeChangePercentage, highAllTimeChangePercentage,
147
+ lowAllTimeTimestamp, highAllTimeTimestamp,
148
+ lowYesterday, highYesterday, openYesterday, closeYesterday,
149
+ priceChangePercentageYesterday, volumeYesterday,
150
+ ytdPriceChangePercentage, volumeRank, volumeMcRank,
151
+ volume24h, volume24hReported, volume7d, volume7d Reported,
152
+ volume30d, volume30dReported, turnover
153
+ ```
154
+
155
+ ### Top-level data fields (beyond statistics)
156
+
157
+ ```
158
+ id, name, symbol, slug, category, description, dateAdded,
159
+ volume, volumeChangePercentage24h, cexVolume, dexVolume,
160
+ urls (website, explorer, twitter, reddit, etc.),
161
+ tags, platforms, relatedCoins, wallets,
162
+ holders, watchCount, watchListRanking
163
+ ```
164
+
165
+ ---
166
+
167
+ ## Path 3: Global market metrics
168
+
169
+ ```python
170
+ import json
171
+
172
+ resp = json.loads(http_get(
173
+ "https://api.coinmarketcap.com/data-api/v3/global-metrics/quotes/latest"
174
+ ))
175
+ data = resp['data']
176
+ q = data['quotes'][0] # USD quote (cryptoId=2781)
177
+
178
+ print(f"Total Market Cap: ${q['totalMarketCap']/1e12:.2f}T")
179
+ print(f"Total Volume 24h: ${q['totalVolume24H']/1e9:.1f}B")
180
+ print(f"Altcoin MCap: ${q['altcoinMarketCap']/1e12:.2f}T")
181
+ print(f"DeFi MCap: ${q['defiMarketCap']/1e9:.1f}B")
182
+ print(f"DeFi Vol 24h: ${q['defiVolume24H']/1e9:.1f}B")
183
+ print(f"Stablecoin MCap: ${q['stablecoinMarketCap']/1e9:.1f}B")
184
+ print(f"Derivatives Vol: ${q['derivativesVolume24H']/1e9:.1f}B")
185
+ print(f"BTC Dominance: {data['btcDominance']:.2f}%")
186
+ print(f"ETH Dominance: {data['ethDominance']:.2f}%")
187
+ print(f"Active Cryptos: {data['activeCryptoCurrencies']}")
188
+ print(f"Total Cryptos: {data['totalCryptoCurrencies']}")
189
+ print(f"Active Exchanges: {data['activeExchanges']}")
190
+ print(f"Active Pairs: {data['activeMarketPairs']}")
191
+
192
+ # Yesterday comparison
193
+ print(f"\nMCap Yesterday: ${q['totalMarketCapYesterday']/1e12:.2f}T")
194
+ print(f"MCap Change: {q['totalMarketCapYesterdayPercentageChange']:+.2f}%")
195
+ ```
196
+
197
+ ---
198
+
199
+ ## Path 4: Historical OHLCV (candlestick data)
200
+
201
+ ```python
202
+ import json, time
203
+
204
+ now = int(time.time())
205
+
206
+ # Daily candles for BTC over last 7 days
207
+ resp = json.loads(http_get(
208
+ "https://api.coinmarketcap.com/data-api/v3/cryptocurrency/historical"
209
+ f"?id=1&convertId=2781&timeStart={now - 7*86400}&timeEnd={now}&interval=daily"
210
+ ))
211
+ candles = resp['data']['quotes'] # list of OHLCV dicts
212
+
213
+ for candle in candles:
214
+ q = candle['quote']
215
+ print(
216
+ f"{candle['timeOpen'][:10]} "
217
+ f"O={q['open']:,.0f} H={q['high']:,.0f} "
218
+ f"L={q['low']:,.0f} C={q['close']:,.0f} "
219
+ f"V=${q['volume']/1e9:.1f}B MCap=${q['marketCap']/1e12:.2f}T"
220
+ )
221
+ ```
222
+
223
+ Candle quote fields: `open, high, low, close, volume, marketCap, circulatingSupply, timestamp`
224
+
225
+ Supported intervals: `daily`, `1h` (hourly). `5m` returns HTTP 500 — not supported.
226
+
227
+ `convertId=2781` = USD. `timeStart`/`timeEnd` are Unix timestamps.
228
+
229
+ ---
230
+
231
+ ## Path 5: Exchange market pairs for a coin
232
+
233
+ ```python
234
+ import json
235
+
236
+ resp = json.loads(http_get(
237
+ "https://api.coinmarketcap.com/data-api/v3/cryptocurrency/market-pairs/latest"
238
+ "?id=1&start=1&limit=10&sort=volume"
239
+ ))
240
+ data = resp['data']
241
+ print(f"Total pairs for {data['name']}: {data['numMarketPairs']}")
242
+
243
+ for pair in data['marketPairs']:
244
+ print(
245
+ f" {pair['exchangeName']:20} {pair['marketPair']:12} "
246
+ f"${pair['price']:,.2f} Vol=${pair['volumeUsd']/1e6:.1f}M"
247
+ )
248
+ ```
249
+
250
+ Pair fields: `rank, exchangeId, exchangeName, exchangeSlug, marketId, marketPair, category (spot/futures), baseSymbol, quoteSymbol, baseCurrencyId, quoteCurrencyId, price, volumeUsd, effectiveLiquidity, lastUpdated, volumeBase, volumeQuote, depthUsdNegativeTwo, depthUsdPositiveTwo, feeType, isVerified, type (cex/dex)`
251
+
252
+ ---
253
+
254
+ ## Path 6: Exchange listings
255
+
256
+ ```python
257
+ import json
258
+
259
+ resp = json.loads(http_get(
260
+ "https://api.coinmarketcap.com/data-api/v3/exchange/listing"
261
+ "?start=1&limit=20&sortBy=score&sortType=desc"
262
+ ))
263
+ exchanges = resp['data']['exchanges']
264
+ for ex in exchanges:
265
+ print(f" {ex['name']:30} score={ex.get('score')} trafficScore={ex.get('trafficScore')}")
266
+ ```
267
+
268
+ Exchange fields: `id, name, slug, dexStatus, platformId, status, score, trafficScore, countries, fiats, filteredTotalVol24h`
269
+
270
+ ---
271
+
272
+ ## Path 7: Price conversion (cross-rate)
273
+
274
+ ```python
275
+ import json
276
+
277
+ # Convert 1 BTC → USD
278
+ resp = json.loads(http_get(
279
+ "https://api.coinmarketcap.com/data-api/v3/tools/price-conversion"
280
+ "?amount=1&id=1&convert_id=2781"
281
+ ))
282
+ result = resp['data']
283
+ usd_price = result['quote'][0]['price']
284
+ print(f"1 {result['symbol']} = ${usd_price:,.2f} USD")
285
+
286
+ # Convert ETH → BTC
287
+ resp2 = json.loads(http_get(
288
+ "https://api.coinmarketcap.com/data-api/v3/tools/price-conversion"
289
+ "?amount=1&id=1027&convert_id=1"
290
+ ))
291
+ btc_price = resp2['data']['quote'][0]['price']
292
+ print(f"1 ETH = {btc_price:.6f} BTC")
293
+ ```
294
+
295
+ `id` = source coin CMC ID, `convert_id` = target currency CMC ID (2781=USD, 1=BTC, 1027=ETH, 825=USDT)
296
+
297
+ ---
298
+
299
+ ## Path 8: News / articles
300
+
301
+ ```python
302
+ import json
303
+
304
+ # News for a specific coin
305
+ resp = json.loads(http_get(
306
+ "https://api.coinmarketcap.com/content/v3/news?coins=1&limit=10"
307
+ ))
308
+ for article in resp['data']:
309
+ meta = article['meta']
310
+ print(f" [{meta['sourceName']}] {meta['title']}")
311
+ print(f" {article['createdAt'][:10]} — {meta['sourceUrl']}")
312
+ ```
313
+
314
+ Article fields: `slug, cover, assets, createdAt` + nested `meta` with `title, subtitle, sourceName, sourceUrl, language, type, status, id, createdAt, updatedAt, releasedAt`
315
+
316
+ Omit `coins=` param for general crypto news. Supports `limit` up to observed 50+ without errors.
317
+
318
+ ---
319
+
320
+ ## Path 9: __NEXT_DATA__ from HTML pages
321
+
322
+ Use when you need data that isn't in the API (e.g. Fear & Greed index, CMC100 index, trending categories).
323
+
324
+ ### Main page (`coinmarketcap.com/`)
325
+
326
+ ```python
327
+ import json, re
328
+
329
+ html = http_get("https://coinmarketcap.com/")
330
+ m = re.search(r'<script id="__NEXT_DATA__"[^>]+>([\s\S]*?)</script>', html)
331
+ nd = json.loads(m.group(1))
332
+ props = nd['props']
333
+
334
+ # Global market metrics (same data as global-metrics API, faster from HTML)
335
+ gm = props['pageProps']['globalMetrics']
336
+ print(f"Total cryptos: {gm['numCryptocurrencies']}")
337
+ print(f"BTC dominance: {gm['btcDominance']:.2f}%")
338
+ print(f"Total MCap: ${gm['marketCap']/1e12:.2f}T")
339
+ print(f"Total Vol 24h: ${gm['totalVol']/1e9:.1f}B")
340
+
341
+ # Spot prices for BTC/ETH/USD/SATS/BITS (the "ticker bar" data)
342
+ # props['quotesLatestData'] — 5 items with short field names
343
+ for q in props['quotesLatestData']:
344
+ print(f" {q['symbol']}: p={q['p']} p24h={q['p24h']:+.3f}%")
345
+ # fields: id, symbol, p (price), p1h, p24h, p7d, p30d, p60d, p90d, pytd, t
346
+
347
+ # Top 101 coins with full USD quotes — from dehydratedState
348
+ queries = props['dehydratedState']['queries']
349
+ homepage_q = next(q for q in queries if q['queryKey'] == ['homepage-data', 1, 100])
350
+ listing = homepage_q['state']['data']['data']['listing']
351
+ coins = listing['cryptoCurrencyList'] # 101 coins
352
+ total = listing['totalCount']
353
+
354
+ for c in coins:
355
+ if c['symbol'] == 'BTC':
356
+ usd = next(q for q in c['quotes'] if q['name'] == 'USD')
357
+ print(f"BTC: #{c['cmcRank']} ${usd['price']:,.2f}")
358
+ break
359
+
360
+ # Page-level shared data (Fear & Greed index, CMC20, altcoin index)
361
+ psd = props['pageProps']['pageSharedData']
362
+ print("pageSharedData keys:", list(psd.keys()))
363
+ # keys: topCategories, fearGreedIndexData, cmc100, cmc20, faqData, altcoinIndex, halvingInfo, deviceInfo
364
+ ```
365
+
366
+ **Gotcha — regex pattern**: Use `[^>]+` to match the `crossorigin="anonymous"` attribute on the script tag. `type="application/json"` alone will miss it:
367
+ ```python
368
+ # CORRECT
369
+ m = re.search(r'<script id="__NEXT_DATA__"[^>]+>([\s\S]*?)</script>', html)
370
+
371
+ # WRONG — returns None because of crossorigin attr
372
+ m = re.search(r'<script id="__NEXT_DATA__" type="application/json">(.*?)</script>', html, re.DOTALL)
373
+ ```
374
+
375
+ **`quotesLatestData` has only 5 entries** (SATS, BITS, BTC, ETH, USD) — it's the currency selector bar, not the full market ranking. For the full ranked listing use `dehydratedState`.
376
+
377
+ **`cmcRank` is at coin top level**, not inside the USD quote object. The `cmcRank` field inside the quote dict is `None`.
378
+
379
+ ### Individual coin page (`/currencies/{slug}/`)
380
+
381
+ ```python
382
+ import json, re
383
+
384
+ html = http_get("https://coinmarketcap.com/currencies/bitcoin/")
385
+ m = re.search(r'<script id="__NEXT_DATA__"[^>]+>([\s\S]*?)</script>', html)
386
+ nd = json.loads(m.group(1))
387
+
388
+ # All stats under props.pageProps.detailRes.detail.statistics
389
+ stats = nd['props']['pageProps']['detailRes']['detail']['statistics']
390
+
391
+ print(f"Price: ${stats['price']:,.2f}")
392
+ print(f"Rank: #{stats['rank']}")
393
+ print(f"MCap: ${stats['marketCap']:,.0f}")
394
+ print(f"Vol 24h: ${stats['volume24h']:,.0f}")
395
+ print(f"Circ Sup: {stats['circulatingSupply']:,.0f}")
396
+ print(f"24h: {stats['priceChangePercentage24h']:+.2f}%")
397
+ print(f"ATH: ${stats['highAllTime']:,.2f} ({stats['highAllTimeTimestamp']})")
398
+ print(f"ATL: ${stats['lowAllTime']:.4f}")
399
+ ```
400
+
401
+ `detailRes.detail` also contains: `name, symbol, slug, description, tags, urls (website/explorer/twitter/reddit), platforms, relatedCoins, holders, watchCount`
402
+
403
+ **Note**: The currency page has no JSON-LD blocks — zero `<script type="application/ld+json">` elements.
404
+
405
+ ---
406
+
407
+ ## Common coin IDs
408
+
409
+ | ID | Symbol | Name |
410
+ |----|--------|------|
411
+ | 1 | BTC | Bitcoin |
412
+ | 1027 | ETH | Ethereum |
413
+ | 52 | XRP | XRP |
414
+ | 825 | USDT | Tether |
415
+ | 1839 | BNB | BNB |
416
+ | 3408 | USDC | USD Coin |
417
+ | 5426 | SOL | Solana |
418
+ | 74 | DOGE | Dogecoin |
419
+ | 2781 | USD | US Dollar (for convert_id) |
420
+
421
+ Find IDs from the listing API: `c['id']` or from the detail API URL by looking up a slug first via the listing API's `c['slug']` field.
422
+
423
+ ---
424
+
425
+ ## Anti-bot / rate limits
426
+
427
+ **Main site (`coinmarketcap.com`):**
428
+ - `http_get` works with the default `Mozilla/5.0` UA — no Cloudflare, no bot detection triggered.
429
+ - Page loads are ~700ms for 690–710KB of HTML+`__NEXT_DATA__`.
430
+
431
+ **Internal API (`api.coinmarketcap.com`):**
432
+ - No auth headers required. No `X-Request-Id` or `X-Forwarded-For` needed.
433
+ - 25 rapid sequential calls with zero rate limiting or errors — no throttle observed at that volume.
434
+ - Typical latency: 65–250ms per call.
435
+ - `error_code: '0'` and `error_message: 'SUCCESS'` in every response; no `credit_count` consumed.
436
+
437
+ **v2 API (`api.coinmarketcap.com/v2/`):**
438
+ - Returns HTTP 401 Unauthorized — requires API key. Do not use.
439
+
440
+ **Pro API (`pro-api.coinmarketcap.com`):**
441
+ - Paid, requires `X-CMC_PRO_API_KEY` header. Do not test or call.
442
+
443
+ ---
444
+
445
+ ## Gotchas
446
+
447
+ - **No JSON-LD on any page tested** — coin pages have zero `<script type="application/ld+json">` elements. Don't look for schema.org markup.
448
+
449
+ - **`__NEXT_DATA__` regex**: Must use `[^>]+` between `__NEXT_DATA__"` and `>` — the tag has `crossorigin="anonymous"` which breaks a naive `type="application/json">` match.
450
+
451
+ - **`cmcRank` location on homepage listing**: It's `c['cmcRank']` (top-level), NOT inside `c['quotes'][n]['cmcRank']` (that field is always `None`).
452
+
453
+ - **5m/sub-hourly OHLCV not available**: Interval `5m` returns HTTP 500. Use `1h` for sub-daily and `daily` for longer ranges.
454
+
455
+ - **v2 API is auth-only**: `api.coinmarketcap.com/v2/...` requires API key (401). The equivalent data is available via `data-api/v3/` without auth.
456
+
457
+ - **`convert` param accepts symbols not just IDs** in the listing API, but `convert_id` in the price-conversion API requires numeric IDs (e.g. `2781` not `USD`).
458
+
459
+ - **Circulating supply**: `c['circulatingSupply']` at the coin top level in the listing response — not inside the quote. The quote has `marketCap` which equals `price * circulatingSupply`.
460
+
461
+ - **Multiple quotes per coin**: The listing API returns multiple quote objects when you request multiple convert currencies. Always filter by `q['name'] == 'USD'` (or your target currency) before reading price fields.
462
+
463
+ - **Pagination**: `start` is 1-indexed (not 0-indexed). `start=1&limit=100` returns items 1–100, `start=101&limit=100` returns items 101–200.