オープンソースのチャートエンジン
LPリスクキャンバス
1つのポジションとそのリスクを1枚のチャートに示します。集中流動性のレンジはエントリーした足からのバンドで、10倍のショートヘッジは建値と清算価格をプライスラインで示します。建玉、レンジからの離脱と復帰、価格が届いた場合の清算は、正確な価格に置いた atPrice マーカーです。2つ目のペインには、トークンを保有し続けた場合との比較(インパーマネントロス)とヘッジ後の損益を手数料抜きで示します。最初の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 万本の足を読み込み、最初のフレームを描画
WASM · WebGPU
ネイティブで 1,000 万本の足を読み込み(LOD ピラミッド構築を含む)
ネイティブ Rust
パン、ズーム、ストリーミング中のフレームあたりのヒープアロケーション
定常状態
WebAssembly パッケージのサイズ(gzip)
全機能込み
ブラウザの数値は Google Chrome + WebGPU、1,000 万本の読み込みはネイティブ Rust での計測です。バーは各数値の目標に対する割合を示します(読み込み 300 ms、アロケーションなし、パッケージ 1.5 MB)。
サンプル
313 のサンプル、
20 のユースケース。
どのサンプルも FerroChart がブラウザ上でリアルタイムに描画するチャートで、ソースコード付きです。データはすべて合成データです。



プライスアクション
25 件のサンプル →あらゆる市場のローソク足、バー、ラインをリアルタイムでストリーミング表示します。



オーダーフロー
20 件のサンプル →フットプリント、板のヒートマップ、マーケットプロファイルをコンピュートシェーダーで描画します。



暗号資産デリバティブ
15 件のサンプル →資金調達率、建玉、清算、ベーシスを価格の下のペインに表示します。



オプションとボラティリティ
18 件のサンプル →インプライド対実現ボラティリティ、スキュー、予想変動幅、ディーラーのエクスポージャーを時系列で表示します。



ポートフォリオ・リスク・クオンツ
24 件のサンプル →資産曲線、ドローダウン、ローリング統計、ファクターリサーチ、リスクチェックを扱います。



カスタムシリーズとプラグイン
11 件のサンプル →積み上げ、グループ、箱ひげ、ブラシ選択のシリーズを、同じGPUフレーム上のレイヤープラグインで描画します。
20 のユースケースをすべて見る
プライスアクション
足の種類と変換
テクニカル分析
オーダーフロー
執行とトレードレビュー
暗号資産デリバティブ
オンチェーン
DeFiとAMM
ミームコインとウォレット
株式とファンダメンタルズ
中国A株
オプションとボラティリティ
金利・為替・マクロ
先物とコモディティ
ファンドとETF
ポートフォリオ・リスク・クオンツ
プライベート市場と個人の資産管理
予測市場
カスタムシリーズとプラグイン
ラボとフラッグシップ
ローソク足と出来高
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 レンダラーを使います。ゴールデンイメージテストで各バックエンドの出力を揃えています。
データ量に左右されない性能
足のデータは GPU 上に置かれ、座標変換はシェーダーで行うため、パンやズームでは少数の uniform を更新するだけです。LOD ピラミッドにより数千万本の足でも軽快に動きます。
30 の組み込みインジケーター
SMA から一目均衡表まで、移動平均、チャネル、オシレーター。値はティックごとにインクリメンタルに更新され、参照データでテストされています。
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