価格軸から発注

オープンソースのチャートエンジン

価格軸から発注

価格軸からの発注(再生した足でのシミュレーション)。価格軸横の「+」または右クリックで、その価格で意味のある指値注文と逆指値注文が表示されます。売り・買いボタンは bid と ask で成行注文を出し、Ladder は 1 つの数量を 5 本の買い指値に分割します。各注文は再生中の価格が届くまでラインで表示され、届くと約定マーカーに変わります。エンジンはどこにも何も送信しません。

Apache-2.0

価格軸から発注:執行とトレードレビューのサンプル

createOrderButton · createQuickTrade · ladderOrders · createTradingLines · tradeMarkers

コード
import { FerroChart } from '@ferrochart/core';
import { createTradingLines, createOrderButton, createQuickTrade, ladderOrders, tradeMarkers } from '@ferrochart/core/trading';

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=BTCUSD&interval=15m&count=400').then((r) => r.json());
// Bar replay with setData and update: all but the last 40 bars, then each
// step() moves the forming bar a little; it closes on its 4th tick. At the end
// of the data the replay starts over (restart() resets the example).
const n = bars.time.length, START = n - 40, TICKS = 4;
const head = (k) => Object.fromEntries(Object.entries(bars).map(([key, v]) => [key, v.slice(0, k)]));
const candles = chart.addCandlestickSeries();
candles.setData(head(START));
let next = START, tick = 0, forming = null;
function step() {
  if (next === n) { next = START; candles.setData(head(START)); restart(); }
  const i = next, t = ++tick, closed = t === TICKS, o = bars.open[i];
  const noise = (Math.random() - 0.5) * (bars.high[i] - bars.low[i]) * 0.5;
  const price = closed ? bars.close[i] : Math.round((o + (bars.close[i] - o) * t / TICKS + noise) * 10) / 10;
  if (t === 1) forming = { time: bars.time[i], open: o, high: o, low: o };
  forming = { ...forming, high: Math.max(forming.high, price), low: Math.min(forming.low, price), close: price, volume: bars.volume[i] * t / TICKS };
  candles.update(forming);
  if (closed) { next++; tick = 0; }
  return { time: bars.time[i], price, closed };
}
chart.setVisibleLogicalRange(START - (canvas.clientWidth < 480 ? 30 : 60), n + 3);
// Room above the bars for the buttons, and below them for buy orders.
chart.applyPriceScaleOptions({ margins: { top: 0.24, bottom: 0.16 } });
// Paper trading: orders "fill" in this page against the replayed price and go
// nowhere else. A real page sends each intent to its own server here.
const answer = () => new Promise((r) => setTimeout(r, 250)); // the server's reply
let now = { time: bars.time[START - 1], price: bars.close[START - 1] };
const quote = () => ({ bid: now.price - 2.5, ask: now.price + 2.5 });
const ui = (tag, css, parent = canvas.parentElement) => parent.appendChild(Object.assign(document.createElement(tag), { style: css }));
const bar = ui('div', 'position:absolute;left:12px;right:84px;top:60px;display:flex;flex-wrap:wrap;gap:8px;align-items:center;z-index:2;pointer-events:none');
const ladder = ui('button', 'font:600 12px system-ui;color:#fff;background:#2962ff;border:0;border-radius:5px;padding:6px 12px;cursor:pointer;pointer-events:auto', bar);
ladder.textContent = 'Ladder';
const note = ui('span', 'font:500 12px system-ui;color:#8b93a7;flex:1 1 150px', bar);
const say = (text) => { note.textContent = `Paper trading · ${text}`; };
say('Right-click the chart, or use the + beside the price axis.');

// Open orders are lines; a fill removes the line and adds a marker.
const lines = createTradingLines(chart, candles);
const orders = new Map(), fills = [];
let seq = 0;
const label = (o) => `${o.side === 'buy' ? 'Buy' : 'Sell'} ${o.type} ${o.quantity}`;
const place = (o) => { orders.set(++seq, o); lines.set({ id: seq, kind: 'order', price: o.price, title: label(o) }); };
const show = () => candles.setMarkers(tradeMarkers(fills, { times: bars.time }));
const fill = (side, price, quantity) => { fills.push({ time: now.time, side, price, quantity }); show(); };

// Market orders at the bid or ask; the second click confirms.
const quick = createQuickTrade(chart, {
  canvas, quantity: 0.1, quantityStep: 0.001, priceStep: 0.5,
  async onOrder({ side, quantity }) {
    await answer();
    const price = side === 'buy' ? quote().ask : quote().bid;
    fill(side, price, quantity);
    say(`${side === 'buy' ? 'Bought' : 'Sold'} ${quantity} at ${price}.`);
  },
});
// Limit and stop orders at a price: the "+" or a right click.
const button = createOrderButton(chart, candles, {
  canvas, priceStep: 0.5, lastPrice: () => now.price, quantity: () => quick.quantity,
  async onOrder(o) {
    await answer();
    place(o);
    say(`${label(o)} at ${o.price} placed.`);
  },
});
// Five buy limits below the market, larger the farther they are.
ladder.onclick = () => {
  const p = now.price;
  for (const o of ladderOrders({ side: 'buy', from: p * 0.997, to: p * 0.989, count: 5, total: 1, distribution: 'linear', priceStep: 0.5, quantityStep: 0.01 })) place(o);
  say('Ladder of 5 buy limits placed.');
};

