1k tradingview communication

From OneKeyHQ/app-monorepo · View interactive version

1k tradingview communication is an AI agent skill from the GitHub repository OneKeyHQ/app-monorepo. OneKey TradingView bridge communication for WebView/iframe messages, K-line data, marks, Perps symbols/lines, order events, and websocket recovery.

How to use this skill

Skill file

TradingView Communication

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.

Mental Model

The app loads the chart app inside WebView/iframe and both sides exchange plain message objects.

Search Anchors

Start with rg instead of assuming local paths.

App repo anchors:

Chart repo anchors:

Treat the TradingView library static asset directory in the chart repo as vendor assets. Do not edit it for bridge changes.

URL Parameters

App URL generation is centralized in useTradingViewUrl.

Common params:

Perps freezes the initial URL symbol and sends later changes via SYMBOL_CHANGE to avoid WebView reloads.

Message Contracts

Market Kline

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'.

Marks

Request/response:

Push updates:

Market marks come from account token transactions. Perps marks come from Hyperliquid fills.

Hyperliquid Price Scale

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().

Perps Symbol Sync

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.

Perps Lines

App -> chart:

Chart -> app:

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.

Recovery And Touch Scroll

Change Checklist

When adding or changing a message:

  1. Update constants/types on both sides, not just one repo.
  2. Preserve requestId for async request/response flows.
  3. Keep the payload shape stable for older app/chart builds where possible.
  4. For app -> chart messages, add or update a chart-side window.message listener.
  5. For chart -> app messages, route through sendMessage() and handle in the relevant app message handler.
  6. For perps lines, respect revision ordering and symbol normalization.
  7. For Hyperliquid symbols, use the raw coin id for API/cache keys. Display labels are UI-only.
  8. Do not bypass $private bridge routing, trading enablement checks, order reject rollback, or origin checks.
  9. Test both web iframe and native/desktop injected-script behavior when bridge mechanics change.

Verification

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.