開源圖表引擎
LP 風險畫布
在一張圖上呈現一個部位及其風險。集中流動性區間是從進場 K 棒起的色帶;10 倍空單避險以價格線標出開倉價與強平價。開倉、每次離開與回到區間,以及價格觸及時的強平,都是畫在確切價格上的 atPrice 標記。第二個窗格顯示部位相對於持有代幣的表現(無常損失)與避險後的損益,未計手續費:依初始 ETH 數量放空後,剩下的大致就是無常損失。
LP 風險畫布:DeFi 與 AMM範例
position: 'atPrice' · addBand · createPriceLine · addSeries('baseline')
程式碼
import { FerroChart } from '@ferrochart/core';
const canvas = document.querySelector('canvas');
// Market data: the synthetic FerroChart demo API. Use your own feed.
const chart = await FerroChart.create(canvas, { theme: 'dark' });
const bars = await fetch('/api/bars?symbol=ETHUSD&interval=1h&count=720').then((r) => r.json());
const candles = chart.addCandlestickSeries();
candles.setData(bars);
const n = bars.time.length;
// An ETH/USDC concentrated-liquidity position opened 12 days ago, ±8% around
// the entry, hedged two hours later with a 10x short of its ETH.
const entry = n - 288, p0 = bars.close[entry], pa = p0 * 0.92, pb = p0 * 1.08;
const amounts = (p) => { // ETH and USDC of one unit of liquidity at price p
const s = Math.sqrt(Math.min(Math.max(p, pa), pb));
return [1 / s - 1 / Math.sqrt(pb), s - Math.sqrt(pa)];
};
const [x0, y0] = amounts(p0);
const hedgeAt = entry + 2, ph = bars.close[hedgeAt], margin = (x0 * ph) / 10;
const liq = ph * (1 + 1 / 10 - 0.005); // maintenance margin 0.5%
// The range as a band from the entry bar; the short's entry and liquidation as price lines.
const edge = (price) => bars.time.map((t, i) => (i < entry ? NaN : price));
const style = { color: '#7ee787', lineWidth: 1, lineStyle: 'dashed', priceLineVisible: false, lastValueVisible: false };
const hi = chart.addSeries('line', style), lo = chart.addSeries('line', style);
hi.setData({ time: bars.time, value: edge(pb) });
lo.setData({ time: bars.time, value: edge(pa) });
chart.addBand(hi, lo, { fill: 'rgba(126, 231, 135, 0.08)' });
candles.createPriceLine({ price: ph, color: '#b388ff', title: 'short entry' });
candles.createPriceLine({ price: liq, color: '#ff5d73', lineStyle: 'solid', lineWidth: 2, title: 'short liquidation' });
// Events at the price they happened: the opens, the range exits and returns, a liquidation.
const at = (i, price, color, text) => ({ time: bars.time[i], position: 'atPrice', price, shape: 'circle', size: 9, color, text });
const markers = [at(entry, p0, '#7ee787', 'LP open'), at(hedgeAt, ph, '#b388ff', 'short')];
const lp = [], net = [];
let zone = 0, streak = 0, liquidated = false; // zone: -1 below the range, 0 in it, 1 above
for (let i = 0; i < n; i++) {
if (i < entry) { lp.push(NaN); net.push(NaN); continue; }
const p = bars.close[i], [x, y] = amounts(p);
if (i >= hedgeAt && !liquidated && bars.high[i] >= liq) { liquidated = true; markers.push(at(i, liq, '#ff5d73', 'liquidated')); }
const now = p > pb ? 1 : p < pa ? -1 : 0;
streak = now === zone ? 0 : streak + 1; // a new zone counts after 12 closes
if (streak === 12) {
const j = i - 11, edge = (now || zone) > 0 ? pb : pa;
markers.push(now ? at(j, edge, '#ffb547', 'out of range') : at(j, edge, '#2ee6b6', 'back in range'));
zone = now;
streak = 0;
}
const hedge = i < hedgeAt ? 0 : liquidated ? -margin : x0 * (ph - p);
lp.push(((x * p + y) / (x0 * p + y0) - 1) * 100); // against holding the tokens
net.push(((x * p + y + hedge) / (x0 * p0 + y0) - 1) * 100); // LP and short, of the capital
}
candles.setMarkers(markers.sort((a, b) => a.time - b.time));
// Second pane: what the position earns, before fees.
const pane = chart.addPane(0.5);
chart.addSeries('baseline', { baseValue: 0, color: '#2ee6b6', downColor: '#ff5d73', topFill: 'rgba(46, 230, 182, 0.2)', bottomFill: 'rgba(255, 93, 115, 0.2)', pricePrecision: 2 }, pane)
.setData({ time: bars.time, value: net });
chart.addSeries('line', { color: '#ffb547', lineWidth: 1.5, pricePrecision: 2 }, pane).setData({ time: bars.time, value: lp });
chart.applyPriceScaleOptions({ margins: { top: 0.22, bottom: 0.05 } }, pane);
chart.addLayer({ pane, build: (ctx) => [
{ type: 'text', x: ctx.rect.x + 8, y: ctx.rect.y + 6, text: 'LP + short, % of capital', color: '#2ee6b6', size: 11 },
{ type: 'text', x: ctx.rect.x + 8, y: ctx.rect.y + 22, text: 'LP vs holding (impermanent loss), %', color: '#ffb547', size: 11 },
] });
chart.setVisibleLogicalRange(entry - 40, n + 4);為逐筆等級的資料而生。
Apple M4 Max · Chrome + WebGPU在瀏覽器中載入 100 萬根 K 線並繪出第一個畫面
WASM · WebGPU
原生載入 1,000 萬根 K 線,含多層級細節金字塔
原生 Rust
平移、縮放與即時串流時每個畫面的堆積記憶體配置次數
穩定狀態
WebAssembly 套件大小(gzip)
包含全部功能
瀏覽器數據:Google Chrome + WebGPU;1,000 萬根 K 線的載入為原生 Rust。長條表示各項數據相對於目標的比例:載入 300 毫秒、零配置、套件 1.5 MB。
範例
313 個範例,
涵蓋 20 個應用情境。
每個範例都是 FerroChart 在你的瀏覽器中即時渲染的圖表,並附上原始碼。所有資料均為模擬資料。



