OneKey TradingView bridge communication for WebView/iframe messages, K-line data, marks, Perps symbols/lines, order events, and websocket recovery.
73
91%
Does it follow best practices?
Run evals on this skill
Adds up to 20 points to the overall score
View guide
Medium
Suggest reviewing before use
Use this to avoid re-discovering the bridge between the OneKey app repository and the separate TradingView chart repository. Do not assume fixed local filesystem paths; locate files by symbol names with rg.
The app loads the chart app inside WebView/iframe and both sides exchange plain message objects.
$private payloads with scope, origin, method, and data.webRef.current.sendMessageViaInjectedScript(message), which lands in the chart as window.postMessage(message).postMessage; native/desktop injects a script that calls window.postMessage(...).Start with rg instead of assuming local paths.
App repo anchors:
useTradingViewUrlTradingViewV2useTradingViewMessageHandlerhandleKLineDataRequest, fetchAccountTransactionMarksuseAutoKLineUpdate, useTradingViewV2WebSocketTradingViewPerpsV2usePerpsTradingViewMessageHandleruseChartLines, buildAllLinesForSymbolsendMessageViaInjectedScript, createMessageInjectedScript, InpageProviderWebView, NativeWebView, DesktopWebViewfetchMarketTokenKline, fetchMarketAccountTokenTransactions, subscribeOHLCV, getTradingviewMidPrice, setTradingviewDisplayPriceScaleTRADING_VIEW_URL, TRADING_VIEW_URL_TESTChart repo anchors:
getBusinessTypeFromUrl, shouldUseFastBootstrapFromUrlTradingViewWidget, ChartManagersendMessage, createDefaultPayload, requestHistoryData, getHyperliquidPriceScale, getMarksDatasetupSymbolChangeListener, publishActiveSymbol, symbolDisplayStateOnekeyDatafeedHyperliquidDatafeed, HyperliquidWebSocketmarksListener, MarksManagersetupPerpsLinesListener, PerpsLinesManagerMETHOD_TYPES, PERPS_TV_MESSAGE_TYPES, ITVLineTreat the TradingView library static asset directory in the chart repo as vendor assets. Do not edit it for bridge changes.
App URL generation is centralized in useTradingViewUrl.
Common params:
timezone, locale, platform, theme, optional appVersion.decimal, networkId, address, symbol, type=market, storageNamespace=market.scene=market-hyperliquid, storageNamespace=market-hyperliquid.symbol, type=perps, storageNamespace=perps, enablePerpsTradingUi.Perps freezes the initial URL symbol and sends later changes via SYMBOL_CHANGE to avoid WebView reloads.
Chart requests history with:
{
scope: '$private',
method: 'tradingview_getKLineData',
data: {
method: 'tradingview_getHistoryData',
resolution,
from,
to,
firstDataRequest,
},
}App handles it in useTradingViewMessageHandler -> handleKLineDataRequest() and fetches serviceMarketV2.fetchMarketTokenKline().
App replies:
{
type: 'kLineData',
payload: {
type: 'history',
kLineData,
requestData,
},
}Realtime market updates are app-pushed with type: 'autoKLineUpdate' and payload.type: 'realtime'.
Request/response:
method: 'tradingview_getMarks' with requestId, symbol, from, to, resolution.type: 'MARKS_RESPONSE', payload: { marks, requestId }.Push updates:
type: 'MARKS_UPDATE', payload: { symbol, operation, marks }.operation is incremental, replace, or clear.Market marks come from account token transactions. Perps marks come from Hyperliquid fills.
Chart requests:
{
scope: '$private',
method: 'tradingview_getHyperliquidPriceScale',
data: { symbol, requestId },
}App responds:
{
type: 'HYPERLIQUID_PRICESCALE_RESPONSE',
payload: { priceScale, minmov: 1, requestId },
}The app calculates from current mid price with calculateDisplayPriceScale() and caches the result through serviceHyperliquid.setTradingviewDisplayPriceScale().
App sends:
{
type: 'SYMBOL_CHANGE',
payload: {
symbol,
displayPair,
displayCoin,
force,
},
}Chart handles it in setupSymbolChangeListener(). Display labels are cached by raw symbol in symbolDisplayState; do not key Hyperliquid API calls off display labels.
App -> chart:
PERPS_TV_LINES_SYNC: full state { symbol, revision, lines }.PERPS_TV_LINES_PATCH: diff { symbol, revision, add, update, remove }.PERPS_TV_LINES_CLEAR: { symbol }.PERPS_TV_ORDER_PRICE_UPDATE_REJECTED: rollback for failed drag amend.Chart -> app:
tradingview_perpsReady: chart lines can be sent.tradingview_perpsOrderCancel: user clicked order-line cancel.tradingview_perpsOrderDraftCreate: plus/context menu placed a draft order.tradingview_perpsOrderPriceUpdate: user dragged a limit order line.tradingview_chartExpand: chart expand/collapse state.The chart serializes sync/patch processing because TradingView line creation is async.
Current app default: PerpCandles sets enablePerpsTradingUi = false, so order draft/cancel/drag UI paths may exist but are not enabled in normal perps candles.
type: 'FORCE_RECOVER_WS' after Hyperliquid WebSocket recovery. Chart validates origin before reconnecting subscriptions.method: 'tradingview_touchScroll' with { deltaY } so app layouts can scroll around the embedded chart.When adding or changing a message:
requestId for async request/response flows.window.message listener.sendMessage() and handle in the relevant app message handler.revision ordering and symbol normalization.$private bridge routing, trading enablement checks, order reject rollback, or origin checks.yarn agent:check --profile commit.npm run build or yarn build from the chart repo root; run npm run lint or yarn lint when touching lint-sensitive code.localhost:5173 (10.0.2.2:5173 for Android emulator).d71e6b7
If you maintain this skill, you can claim it as your own. Once claimed, you can manage eval scenarios, bundle related skills, attach documentation or rules, and ensure cross-agent compatibility.