Skip to main content

Getting started with Altrady Charts

Altrady Charts is a charting library you build into your own web app. It has a class-based API that works in any framework (React, Vue, Angular, Svelte or plain JavaScript): you give it a DOM element and a data source, and it renders a full chart UI with drawing tools, indicators and more.

This guide gets you from download to a live chart fed by the Altrady Data API. Every option and method is described in the TypeScript types that ship in the package (index.d.ts), and its README.md gives an overview.

1. Get the library​

  1. On the Charts page, pick your edition (Community is free; Pro and Enterprise need a subscription or offer).
  2. Read and accept the licence for that edition. Downloads unlock after that.
  3. Download the .tgz of the latest version and commit it to your private repository, for example under vendor/. The licence does not allow publishing the builds.
  4. Check the file against the SHA-256 shown on the Charts page:
shasum -a 256 vendor/altrady-charts-pro-0.1.3.tgz
  1. Add it to your project:
pnpm add ./vendor/altrady-charts-pro-0.1.3.tgz
# npm install ./vendor/altrady-charts-pro-0.1.3.tgz
# yarn add file:./vendor/altrady-charts-pro-0.1.3.tgz

The package name depends on your edition:

EditionPackageStylesheet
Community@altrady/charts@altrady/charts/styles
Pro@altrady/charts-pro@altrady/charts-pro/styles
Enterprise@altrady/charts-enterprise@altrady/charts-enterprise/styles

The examples below use @altrady/charts; use your edition's package name instead. The Enterprise package expects React from your app as a peer dependency; Community and Pro bundle their own.

2. Your first chart​

Give the chart an element with a size:

<div id="chart" style="height: 600px"></div>

Then create it with a dataLoader built from a datafeed (step 3 shows a real one):

import { AltradyCharts, createDataLoader } from "@altrady/charts"
import "@altrady/charts/styles"

const chart = new AltradyCharts({
container: "chart",
symbol: { ticker: "BINA_USDT_BTC", pricePrecision: 2, volumePrecision: 5 },
period: { type: "hour", span: 1, text: "1H" },
dataLoader: createDataLoader(datafeed),
theme: "dark",
})

// When your view unmounts:
chart.dispose()

3. Feed it with the Altrady Data API​

The chart asks a datafeed for history (getBars) and live updates (subscribeBars). With @altrady/data, the Altrady Data JavaScript SDK, that is a few lines:

pnpm add @altrady/data

Get a token on your backend. Create an API key on the API keys page, then exchange it for a token. Keep the client secret on your server, never in the browser:

curl -X POST https://data.altrady.com/oauth/token \
-d client_id=YOUR_KEY_ID \
-d client_secret=YOUR_SECRET

Create the client in the browser with that token:

import { AltradyData } from "@altrady/data"

// Talks to the Altrady Data gateway (data-gateway.altrady.com) by default.
const client = new AltradyData(token)

Write the datafeed. Markets use Altrady Data symbols in the form EXCHANGE_QUOTE_BASE, for example BINA_USDT_BTC (BTC priced in USDT on Binance).

const RESOLUTIONS = ["1", "5", "15", "60", "240", "1D", "1W"]
const live = new Map() // subscriberUID -> { params, handler }

const toBar = (c) => ({
time: c.time.getTime(), // the chart wants milliseconds
open: c.open, high: c.high, low: c.low, close: c.close,
volume: c.baseVolume,
})

const datafeed = {
onReady: (callback) =>
setTimeout(() => callback({ supportedResolutions: RESOLUTIONS }), 0),

// Optional: hook this up to your own market list (see AltradyDataCache in @altrady/data).
searchSymbols: (_input, _exchange, _type, onResult) => onResult([]),

resolveSymbol: (symbol, onResolve) =>
setTimeout(() => onResolve({
ticker: symbol,
name: symbol,
pricescale: 100, // 2 decimals; use 10 ** market.precisionPrice for the real value
has_intraday: true,
has_daily: true,
supported_resolutions: RESOLUTIONS,
}), 0),

getBars: async (symbolInfo, resolution, { from, to }, onResult, onError) => {
try {
const candles = await client.fetchCandles({
coinraySymbol: symbolInfo.ticker, resolution, start: from, end: to,
})
onResult(candles.map(toBar), { noData: candles.length === 0 })
} catch (error) {
onError(String(error))
}
},

subscribeBars: (symbolInfo, resolution, onTick, subscriberUID) => {
const params = { coinraySymbol: symbolInfo.ticker, resolution }
const handler = ({ candle }) => onTick(toBar(candle))
live.set(subscriberUID, { params, handler })
client.subscribeCandles(params, handler)
},

unsubscribeBars: (subscriberUID) => {
const sub = live.get(subscriberUID)
if (sub) client.unsubscribeCandles(sub.params, sub.handler)
live.delete(subscriberUID)
},
}

Tokens expire after 30 days (sooner on a trial). Register a refresh callback so the client asks your backend for a new one:

client.onTokenExpired(async () => await fetchFreshTokenFromYourBackend())
client.checkToken()

4. What your edition adds​

Pro adds trading from the chart. For example, show an open order as a draggable line:

import { createOrderLine } from "@altrady/charts-pro"

const line = createOrderLine(chart.getChart()!, {
price: 49500,
text: "Buy 0.5 BTC",
quantity: "0.5 BTC",
onCancel: () => cancelOrder(orderId),
onModify: (event) => modifyOrder(orderId, event?.overlay.points[0].value),
})

Price alerts work the same way with createPriceAlert. The order handles (cursor +, order drafts, trade menu) are behind the trade_overlay feature flag: turn it on and handle what users do with the onTradeAction option.

Enterprise adds positions, multi-chart layouts, user scripts, bar replay and white-label branding. For example, start with two charts side by side:

const charts = new AltradyCharts({ container: "chart", symbol, period, dataLoader, layout: "2-cols" })
charts.setLayoutSync({ interval: true, crosshair: true })

The package's TypeScript types list every feature of your edition, including smart positions, script providers and the brand option for white-label.

5. Upgrading​

Download the new version from the Charts page, replace the file in vendor/, and point your package.json at it. Check the changes listed with each version first.

6. Keep within the licence​

  • Community and Pro: keep the Altrady Charts watermark on the chart, and put one "Charts by Altrady" link to https://www.altrady.com/charting-library on your public website (or the about screen of an app without one).
  • Enterprise: you may change or remove the watermark and the credit.
  • All editions: keep the builds private and keep the license and third-party notices with the files.

The full terms are on the Charts page, under each edition's licence.