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
| Path | Use it when | Integrator action |
|---|---|---|
| Local browser storage | State only needs to survive in one browser | Use the default adapter or configure createLocalChartStorageAdapter |
| Built-in REST adapter | Your backend can implement the SDK's fixed HTTP contract | Configure createRestChartStorageAdapter, then implement the documented routes |
| Custom chart storage adapter | You already have different REST routes, GraphQL, RPC, broker storage, or pushed drawing updates | Implement 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
nullonly when a load finds no record. Reject permission, transport, timeout, and validation failures. - Preserve the server-assigned
storageIdwhen 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
- REST chart storage adapter — implement the built-in HTTP contract.
- Custom chart storage adapter — connect an existing transport or add pushed drawing updates.
- Chart image storage — upload inline image drawings before parent JSON persistence.
- Test chart storage — prove enabled chart-storage operations end to end.