Skip to Content
API ReferenceOverview

GoCharting SDK - API Reference

Complete API documentation for the GoCharting SDK.

API Documentation

Core API

Chart API — main createChart() function and ChartInstance methods

GoCharting Component — declarative GoCharting React component

Chart Widget — chart instance methods for programmatic control

Datafeed API — interface for custom data sources

Custom Feed — example datafeed implementation

Chart / API surface

  • Widget façadeactiveChart / Phase 0–1E (viewport, shapes, studies, trading lines, events & actions)

Configuration

Chart Configuration — complete ChartConfig options

Theme Configuration — styling and appearance options

Trading Configuration — trading-specific settings and integration

Utilities

Enums & literal unions — catalog of real GoCharting union types

Event System — chart events and callbacks (appCallback, onReady, onError)

Helper Functions — utility functions and constants

Type Definitions — TypeScript type definitions

Quick Reference

Basic Usage

import { createChart } from "@gocharting/chart-sdk"; // Create custom datafeed object (no class inheritance needed) const myDatafeed = { async getBars(symbolInfo, resolution, periodParams) { // Fetch historical bars from your API const response = await fetch(`/api/bars?symbol=${symbolInfo.symbol}`); const data = await response.json(); return { bars: data }; }, resolveSymbol(symbolName, onResolve, onError) { // Resolve symbol information const parts = String(symbolName).split(":"); const exchange = parts[0] || "NASDAQ"; const segment = parts.length >= 3 ? parts[1] : "EQUITY"; const symbol = parts[parts.length - 1] || "AAPL"; const name = symbol; const validIntervals = ["1m", "5m", "15m", "1h", "1D"]; const symbolInfo = { exchange, segment, symbol, name: symbol, asset_type: "EQUITY", source_id: symbol, tradeable: true, is_index: false, is_formula: false, delay_seconds: 0, data_status: "streaming", contract_size: 1, tick_size: 0.01, display_tick_size: 0.01, volume_size_increment: 1, max_tick_precision: 2, max_volume_precision: 0, quote_currency: "USD", supports: { footprint: false }, exchange_info: { name: exchange.toLowerCase(), code: exchange, country_cd: "US", zone: "America/New_York", hours: [ { open: false }, { open: true }, { open: true }, { open: true }, { open: true }, { open: true }, { open: false }, ], valid_intervals: validIntervals, }, ticker: symbol, full_name: `${exchange}:${segment}:${symbol}`, description: name, type: "stock", session: "0930-1600", timezone: "America/New_York", has_intraday: true, has_daily: true, supported_resolutions: validIntervals, }; onResolve(symbolInfo); }, }; // Initialize chart with simplified API const chart = createChart("#chart", { symbol: "AAPL", interval: "1D", datafeed: myDatafeed, licenseKey: "YOUR_LICENSE_KEY", trading: { enableTrading: true, }, theme: "dark", });

React Usage (Declarative)

import { GoCharting } from "@gocharting/chart-sdk"; function App() { return ( <GoCharting symbol="AAPL" interval="1D" datafeed={myDatafeed} licenseKey="YOUR_LICENSE_KEY" theme="dark" height="600px" /> ); }

See the GoCharting Component page for props and ref-based imperative access.

Essential Methods

