π GoCharting SDK - API Reference
Complete API documentation for the GoCharting SDK.
π API Documentation
Core API
- Chart API - Main
createChart()function for chart creation - Chart Widget - ChartInstance and ChartWrapper methods for programmatic control
- Datafeed API - Interface for implementing custom data sources
- Custom Feed - Example implementation of datafeed object
Configuration
- Chart Configuration - Complete ChartConfig options
- Theme Configuration - Styling and appearance options
- Trading Configuration - Trading-specific settings and integration
Utilities
- 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 symbolInfo = {
symbol: symbolName,
full_name: symbolName,
description: symbolName,
exchange: "EXCHANGE",
type: "stock",
// ... other required fields
};
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",
});Essential Methods
// ChartWrapper methods (returned by createChart)
chart.destroy(); // Clean up and destroy the chart
chart.isDestroyed(); // Check if chart is destroyed
const chartInstance = chart.getChartInstance(); // Get the ChartInstance
// ChartInstance methods (from chart.getChartInstance() or onReady callback)
chartInstance.setSymbol("MSFT"); // Change symbol
chartInstance.setInterval("1H"); // Change interval
chartInstance.setTheme("dark"); // Change theme
chartInstance.resize(800, 600); // Resize chart
// Trading integration
chartInstance.setBrokerAccounts({
accountList: [{ id: "1", name: "Account 1", balance: 10000, currency: "USD" }],
orderBook: [],
tradeBook: [],
positions: [],
});
// Multichart methods (for multi-chart layouts)
chartInstance.setChartSymbolAtIndex("GOOGL", 0); // Change symbol of chart at index 0
chartInstance.setIntervalAtIndex("5m", 1); // Change interval of chart at index 1
// Settings and state management
chartInstance.updateSettings({ zone: "America/New_York", showGrid: true });
const state = chartInstance.getChartState(); // Get complete chart state
chartInstance.setChartState(state); // Restore chart state
// Resubscribe after reconnection
chartInstance.resubscribeAll(); // Resubscribe to all data feedsπ Method Categories
ChartWrapper Methods (Lifecycle Management)
destroy()- Clean up and destroy the chartisDestroyed()- Check if chart is destroyedgetChartInstance()- Get the underlying ChartInstance
ChartInstance Methods - Basic Control
setSymbol(symbol)- Change the displayed symbolsetInterval(interval)- Change the time intervalsetTheme(theme)- Change the chart theme (βlightβ or βdarkβ)resize(width, height)- Resize the chartdestroy()- Clean up and destroy the chart
ChartInstance Methods - Multichart
setChartSymbolAtIndex(symbol, chartIdx)- Change symbol of specific chartsetIntervalAtIndex(interval, chartIdx)- Change interval of specific chartaddIndicatorAtIndex(indicator, chartIdx)- Add indicator to specific chartaddDrawingAtIndex(drawing, chartIdx)- Add drawing to specific chartdeleteObjectAtIndex(objectId, chartIdx)- Delete object from specific chartupdateSettingsAtIndex(settings, chartIdx)- Update settings of specific chartgetChartStateAtIndex(chartIdx)- Get state of specific chartsetChartStateAtIndex(state, chartIdx)- Set state of specific chart
ChartInstance Methods - Indicators & Drawings
addIndicator(indicator)- Add indicator to current chartaddDrawing(drawing, chartId?)- Add drawing to current chartdeleteObject(objectId, chartId?)- Delete indicator or drawing
ChartInstance Methods - Settings & State
updateSettings(settings)- Update chart settings (timezone, grid, etc.)getChartState()- Get complete chart statesetChartState(state)- Restore chart stateresubscribeAll(idToken?)- Resubscribe to all data feeds after reconnection
ChartInstance Methods - Trading
setBrokerAccounts(data)- Set trading account data (accounts, orders, trades, positions)
π§ 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
// ========================================================================
// Display Options
// ========================================================================
theme?: "light" | "dark"; // Chart theme (default: "light")
themeColor?: string; // Theme color (e.g., "dark", "#1a1a1a")
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
// ========================================================================
debugLog?: boolean; // Enable debug logging (default: false)
disableSearch?: boolean; // Hide search bar (default: false)
disableCompare?: boolean; // Hide compare button (default: false)
hideDrawingToolBar?: boolean; // Hide drawing toolbar (default: false)
alwaysDrawMode?: boolean; // Enable always draw mode (default: false)
// ========================================================================
// Configuration Overrides
// ========================================================================
defaultInitialChartConfig?: DefaultInitialChartConfig; // Override default settings
trading?: TradingConfig; // Trading configuration
popups?: PopupsConfig; // Popup preferences
favourite?: FavouriteConfig; // Favorite symbols/intervals/indicators
exclude?: ExcludeOptions; // Exclude UI elements
// ========================================================================
// Event Callbacks
// ========================================================================
appCallback?: AppCallbackEventHandler; // Trading and app events
onReady?: OnReadyEventHandler; // Chart ready callback
onError?: OnErrorEventHandler; // Error callback
}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 | Resolution,
onRealtimeCallback: (data: Bar | Tick) => void,
subscriberUID: string,
onResetCacheNeededCallback?: () => void,
): void;
unsubscribeTicks?(subscriberUID: string): void;
getMarks?(
symbolInfo: SymbolInfo,
from: number,
to: number,
onDataCallback: (marks: Mark[]) => void,
resolution: string | Resolution,
): void;
getTimescaleMarks?(
symbolInfo: SymbolInfo,
from: number,
to: number,
onDataCallback: (marks: TimescaleMark[]) => void,
resolution: string | Resolution,
): 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 symbolInfo = {
symbol: symbolName,
full_name: symbolName,
description: symbolName,
exchange: "API",
type: "crypto",
// ... other required fields
};
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: (eventType, message, onClose) => {
console.log("Trading event:", eventType, message);
// Handle trading events (place order, modify order, etc.)
},
onReady: (chartInstance) => {
// Set broker accounts when chart is ready
chartInstance.setBrokerAccounts({
accountList: [
{
id: "123",
name: "Trading Account",
balance: 10000,
currency: "USD",
},
],
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']
}π Related Documentation
- Getting Started - Quick start guide
- React + TypeScript Example - Complete implementation example
- Vanilla JavaScript Example - Pure JavaScript implementation
- TypeScript Types - Complete type definitions
π Need Help?
- Email: admin@gocharting.com
- Documentation: gocharting.com/sdk/docsΒ
- GitHub: github.com/gocharting/sdkΒ
- Discord: gocharting.com/discordΒ
For detailed method documentation, click on the specific API sections above.
Last updated on