價格走勢
25 個範例 →適用於任何市場的 K 線、棒線與折線,即時串流更新。



訂單流
20 個範例 →足跡圖、深度熱力圖與市場輪廓,走 compute shader 路徑。



加密貨幣衍生性商品
15 個範例 →資金費率、未平倉量、清算與基差,顯示在價格下方的窗格中。



選擇權與波動率
18 個範例 →隱含波動率與實現波動率對照、偏斜、預期波動幅度與造市商曝險的時間變化。



投資組合、風險與量化
24 個範例 →權益曲線、回撤、滾動統計、因子研究與風險檢查。



自訂系列與外掛
11 個範例 →堆疊、分組、箱形與筆刷選取系列:在同一個 GPU 影格上疊加圖層外掛。
瀏覽全部 20 個應用情境
價格走勢
K 線類型與轉換
技術分析
訂單流
執行與交易檢討
加密貨幣衍生性商品
鏈上資料
DeFi 與 AMM
迷因幣與錢包
股票與基本面
中國 A 股
選擇權與波動率
利率、外匯與總體經濟
期貨與大宗商品
基金與 ETF
投資組合、風險與量化
私募市場與個人理財
預測市場
自訂系列與外掛
實驗室與旗艦範例
K 線 + 成交量
1 / 25The classic view. A day of real one-minute bars, updating every second, on a GPU-rendered price scale with a volume histogram below. Drag to pan, scroll or pinch to zoom.
FerroChart.createaddCandlestickSeriesaddVolumeSeries拖曳平移 · 滾輪或雙指縮放 · 按兩下重設即時資料 · OKXcandles
特色
為行情資料而設計。
跨平台渲染
同一個 Rust 核心:瀏覽器中使用 WebGPU 與 WebGL2 後端,原生應用程式透過 wgpu 在 Metal、Vulkan 與 DirectX 12 上執行,伺服器上則使用 CPU 渲染器。黃金影像測試確保各後端輸出一致。
效能與資料量無關
K 線資料常駐 GPU,座標轉換在著色器中完成,平移與縮放只需更新少量 uniform。多層級細節金字塔讓數千萬根 K 線依然流暢。
30 個內建指標
從 SMA 到一目均衡表的均線、通道與震盪指標。每個 tick 增量更新,並以參考資料測試。
29 種繪圖工具
趨勢線、通道、費波那契工具、叉子線、江恩角度線、型態、艾略特波浪、區間、部位與文字,支援復原與重做。繪圖與圖表狀態可序列化為 JSON。
多圖連動
同步群組可在多個圖表之間連動十字游標與可見範圍。
易於擴充
自訂系列、圖層與繪圖工具的外掛介面。提供 JavaScript、Rust 與 Python 繫結,以及供 C#、C++、Qt 與 Flutter 使用的 C ABI。
開始使用
每種語言,同一套 API。
所有繫結都遵循同一模型:建立圖表、加入系列、設定資料、加入指標。資料以欄的形式傳入,可以是型別化陣列、Rust 切片或 DataFrame。
- JavaScript 與 TypeScript
- Rust
- Python 與 Jupyter
- C、C#、C++
import { FerroChart } from '@ferrochart/core';
const chart = await FerroChart.create(canvas, { theme: 'dark' });
const candles = chart.addCandlestickSeries();
chart.addVolumeSeries(candles);
candles.setData(bars); // [{ time, open, high, low, close, volume }, ...]
chart.addIndicator(candles, 'ema', { n: 20 });
chart.addIndicator(candles, 'macd'); // in a new pane