Docs

Getting started

From an empty folder to a live, interactive chart, one small step at a time. Every step ends with something you can see, and most come with a chart running right here.

The blue steps matter most: a chart on screen, your own data, and the chart type you want.

Before you start

You needVersionWhy
Node.js22 or newerThe package requires it (engines)
React and React DOM18 or 19They are peer dependencies
A bundlerVite, Next.js, or similarThe package is ESM and ships its CSS separately

The ten steps

  1. Create a project

    Skip this if you already have a React app.

    bash
    npm create vite@latest my-charts -- --template react-ts
    cd my-charts

    You should see: a my-charts folder with src/App.tsx in it.

  2. Install Astroneum

    npm
    npm install astroneum

    You should see: astroneum under dependencies in package.json.

  3. Render your first chart

    Replace src/App.tsx with this. The chart below is exactly this code, running on live Bitcoin data.

    src/App.tsx
    import { AstroneumChart, createStandardCryptoDatafeed, STANDARD_CRYPTO_SYMBOLS } from 'astroneum'
    import 'astroneum/style.css'
    
    // Create the datafeed once, outside the component.
    const datafeed = createStandardCryptoDatafeed()
    
    export default function App() {
      return (
        <AstroneumChart
          symbol={STANDARD_CRYPTO_SYMBOLS[0]}
          period={{ multiplier: 1, timespan: 'hour', text: '1H' }}
          datafeed={datafeed}
          theme="dark"
          style={{ width: '100%', height: 360 }}
        />
      )
    }
    Running: live Bitcoin from Binance
    Loads when scrolled into view

    You should see: a live candlestick chart with three moving-average lines (the default) and a volume pane underneath. Drag to pan, scroll to zoom, and use the toolbar to switch timeframe or add indicators.

    If the chart above stays empty, your network may be blocking the exchange. Step 5 shows data that needs no network.

  4. How data gets into the chart

    Before using your own data, see what the chart does with a datafeed. A datafeed is an object with four methods. The chart calls them; you never call them yourself.

    MethodThe chart calls it whenYou return
    searchSymbols(search?)you type in the symbol search boxPromise<SymbolInfo[]>
    getHistoryData(symbol, period, from, to)it loads the first bars, and when you scroll backPromise<CandleData[]>, oldest first
    subscribe(symbol, period, callback)history has loadednothing; call callback(bar) for each live update
    unsubscribe(symbol, period)the symbol or period changesnothing; stop sending updates

    A bar (CandleData) is { timestamp, open, high, low, close, volume? }, with timestamp in milliseconds.

    The one rule for live updates

    Send a bar with the same timestamp as the latest bar to update it, or a newer timestamp to start a new bar. Older timestamps are ignored. Try it:

    10:0010:0110:0210:0310:0410:05incomingnothing yet
    // press a button: this is what your datafeed does
  5. Use your own data

    This is a complete datafeed that needs no server. It makes up a random price and keeps it moving, which is handy for testing. It is the code below, running:

    src/App.tsx
    import { AstroneumChart } from 'astroneum'
    import type { CandleData, Datafeed, Period, SymbolInfo } from 'astroneum'
    import 'astroneum/style.css'
    
    const MINUTE = 60_000
    const symbol: SymbolInfo = { ticker: 'DEMO', name: 'Demo market', pricePrecision: 2 }
    const period: Period = { multiplier: 1, timespan: 'minute', text: '1m' }
    
    let price = 100
    function nextBar(timestamp: number): CandleData {
      const open = price
      price = Math.max(1, price + (Math.random() - 0.5) * 2)
      return {
        timestamp,
        open,
        high: Math.max(open, price) + Math.random() * 0.4,
        low: Math.min(open, price) - Math.random() * 0.4,
        close: price,
        volume: Math.round(Math.random() * 1000),
      }
    }
    
    let timer: ReturnType<typeof setInterval> | undefined
    
    const datafeed: Datafeed = {
      // The symbol search box. One symbol is enough for this demo.
      searchSymbols: async () => [symbol],
    
      // Called with a time range. Return bars inside it, oldest first.
      getHistoryData: async (_symbol, _period, from, to) => {
        const bars: CandleData[] = []
        for (let t = Math.ceil(from / MINUTE) * MINUTE; t <= to; t += MINUTE) bars.push(nextBar(t))
        return bars
      },
    
      // Send a bar every second. Same minute = update it; new minute = new bar.
      subscribe: (_symbol, _period, callback) => {
        let last = nextBar(Math.floor(Date.now() / MINUTE) * MINUTE)
        timer = setInterval(() => {
          const minute = Math.floor(Date.now() / MINUTE) * MINUTE
          if (minute > last.timestamp) {
            last = nextBar(minute)
          } else {
            price = Math.max(1, price + (Math.random() - 0.5))
            last = { ...last, close: price, high: Math.max(last.high, price), low: Math.min(last.low, price) }
          }
          callback(last)
        }, 1000)
      },
    
      unsubscribe: () => clearInterval(timer),
    }
    
    export default function App() {
      return (
        <AstroneumChart
          symbol={symbol}
          period={period}
          datafeed={datafeed}
          theme="dark"
          style={{ width: '100%', height: 360 }}
        />
      )
    }
    Running: the datafeed above
    Loads when scrolled into view

    You should see: a chart of the made-up market, with the last candle twitching every second. That is the whole contract: history in, then a stream of updates.

    To connect a real source, keep the same four methods and replace the bodies with fetch calls and a WebSocket. The Datafeeds page goes further.

  6. Choose a chart type

    There are two kinds of chart type, and the difference decides how you set them up.

    Types the chart draws itself: one style prop

    tsx
    <AstroneumChart
      symbol={symbol}
      period={period}
      datafeed={datafeed}
      styles={{ candle: { type: 'line' } }}   // the only change
      style={{ width: '100%', height: 360 }}
    />
    Loads when scrolled into view

    You should see: a single price line where the candles were. You can change styles while the chart is mounted; it updates in place.

    Types built from your data: wrap the datafeed

    tsx
    import { createTransformedDatafeed, generateRenko, heikinAshi } from 'astroneum'
    
    // Heikin-Ashi: same timestamps, smoothed values.
    const heikin = createTransformedDatafeed(datafeed, () => heikinAshi)
    
    // Renko: fixed-size bricks. The factory runs once on the loaded history,
    // so the brick size stays fixed while live updates arrive.
    const renko = createTransformedDatafeed(datafeed, (history) => {
      const range = history.slice(-100).reduce((sum, bar) => sum + (bar.high - bar.low), 0) / 100
      const brick = Number(range.toPrecision(2))
      return (bars) => generateRenko(bars, brick)
    })
    
    <AstroneumChart key="renko" datafeed={renko} /* ...the same props as before... */ />
    Loads when scrolled into view

    You should see: stepped bricks that only move when the price moves a full brick. Remount with a different key when you switch datafeeds. Renko ignores time, so its time axis shows synthetic times.

  7. Add indicators

    Indicators are props. Overlays such as moving averages draw on the price chart; everything else gets its own pane underneath.

    tsx
    <AstroneumChart
      symbol={symbol}
      period={period}
      datafeed={datafeed}
      mainIndicators={[{ name: 'EMA', calcParams: [7, 25, 99] }, { name: 'BOLL' }]}
      subIndicators={['VOL', 'RSI', 'MACD']}
      style={{ width: '100%', height: 460 }}
    />
    Loads when scrolled into view

    You should see: the EMA lines and a Bollinger band on the price chart, plus VOL, RSI and MACD panes beneath it. The props follow changes: add or remove a name and the chart updates without remounting. There are about 50 indicators; the Indicators page lets you toggle them.

  8. Control the chart from code

    Attach a ref to get a handle. It lets your own buttons drive the chart. Click them:

    src/App.tsx
    import { useRef } from 'react'
    import { AstroneumChart, createStandardCryptoDatafeed, STANDARD_CRYPTO_SYMBOLS } from 'astroneum'
    import type { AstroneumHandle } from 'astroneum'
    import 'astroneum/style.css'
    
    const datafeed = createStandardCryptoDatafeed()
    
    export default function App() {
      const chart = useRef<AstroneumHandle>(null)
    
      return (
        <>
          <button onClick={() => chart.current?.setSymbol(STANDARD_CRYPTO_SYMBOLS[1])}>Switch symbol</button>
          <button onClick={() => chart.current?.setPeriod({ multiplier: 15, timespan: 'minute', text: '15m' })}>15m</button>
          <button onClick={() => chart.current?.setTheme('light')}>Light theme</button>
          <button onClick={() => chart.current?.setTheme('dark')}>Dark theme</button>
    
          <AstroneumChart
            ref={chart}
            symbol={STANDARD_CRYPTO_SYMBOLS[0]}
            period={{ multiplier: 1, timespan: 'hour', text: '1H' }}
            datafeed={datafeed}
            theme="dark"
            style={{ width: '100%', height: 360 }}
          />
        </>
      )
    }
    Running: the buttons control the chart
    Loads when scrolled into view
    MethodWhat it does
    setSymbol(symbol) / getSymbol()change or read the symbol
    setPeriod(period) / getPeriod()change or read the timeframe
    setTheme('dark' | 'light' | 'high-contrast')switch the theme
    setStyles(styles)change chart styles, such as the chart type
    serializeState() / loadState(state)save and restore the chart, drawings included

    Saving the user's chart is two calls. serializeState() returns plain JSON, so it goes anywhere: localStorage, a URL, or your database.

  9. Faster and offline (optional)

    Both features are off by default. Turn them on when you need them.

    History cache

    Remembers loaded bars in the browser, so a reload only fetches what is new and the chart still opens when the data source is down.

    tsx
    <AstroneumChart historyCache /* ...other props... */ />

    Indicator workers

    For very long histories (tens of thousands of bars), this moves heavy indicator maths off the main thread so scrolling stays smooth.

    tsx
    import { configureIndicatorWorkers } from 'astroneum'
    
    configureIndicatorWorkers({ enabled: true }) // MA, EMA, RSI and BOLL, 20,000+ bars

    See Speed and offline for a live look at the cache.

  10. Ship it

    Next.js

    Add the package to transpilePackages, and render the chart from a client component:

    ts
    // next.config.ts
    const nextConfig = { transpilePackages: ['astroneum'] }
    export default nextConfig
    tsx
    // app/components/Chart.tsx
    'use client'
    import { AstroneumChart } from 'astroneum'
    import 'astroneum/style.css'
    // ...

    The package is safe to import on the server (it does not touch window at import time), so server-side rendering will not crash. The chart itself draws in the browser.

    Everything else

    Build as usual. The CSS file is separate (astroneum/style.css) so you control how it loads. Optional features are separate imports, so apps that do not use them do not pay for them:

    ImportAdds
    astroneumthe chart and the common datafeeds
    astroneum/replaybar replay
    astroneum/multichartmulti-chart grids
    astroneum/datafeeds/cryptothe crypto datafeed on its own
    astroneum/datafeeds/polygonPolygon.io datafeeds
    astroneum/datafeeds/webtransportexperimental WebTransport datafeed

Troubleshooting

What you seeWhyFix
Nothing renders, no errorThe container has no heightSet style={{ height: 560 }} or give the parent a height
The chart looks broken or unstyledThe CSS is missingimport 'astroneum/style.css' once in your app
window is not definedRendering on the serverIn Next.js, put the chart in a component marked 'use client'
Empty chart, no barsgetHistoryData returned nothing or threwLog what it returns; times are in milliseconds, oldest first
Chart never updates livesubscribe never calls callbackCall callback(bar) with the same or a newer timestamp
A new bar shows up in the wrong placeTimestamps are in secondsMultiply by 1000
Switching to Renko or Heikin-Ashi shows the old chartThe chart keeps its first datafeedGive the chart a different key for each datafeed
Unsupported engine on installNode is older than 22Upgrade Node
Crypto data does not loadA network or region block on the exchangeTry another symbol, or use your own datafeed