// Two earlier trades and an open order to start with.
fills.push({ time: bars.time[START - 30], side: 'buy', price: bars.close[START - 30], quantity: 0.2 },
  { time: bars.time[START - 12], side: 'sell', price: bars.close[START - 12], quantity: 0.2 });
show();
place({ side: 'sell', type: 'limit', price: Math.round(now.price * 1.004), quantity: 0.1 });
quick.setQuote(quote());

function restart() { fills.length = 0; show(); }
const timer = setInterval(() => {
  now = step();
  quick.setQuote(quote());
  for (const [id, o] of orders) {
    // Buy limits and sell stops fill at or below their price, the others at or above.
    const down = (o.type === 'limit') === (o.side === 'buy');
    if (down ? now.price > o.price : now.price < o.price) continue;
    const price = o.type === 'limit' ? o.price : now.price;
    orders.delete(id);
    lines.remove(id);
    fill(o.side, price, o.quantity);
    say(`${label(o)} filled at ${price}.`);
  }
}, 600);

// The page calls this before it destroys the chart.
const stop = () => { clearInterval(timer); button.destroy(); quick.destroy(); lines.destroy(); bar.remove(); };

ティック単位のデータのために。

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)。

サンプル

320 のサンプル、
20 のユースケース。

どのサンプルも FerroChart がブラウザ上でリアルタイムに描画するチャートで、ソースコード付きです。データはすべて合成データです。

バーリプレイ
リアルタイムストリーム
ローソク足と出来高
01

プライスアクション

28 件のサンプル →

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

板のヒートマップ
デルタフットプリント
フットプリント
04

オーダーフロー

20 件のサンプル →

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

インプライド・ボラティリティ・ベーシス
ロング/ショート比率・CVD
資金調達率・建玉・清算
06

暗号資産デリバティブ

15 件のサンプル →

資金調達率、建玉、清算、ベーシスを価格の下のペインに表示します。

リスクリバーサル・バタフライ
満期までの予想変動幅
インプライド対実現ボラティリティ・IVランク
12

オプションとボラティリティ

18 件のサンプル →

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

同時ドローダウン
アンダーウォーターカーブ・最大ドローダウン
資産曲線・ドローダウン
16

ポートフォリオ・リスク・クオンツ

24 件のサンプル →

資産曲線、ドローダウン、ローリング統計、ファクターリサーチ、リスクチェックを扱います。

グループ縦棒
積み上げ縦棒
100%積み上げエリア
19

カスタムシリーズとプラグイン

11 件のサンプル →

積み上げ、グループ、箱ひげ、ブラシ選択のシリーズを、同じGPUフレーム上のレイヤープラグインで描画します。

20 のユースケースをすべて見る

プライスアクション

足の種類と変換

テクニカル分析

オーダーフロー

執行とトレードレビュー

暗号資産デリバティブ

オンチェーン

DeFiとAMM

ミームコインとウォレット

株式とファンダメンタルズ

中国A株

オプションとボラティリティ

金利・為替・マクロ

先物とコモディティ

ファンドとETF

ポートフォリオ・リスク・クオンツ

プライベート市場と個人の資産管理

予測市場

カスタムシリーズとプラグイン

ラボとフラッグシップ

特長

市場データのための設計。

01

クロスプラットフォームの描画

ひとつの Rust コアで、ブラウザでは WebGPU と WebGL2、ネイティブアプリでは wgpu により Metal、Vulkan、DirectX 12、サーバーでは CPU レンダラーを使います。ゴールデンイメージテストで各バックエンドの出力を揃えています。

02

データ量に左右されない性能

足のデータは GPU 上に置かれ、座標変換はシェーダーで行うため、パンやズームでは少数の uniform を更新するだけです。LOD ピラミッドにより数千万本の足でも軽快に動きます。

03

30 の組み込みインジケーター

SMA から一目均衡表まで、移動平均、チャネル、オシレーター。値はティックごとにインクリメンタルに更新され、参照データでテストされています。

04

29 の描画ツール

トレンドライン、チャネル、フィボナッチ、ピッチフォーク、ギャンファン、パターン、エリオット波動、レンジ、ポジション、テキスト。元に戻す・やり直しに対応し、描画とチャートの状態は JSON に保存できます。

05

チャートの同期

同期グループで、複数のチャートのクロスヘアと表示範囲を連動させます。

06

拡張性

カスタムシリーズ、レイヤー、描画ツールのためのプラグインインターフェース。JavaScript、Rust、Python のバインディングと、C#、C++、Qt、Flutter 向けの C ABI を提供します。

はじめる

どの言語でも、同じ API。

どのバインディングも同じモデルです。チャートを作成し、シリーズを追加し、データを設定し、インジケーターを追加します。データは型付き配列、Rust のスライス、DataFrame から列として渡します。

  • JavaScript・TypeScript
  • Rust
  • Python・Jupyter
  • C、C#、C++
ドキュメントを読む
main.js
$ npm install @ferrochart/core
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

FerroChart

あらゆる市場に。
あらゆる画面に。
ひとつのエンジン。

Apache-2.0 のオープンソース。ブラウザからトレーディングデスクまで。