/chart: price charts
/chart symbol:AAPL draws a price chart as a PNG. symbol takes a ticker (AAPL, ^GSPC), a
company name (apple), a coin (bitcoin, btc, ETH-USD) or a currency pair (EUR/USD, usdjpy).
It ships off (migration 0109). A server turns it on from Commands, as with /topic.
Options
| Option | Values |
|---|---|
compare |
up to 3 more symbols, drawn together as percent change (MSFT, bitcoin, EUR/USD) |
currency |
convert prices to this currency (EUR, GBP, JPY, any ISO code) |
period |
1 day, 5 days, 1 month (default), 3 months, 6 months, YTD, 1 year, 5 years, all time |
style |
area (default), line, candles |
volume |
show trading volume under the chart |
theme |
dark (default), light |
A server can change the defaults on its Stock charts page (Settings → Stock charts).
Crypto, currencies and comparisons
- Coins.
btcpicksBTC-USDover look-alike funds; a name such asbitcoinuses Yahoo's first result. - Currency pairs.
EUR/USD,eur usd,eurusdandeur-usdall read asEURUSD=X. Only real ISO 4217 codes count, soBTC-USDstill goes to search. currency. Converts every price into that currency with Yahoo's<FROM><TO>=Xrate over the same period; each point uses the latest rate at or before it. Prices Yahoo quotes in pence (GBp,GBX,ZAc,ILA) are scaled to the major unit first.compare. One line per symbol as percent change from the start of the window where all of them have data (so intraday stocks and 24/7 crypto are measured over the same hours; if they barely overlap, the whole span is used). If the symbols are priced in different currencies and none was asked for, all convert to the first symbol's currency, since percent changes in different currencies would not compare. Colors are the Okabe-Ito set, readable with common color blindness. Style and volume buttons are hidden on a comparison.- A button's id holds up to four symbols in 36 characters; extras that do not fit are dropped.
Buttons
The reply has buttons for each period, the style (cycles), volume, theme and Refresh. A click
redraws the same message. Only the person who ran the command can click; anyone else gets a private
note. The chart's settings live in each button's custom_id
(stk|symbols|period|style|theme|volume|currency|user|key, stock-state.ts), so nothing is stored.
Server look
By default every chart picks up the server's look. Sources, strongest first:
- The owner's accent color (Stock charts page).
- The owner's style hint, a few words such as "ocean" or "neon".
- The main color of the server icon. Read once per icon by drawing it small with resvg; the result
is stored in
stock_settingswith the icon hash, so a new icon is read again and nothing else is. - A theme word in the server description, only when it points one way. No match, or a tie between themes, changes nothing.
The color tints the background, panel and grid, colors the symbol, adds a thin top bar, and the
icon and server name appear in the footer. Rising and falling stay green and red (they mean
something) unless the owner sets them. Text and colors are lightened or darkened when they would
not read on the background (ensureContrast, tested as a property). The owner can turn automatic
looks off, or hide the badge; their own colors still apply.
How it works
stock-chart-core.ts: Yahoo response to points, scales, and the scene, built with svjeez (static, no animation).stock-branding.ts: pure color logic.stock-branding-io.ts: gathers settings, guild metadata and the icon.stock-command.ts: resolves the name, fetches, draws, rasterizes with resvg (svg-to-png.ts) and edits the deferred reply with the PNG and buttons.stock-data.tsgets the prices; see Data sources below.svg-to-png.tsstarts resvg from a precompiled module on Workers (see "Why the wasm import" below).
Data sources and the cache
Order for one symbol and period:
- A fresh saved copy (60 seconds for 1 day, 5 minutes for 5 days, 15 minutes up to 6 months, an hour for YTD and 1 year, 6 hours beyond).
- Yahoo Finance's public chart endpoint. Unofficial: no key, and it can throttle or change.
- If Yahoo fails: Binance's public candles for a coin (
BTC-USD,ETH-EUR;data-api.binance.vision), or Frankfurter's ECB daily rates for a currency pair (EURUSD=X; daily only, so a "1 day" chart shows the last week of daily points). - If those fail or do not apply: a saved copy up to 24 hours old, and the footer says how old it is.
Saved copies use Cloudflare's Cache API (per data center, free, no database writes), or memory where
that does not exist. Name-to-symbol lookups are saved for a day. Identical requests at the same
moment share one fetch. The footer names the source (Yahoo Finance, Binance,
ECB rates (Frankfurter), or several for a comparison).
Stooq was considered for daily stocks and is not used: it now serves a JavaScript proof-of-work page to scripts. There is no stock fallback beyond the saved copy; a keyed provider (Twelve Data, Tiingo) would be the next step.
Why the wasm import
Cloudflare Workers refuse to compile WebAssembly from bytes ("Wasm code generation disallowed by
embedder"); they accept a precompiled module. /chart first shipped starting resvg from bytes and
failed in production with "Something went wrong drawing that chart" (found 2026-11-29; reproduced in
workerd). vite.config.js (resvgWasmModule) leaves import('virtual:resvg-wasm') as
import('./resvg_bg.wasm') and emits the file beside the server chunks; wrangler turns it into a
module. Node, the gateway and tests have no such import, so svg-to-png.ts falls back to fetching the
bytes there.
Credit
Every chart carries "Made with svjeez.texoport.in" in its footer line, and so does the Discord
embed's footer (CREDIT in stock-chart-core.ts). Keep it when changing the footer.
Not done
Alerts, a watchlist, correlation or ratio charts, intraday for exchanges Yahoo does not cover, a cache for repeated requests (each chart is two Yahoo calls and one render).