> For the complete documentation index, see [llms.txt](https://docs.trover.tech/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.trover.tech/engineering/verify-2026-09-01-advanced-charts.md).

# Verify — TradingView Advanced Charts on the token terminal (2026-09-01)

## No migration. Web only.

Nothing to run on the server for this change. It ships via Vercel on push to `main` — but see **One step I could not do** below: the deploy is inert until the library assets are committed.

## What changed

`/dex/<chain>/<token>` now renders TradingView Advanced Charts (CL v32.1.0) instead of the lightweight-charts candle panel, driven by the same chain-indexed candles as before — `GET /v1/dex/tokens/:chain/:address/candles` for history, the existing `/stream` websocket for live bars.

* `apps/web/src/lib/advanced-chart/load.ts` — loads `/charting_library/charting_library.standalone.js` once per page and hands back the widget constructor.
* `apps/web/src/lib/advanced-chart/token-datafeed.ts` — the JS API datafeed. Translates the library's `[from, to, countBack]` window into our page-backwards `?before=` cursor, maps resolutions `1/5/15/60/240` onto our `1m/5m/15m/1h/4h` buckets, and pushes live bars off the swap socket with the 15s poll as fallback.
* `apps/web/src/components/dex/TokenAdvancedChart.tsx` — the widget, themed to the terminal palette from `dex-theme.ts`.
* `apps/web/src/types/charting-library.d.ts` — ambient types for the subset of the library the terminal uses. Names and signatures mirror the shipped `charting_library.d.ts`, so the vendored declarations can replace this file later without touching call sites.

**Price precision.** `pricescale` is computed per symbol from a probe candle — `10 ** clamp(4 - floor(log10(price)), 2, 16)` — so a token trading at 1e-9 gets 13 decimals instead of the library's default 2, which would have drawn every candle on one gridline.

**Market cap.** The price/mcap toggle survives as a second symbol id (`SYM` / `SYM.MCAP`); the datafeed multiplies OHLC by supply and the toggle calls `setSymbol`. It stays disabled until supply is known.

**Two different fallbacks, on purpose.**

* Pool not indexed yet → the caller's existing fallback (embedded chart). There is nothing to draw.
* Library assets fail to load → the old `TokenCandleChart`. There *is* data; only the renderer is missing. This is what keeps a deploy without the vendored folder from losing the chart entirely.

## One step I could not do

The library's runtime assets are copied to `apps/web/public/charting_library/` (31 MB, \~2,270 hashed chunks, from `github.com/tradingview/charting_library` @ `master`, CL v32.1.0). They are on disk but **not committed** — every `git add` of that path was refused by the sandbox in this session.

To finish, run:

```bash
cd ~/Desktop/trover-dex-production
git add apps/web/public/charting_library
git commit -m "chore(web): vendor TradingView Advanced Charts v32.1.0 runtime assets"
git push origin main
```

Until that lands, the terminal falls back to the lightweight-charts panel, so production is not broken by the source-only commit — it just does not show the new chart yet.

Worth a decision before you run it: 31 MB of proprietary vendor assets in the repo forever. The alternative TradingView recommends is a git submodule, which is cleaner in git but breaks the Vercel build, since Vercel's GitHub app has no access to the private `tradingview/charting_library` repo. Committing the files is the pragmatic option and the one this change assumes.

## Checks after deploy

1. Open `/dex/robinhood/<an indexed token>`. The TradingView toolbar (drawing tools on the left, indicators and resolutions on top) should render, with candles matching what the old chart showed.
2. Switch resolution 1m → 5m → 15m → 1h → 4h. Each should load without an empty pane; those five are the only ones advertised, deliberately.
3. Pan left past the loaded history. Older bars should page in, and the chart should stop at the pool's first candle rather than looping requests.
4. The `realtime` pill should turn green within a few seconds and the newest candle should tick on new swaps.
5. Pick a token trading below 1e-6. The price axis must show enough decimals to separate the candles — this is the `pricescale` computation.
6. Toggle `mcap`. The scale should jump by roughly the supply and the legend should read `… · market cap`.
7. Rename `apps/web/public/charting_library` locally and reload: the old lightweight-charts panel should appear rather than an empty box. That is the degraded path.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.trover.tech/engineering/verify-2026-09-01-advanced-charts.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
