Skip to main content

Chart storage

Use ChartStorageAdapter to persist chart workspace layouts, drawings, templates, user settings, and replay state. This adapter does not persist the outer widget panel arrangement. Use Widget layout storage for WidgetLayoutState.

Choose an integration path

PathUse it whenIntegrator action
Local browser storageState only needs to survive in one browserUse the default adapter or configure createLocalChartStorageAdapter
Built-in REST adapterYour backend can implement the SDK's fixed HTTP contractConfigure createRestChartStorageAdapter, then implement the documented routes
Custom chart storage adapterYou already have different REST routes, GraphQL, RPC, broker storage, or pushed drawing updatesImplement the required ChartStorageAdapter method families directly

Use one implementation as the authority for each object family. Do not expose two competing implementations of the same ChartStorageAdapter method.

Use local browser storage

The default chart storage adapter stores one same-origin JSON document under tradescript:chart-storage:v1. Use an application-specific key when multiple products share an origin:

import { createLocalChartStorageAdapter } from '@tradescript/pro/sdk';

const storage = createLocalChartStorageAdapter({
key: 'my-app:chart-storage:v1',
});

Missing user and workspace context use the local and default scopes. Invalid stored JSON resets to empty state. When browser storage is unavailable, the fallback is process memory and does not survive reload.

This whole-document read/modify/write path is suitable for demos, prototypes, and single-browser products. It is not an authenticated multi-user backend.

Use the built-in REST contract

createRestChartStorageAdapter owns HTTP requests, per-request headers, query context, response envelopes, and documented error mapping. Your server must implement its exact routes for:

  • chart workspace layouts;
  • separate drawings and drawing permissions;
  • chart, indicator, and drawing templates;
  • user settings;
  • replay state.

Open REST chart storage adapter for the route, wire field, payload, identity, and conflict contract.

Implement a custom chart storage adapter

Implement ChartStorageAdapter directly when the built-in REST convention does not match your backend. Method presence defines capability, so implement a complete lifecycle for each product feature and omit unsupported methods.

Open Custom chart storage adapter for an authenticated chart workspace layout example, outcome rules, and drawing-subscription teardown requirements.

Add chart image storage when needed

If users add local image drawings, pass a separate ChartImageStorageAdapter. It uploads inline image bytes before ChartStorageAdapter saves the parent chart workspace layout, drawing record, or template JSON.

Open Chart image storage for the upload and file-lifecycle contract.

Verify the selected path

  • Check chart.getStorageCapabilities() after mounting. Every enabled value must correspond to a callable adapter method.
  • Treat browser-supplied user, workspace, chart, and chart workspace layout ids as routing context, not authorization.
  • Return null only when a load finds no record. Reject permission, transport, timeout, and validation failures.
  • Preserve the server-assigned storageId when a chart workspace layout moves from create to update.
  • Release custom drawing subscriptions when their chart context changes or the chart is destroyed.

Then run Test chart storage against a production-shaped backend.

Next steps