// Lifecycle chart.destroy(); // Clean up and destroy the chart chart.isDestroyed(); // Check if chart is destroyed // Chart control chart.setSymbol("MSFT"); // Change symbol chart.setInterval("1h"); // Change interval chart.setTheme("dark"); // Change theme chart.setChartType("line"); // Change chart type chart.resize(800, 600); // Not yet implemented — currently throws; the chart auto-sizes via AutoFit, so resize the container instead chart.goToDate("2025-06-01"); // Jump to a date chart.setTimezone("America/New_York"); // Set timezone // Trading integration chart.setBrokerAccounts({ accountList: [{ account_id: "ACCOUNT_001", currency: "USD", balance: 10000 }], orderBook: [], tradeBook: [], positions: [], }); chart.updatePositions(partialUpdates); // Currently no-ops — use setBrokerAccounts() until implemented // Multichart methods (for multi-chart layouts) chart.setChartSymbolAtIndex("GOOGL", 0); // Change symbol of chart at index 0 chart.setIntervalAtIndex("5m", 1); // Change interval of chart at index 1 // Settings and state management chart.updateSettings({ zone: "America/New_York", showGrid: true }); const state = chart.getChartState(); // Get complete chart state chart.setChartState(state); // Restore chart state // Resubscribe after reconnection chart.resubscribeAll(); // Resubscribe to all data feeds

Method Categories

The object returned by createChart() (a ChartInstance) exposes the following methods — see the Chart API for full documentation of each:

Lifecycle

  • destroy() - Clean up and destroy the chart
  • isDestroyed() - Check if chart is destroyed
  • getChartInstance() - Get the underlying chart component instance (advanced)

Widget façade

  • activeChart() / chart(index) — per-chart IChartApi (Phase 0–1E)
  • chartsCount() / activeChartIndex() / setActiveChart(index)
  • subscribe / unsubscribe / getAllCharts()

Chart Control

  • setSymbol(symbol) - Change the displayed symbol
  • setInterval(interval) - Change the time interval
  • setTheme(theme) - Change the chart theme (“light” or “dark”)
  • setChartType(chartType) - Change the chart type (candlestick, line, area, …)
  • resize(width, height) - Resize the chart (not yet implemented — currently throws; the chart auto-sizes via AutoFit, so resize the container instead)
  • goToDate(date) - Jump to a specific date or date range
  • setTimezone(timezone) - Set the chart timezone
  • getTimezonePresets() - Get available timezone presets
  • getCurrentTimezone() - Get the current timezone

Multichart (by index)

  • setChartSymbolAtIndex(symbol, chartIdx) - Change symbol of specific chart
  • setIntervalAtIndex(interval, chartIdx) - Change interval of specific chart
  • setChartTypeAtIndex(chartType, chartIdx) - Change chart type of specific chart
  • addIndicatorAtIndex(indicator, chartIdx) - Add indicator to specific chart
  • addDrawingAtIndex(drawing, chartIdx, chartId?) - Add drawing to specific chart
  • deleteObjectAtIndex(objectId, chartIdx, chartId?) - Delete object from specific chart
  • updateSettingsAtIndex(settings, chartIdx) - Update settings of specific chart
  • getChartStateAtIndex(chartIdx) - Get state of specific chart
  • setChartStateAtIndex(state, chartIdx) - Set state of specific chart

Indicators & Drawings

  • addIndicator(indicator) - Add indicator to current chart
  • addDrawing(drawing, chartId?) - Add drawing to current chart
  • deleteObject(objectId, chartId?) - Delete indicator or drawing

Settings & State

  • updateSettings(settings) - Update chart settings (timezone, grid, etc.)
  • getChartState() - Get complete chart state
  • setChartState(state) - Restore chart state
  • resubscribeAll(idToken?) - Resubscribe to all data feeds after reconnection

Templates

  • saveTemplate(templateName) - Save current indicators as a named template
  • applyTemplate(template) - Apply a template to the current chart
  • getTemplates() - Get all saved templates
  • deleteTemplate(templateId) - Delete a template by ID

Trading

  • setBrokerAccounts(data) - Set trading account data (accounts, orders, trades, positions)
  • updatePositions(positions) - Merge partial position updates (prices, PnL) without a full rebuild (currently no-ops — use setBrokerAccounts() until implemented)

OI Profile (Futures/Options)

  • setOIProfile(metric) - Set the OI Profile metric (‘oi’, ‘volume’, ‘delta’, ‘gamma’, ‘theta’, ‘vega’)
  • getOIProfileSettings() - Get current OI Profile settings

