Extend the datafeed to Trading Platform
Overview
This sub-tutorial builds on the Connect data via Datafeed API tutorial. There, you implemented a Binance-backed datafeed for Advanced Charts. Here, you will reuse that exact datafeed to power a full Trading Platform experience: broker trading, the DOM (depth of market), live watchlist quotes, save/load persistence, custom price alerts, and a news feed.
Complete the Advanced Charts datafeed tutorial first.
This section assumes you already have a working src/datafeed/ (datafeed, helpers, streaming) and a shared src/widget-options.js.
What is different about Trading Platform
Trading Platform is a paid superset of Advanced Charts. It ships as a separate runtime package and adds trading-specific UI (account manager, order tickets, DOM, positions) on top of the chart.
The same datafeed serves both products, but Trading Platform asks the datafeed for more:
| Capability | Advanced Charts | Trading Platform |
|---|---|---|
Chart data (onReady, resolveSymbol, getBars, subscribeBars, etc.) | ✅ | ✅ |
Quotes (getQuotes, subscribeQuotes, unsubscribeQuotes) | — | ✅ |
Depth of market (subscribeDepth, unsubscribeDepth) | — | ✅ |
Broker integration (broker_factory, broker_config) | — | ✅ |
| Save/load, news, widgetbar | — | ✅ |
In the Advanced Charts tutorial you saw that the AC page strips the quote and depth methods from the datafeed clone. Trading Platform passes the full datafeed through instead, so those methods become available.
Install the Trading Platform runtime
Trading Platform lives in a different private repository.
The install helper downloads it (and, importantly, still installs Advanced Charts so the / page keeps working) and the BrokerDemo sample bundle used for trading:
npm run tv:install:tp -- 31.2.0
This places:
vendor/tradingview/trading_platform/charting_library.esm.js
third_party/tradingview/broker-sample/dist/bundle.js
If you place the package manually, copy trading_platform-master/charting_library/ into the project root and run npm run tv:sync, then copy the broker sample bundle into third_party/tradingview/broker-sample/dist/bundle.js.
Start the project and open the trading page:
npm run start
http://127.0.0.1:3000/trading
npm run start, not the static serverThe news feed is proxied same-origin through server.mjs (see Save/load, news, and watchlist).
The static fallback (npm run start:static) serves the chart but cannot load news.
The trading page entry point
The Trading Platform page has its own HTML and bootstrap (trading.html → src/trading.js).
The bootstrap imports the Trading Platform ESM runtime and the BrokerDemo bundle, then builds the widget with trading options:
import Datafeed from './datafeed/datafeed.js';
import { LocalStorageSaveLoadAdapter } from './save-load-adapter.js';
import { createTradingPlatformOptions } from './widget-options.js';
import { widget as createWidget } from '/vendor/tradingview/trading_platform/charting_library.esm.js';
// Side-effect import: exposes globalThis.Brokers.BrokerDemo
import '../third_party/tradingview/broker-sample/dist/bundle.js';
createTradingPlatformOptions (in widget-options.js) reuses the shared base options and adds Trading Platform featuresets, the news feed, and the Trading Platform library path:
const TRADING_PLATFORM_ENABLED_FEATURES = [
'dom_widget',
'saveload_separate_drawings_storage',
'pre_post_market_price_line',
'legend_last_day_change',
];
const TRADING_PLATFORM_DISABLED_FEATURES = [
'open_account_manager',
'show_right_widgets_panel_by_default',
];
export function createTradingPlatformOptions(options = {}) {
return createWidgetOptions({
...options,
// Note: the full Datafeed (with quotes + depth) is used here, not the stripped clone.
libraryPath: 'vendor/tradingview/trading_platform/',
rss_news_feed: CRYPTO_RSS_NEWS_FEED,
rss_news_title: CRYPTO_RSS_TITLE,
enabledFeatures: [...TRADING_PLATFORM_ENABLED_FEATURES, ...(options.enabledFeatures ?? [])],
disabledFeatures: [...TRADING_PLATFORM_DISABLED_FEATURES, ...(options.disabledFeatures ?? [])],
});
}
Where to go next
This sub-tutorial is split into three parts that you can follow in order:
- Broker integration — wire up
broker_factory/broker_configwith the BrokerDemo sample and enable trading features. - Quotes and the DOM — implement
getQuotes/subscribeQuotesfor the watchlist andsubscribeDepthfor the Depth of market widget. - Save/load, news, and watchlist — save and load charts with a localStorage adapter, then add the news and watchlist widgets.