Configuration Options

ChartConfig Interface

{ // ======================================================================== // Required Properties // ======================================================================== datafeed: Datafeed; // Your datafeed implementation symbol: string; // Initial symbol (e.g., "AAPL", "BYBIT:FUTURE:BTCUSDT") interval: string; // Initial interval (e.g., "1m", "5m", "1D") licenseKey?: string; // Your SDK license key (required unless skipLicenseValidation) // ======================================================================== // Display Options // ======================================================================== theme?: "light" | "dark"; // Chart theme (default: "light") themeColor?: string; // Theme color override ("light" or "dark") autosize?: boolean; // Enable automatic resizing (default: true) width?: number | string; // Chart width (default: "100%") height?: number | string; // Chart height (default: "100%") locale?: string; // Locale (e.g., "en-US", "en") (default: "en-US") // ======================================================================== // Feature Flags // ======================================================================== skipLicenseValidation?: boolean; // Skip licenseKey requirement (demo only, default: false) debugLog?: boolean; // Enable debug logging (default: false) disableSearch?: boolean; // Hide search bar (default: false) disableCompare?: boolean; // Hide compare button (default: false) autoSave?: boolean; // Auto-save chart state to sessionStorage (default: true) showCrosshairPlusIcon?: boolean; // Show the crosshair plus icon (default: true) isNativeApp?: boolean; // Native WebView: hide JS bars; emit OPEN_CONTEXT_MENU (default: false) touchMode?: boolean; // Force full JS mobile Chart-tab shell (default: false) // ======================================================================== // Configuration Overrides // ======================================================================== defaultInitialChartConfig?: object; // Deep-merged chart configuration overrides trading?: TradingConfig; // Trading configuration (use trading.enableTrading) contextMenu?: object; // Context menu options override popups?: object; // Popup preferences favourite?: object; // Favorite symbols override exclude?: object; // Exclude UI elements // ======================================================================== // Event Callbacks // ======================================================================== appCallback?: (event: AppCallbackEvent) => void; // Trading and app events onReady?: (chartInstance) => void; // Chart ready callback onError?: (error) => void; // Error callback }

See the Configuration API for detailed descriptions of every option.

Datafeed Interface

interface Datafeed { // Required methods getBars( symbolInfo: SymbolInfo, resolution: string | Resolution, periodParams: PeriodParams, ): Promise<BarsResult | UDFResponse>; resolveSymbol( symbolName: string, onResolve: (symbolInfo: SymbolInfo) => void, onError: (error: string) => void, ): void; // Optional methods searchSymbols?( userInput: string, exchange: string, symbolType: string, onResultReadyCallback: (result: { searchInProgress: boolean; items: SearchResult[]; }) => void, ): void; subscribeTicks?( symbolInfo: SymbolInfo, resolution: string, onRealtimeCallback: (data: Bar | Tick | TradeMessage) => void, subscriberUID: string, onResetCacheNeededCallback?: () => void, ): void; unsubscribeTicks?(subscriberUID: string): void; getMarks?( symbolInfo: SymbolInfo, startDate: number, endDate: number, onDataCallback: (marks: Mark[]) => void, resolution: string | Resolution, ): void; getTimescaleMarks?( symbolInfo: SymbolInfo, from: number, to: number, onDataCallback: (marks: TimescaleMark[]) => void, resolution: string | Resolution, ): void; destroy?(): void; }

Common Use Cases

1. Basic Chart Setup

import { createChart } from "@gocharting/chart-sdk"; const chart = createChart("#chart", { symbol: "BTCUSD", interval: "1D", datafeed: myDatafeed, licenseKey: "YOUR_LICENSE_KEY", });

2. Custom Data Source

import { createChart } from "@gocharting/chart-sdk"; const apiDatafeed = { async getBars(symbolInfo, resolution, periodParams) { const response = await fetch(`/api/bars?symbol=${symbolInfo.symbol}`); const data = await response.json(); return { bars: data }; }, resolveSymbol(symbolName, onResolve, onError) { const parts = String(symbolName).split(":"); const exchange = parts[0] || "BYBIT"; const segment = parts.length >= 3 ? parts[1] : "FUTURE"; const symbol = parts[parts.length - 1] || "BTCUSDT"; const validIntervals = ["1m", "5m", "15m", "1h", "1D"]; const symbolInfo = { exchange, segment, symbol, name: "Demo Symbol", asset_type: "CRYPTO", source_id: symbol, pair: { from: "BTC", to: "USDT" }, tradeable: true, is_index: false, is_formula: false, delay_seconds: 0, data_status: "streaming", contract_size: 1, tick_size: 0.1, display_tick_size: 1, volume_size_increment: 0.001, max_tick_precision: 1, max_volume_precision: 3, quote_currency: "USDT", future_type: "PERP", supports: { footprint: true }, exchange_info: { name: exchange.toLowerCase(), code: exchange, zone: "UTC", hours: Array.from({ length: 7 }, () => ({ open: true })), valid_intervals: validIntervals, }, ticker: symbol, full_name: `${exchange}:${segment}:${symbol}`, description: "Demo Symbol", type: "crypto", session: "24x7", timezone: "UTC", has_intraday: true, has_daily: true, supported_resolutions: validIntervals, }; onResolve(symbolInfo); }, }; const chart = createChart("#chart", { symbol: "BTCUSD", interval: "1D", datafeed: apiDatafeed, licenseKey: "YOUR_LICENSE_KEY", });

3. Trading Integration

import { createChart } from "@gocharting/chart-sdk"; const chart = createChart("#chart", { symbol: "BTCUSD", interval: "1D", datafeed: myDatafeed, licenseKey: "YOUR_LICENSE_KEY", trading: { enableTrading: true, }, appCallback: (event) => { console.log("Trading event:", event.eventType, event.message); // Handle trading events (place order, modify order, etc.) if (event.eventType === "PLACE_ORDER") { // Call your broker API, then dismiss the SDK popup if (event.onClose) event.onClose(); } }, onReady: (chartInstance) => { // Set broker accounts when chart is ready chartInstance.setBrokerAccounts({ accountList: [ { account_id: "ACCOUNT_001", currency: "USD", balance: 10000, }, ], orderBook: [], tradeBook: [], positions: [], }); }, });

Data Formats

Bar Data Format

{ time: 1609459200000, // Unix timestamp in milliseconds open: 100.50, high: 102.75, low: 99.25, close: 101.80, volume: 1500000 }

Symbol Info Format

{ // Basic Information exchange: 'BYBIT', segment: 'FUTURE', symbol: 'BTCUSDT', name: 'BTC / USDT PERPETUAL FUTURES', asset_type: 'CRYPTO', source_id: 'BTCUSDT', // Pair Information pair: { from: 'BTC', to: 'USDT' }, // Trading Information tradeable: true, is_index: false, is_formula: false, // Data Feed Information delay_seconds: 0, data_status: 'streaming', // Price & Volume Precision tick_size: 0.1, display_tick_size: 1, volume_size_increment: 0.001, max_tick_precision: 1, max_volume_precision: 3, quote_currency: 'USDT', // Exchange Information exchange_info: { name: 'bybit', code: 'BYBIT', zone: 'UTC', valid_intervals: ['1m', '5m', '15m', '30m', '1h', '4h', '1D', '1W', '1M'] }, // Legacy/Compatibility Fields ticker: 'BTCUSDT', full_name: 'BYBIT:FUTURE:BTCUSDT', description: 'BTC / USDT PERPETUAL FUTURES', type: 'crypto', session: '24x7', timezone: 'UTC', has_intraday: true, supported_resolutions: ['1', '5', '15', '30', '60', '240', '1D'] }

Need Help?


For detailed method documentation, click on the specific API sections above.

Last updated on