本文へスキップ

Price WebSocket API

Oracle server は、ライブ source tick、集計価格更新、finalized source tick bucket を受け取るための読み取り専用 WebSocket エンドポイントを提供します。

本番 WebSocket URL:

text
wss://api.coinpost.ai/oracle/ws/prices

upstream endpoint path:

text
GET /ws/prices

認証方式

WebSocket upgrade の認証は Oracle server のルールに従います。auth.enabled または cp_auth.enabled が true の場合、API key を Bearer token として送信します。

text
Authorization: Bearer <api_key>

カスタム WebSocket ヘッダーを設定できないブラウザクライアントは、WebSocket URL に token を渡せます。

text
wss://api.coinpost.ai/oracle/ws/prices?token=<api_key>
wss://api.coinpost.ai/oracle/ws/prices?access_token=<api_key>

Query token 認証は price WebSocket endpoint でのみ受け付けます。

REST API の認証方式は REST operation ページを参照してください。

Client Messages

Client message は JSON です。未知のフィールドは無視されます。

Subscribe

json
{
  "type": "subscribe",
  "id": "btc-live",
  "symbols": ["BTC"],
  "channels": ["aggregate", "sources", "ticks"],
  "sources": ["bitbank", "binance_japan", "coinbase"],
  "include_snapshot": true
}

フィールド:

  • id: 任意の subscription ID。Server は subscription_id として同じ値を返します。
  • symbols: 必須。canonical symbol のリストです。
  • channels: 任意のリストです。デフォルトは ["aggregate", "sources"] です。
  • sources: 任意の source filter です。省略するか空リストを渡すと、すべての source が対象になります。
  • include_snapshot: 任意の boolean です。true の場合、server は最新状態をすぐに送信します。

Channels:

  • aggregate: snapshot aggregate data と aggregate_update message を受け取ります。
  • sources: snapshot source data と source_update message を受け取ります。
  • ticks: finalized tick message を受け取ります。

Unsubscribe

json
{
  "type": "unsubscribe",
  "id": "btc-live"
}

id を省略した場合、default subscription が削除されます。

Ping

json
{
  "type": "ping",
  "ts": "2026-06-10T06:00:00Z"
}

Response:

json
{
  "type": "pong",
  "ts": "2026-06-10T06:00:00Z"
}

Server Messages

Snapshot

include_snapshot が true の subscribe 後に送信されます。sources は source name から最新 source tick への map です。

json
{
  "type": "snapshot",
  "subscription_id": "btc-live",
  "symbol": "BTC",
  "asset_id": "d388491f-2ee0-337f-bad1-fd8f4444e076",
  "tick_interval": "1m0s",
  "aggregate": {
    "source": "aggregated",
    "selected_source": "bitbank",
    "selected_pair": "btc_jpy",
    "price_usd": "61363.4557105392479143",
    "price_jpy": "9839303",
    "tick_start": "2026-06-10T15:01:00+09:00",
    "tick_interval": "1m0s",
    "method": "source_vote",
    "vote_band_pct": "0.003",
    "vote_sources": ["bitbank", "bitflyer", "coinbase"],
    "rejected_sources": ["binance_japan"],
    "updated_at": "2026-06-10T15:01:24.347954002+09:00"
  },
  "sources": {
    "bitbank": {
      "symbol": "BTC",
      "asset_id": "d388491f-2ee0-337f-bad1-fd8f4444e076",
      "source": "bitbank",
      "pair": "btc_jpy",
      "tick_start": "2026-06-10T15:01:00+09:00",
      "tick_interval": "1m0s",
      "native_price": "9839303",
      "native_currency": "JPY",
      "price_jpy": "9839303",
      "price_usd": "61363.4557105392479143",
      "open": "9839303",
      "high": "9839303",
      "low": "9839303",
      "close": "9839303",
      "bid": "9837946",
      "ask": "9837947",
      "source_timestamp": "2026-06-10T15:01:10.046+09:00",
      "received_at": "2026-06-10T15:01:11.420015171+09:00",
      "transport": "websocket",
      "sample_count": 12
    }
  }
}

Source Update

channelssources が含まれる場合に送信されます。これは公開 API の中で最も低遅延な取引所 source tick event です。

json
{
  "type": "source_update",
  "subscription_id": "btc-live",
  "symbol": "BTC",
  "asset_id": "d388491f-2ee0-337f-bad1-fd8f4444e076",
  "source": "bitbank",
  "pair": "btc_jpy",
  "tick_start": "2026-06-10T15:01:00+09:00",
  "tick_interval": "1m0s",
  "native_price": "9839303",
  "native_currency": "JPY",
  "price_jpy": "9839303",
  "price_usd": "61363.4557105392479143",
  "open": "9839303",
  "high": "9839303",
  "low": "9839303",
  "close": "9839303",
  "bid": "9837946",
  "ask": "9837947",
  "source_timestamp": "2026-06-10T15:01:10.046+09:00",
  "received_at": "2026-06-10T15:01:11.420015171+09:00",
  "transport": "websocket",
  "sample_count": 12,
  "updated_at": "2026-06-10T15:01:11.421000000+09:00"
}

フィールド補足:

  • native_price: source quote currency で観測した最新価格です。
  • price_usd / price_jpy: 変換できる場合の正規化価格です。
  • open, high, low, close: 現在の tick_start に対応する source tick bucket の値です。
  • bid / ask: source ticker が提供する場合の best bid と best ask です。
  • sample_count: 現在の bucket に畳み込まれた source message 数です。
  • source_timestamp: 取引所または upstream source が報告した時刻です。
  • received_at: worker がローカルで受信した時刻です。

Bid と ask の提供状況:

SourceBid/ask
bitbankYes
binance_japanYes
bitflyerYes
coinbaseYes
gmo_coinYes
coincheckNo, current collector uses trades
coingeckoNo, current collector uses simple price

これらは ticker level の best bid と best ask です。full order book ではありません。

Aggregate Update

channelsaggregate が含まれる場合に送信されます。Worker は各 source update 後に現在の aggregate を再計算します。

json
{
  "type": "aggregate_update",
  "subscription_id": "btc-live",
  "symbol": "BTC",
  "asset_id": "d388491f-2ee0-337f-bad1-fd8f4444e076",
  "source": "bitbank",
  "tick_start": "2026-06-10T15:01:00+09:00",
  "tick_interval": "1m0s",
  "aggregate": {
    "source": "aggregated",
    "selected_source": "bitbank",
    "selected_pair": "btc_jpy",
    "price_usd": "61363.4557105392479143",
    "price_jpy": "9839303",
    "tick_start": "2026-06-10T15:01:00+09:00",
    "tick_interval": "1m0s",
    "method": "source_vote",
    "vote_band_pct": "0.003",
    "vote_sources": ["bitbank", "bitflyer", "coinbase"],
    "rejected_sources": ["binance_japan"],
    "updated_at": "2026-06-10T15:01:24.347954002+09:00"
  },
  "updated_at": "2026-06-10T15:01:24.347954002+09:00"
}

Tick

channelsticks が含まれ、tick bucket が finalized になったときに送信されます。

json
{
  "type": "tick",
  "subscription_id": "btc-live",
  "symbol": "BTC",
  "asset_id": "d388491f-2ee0-337f-bad1-fd8f4444e076",
  "tick_start": "2026-06-10T15:01:00+09:00",
  "tick_interval": "1m0s",
  "aggregate": {
    "source": "aggregated",
    "selected_source": "bitbank",
    "selected_pair": "btc_jpy",
    "price_usd": "61363.4557105392479143",
    "price_jpy": "9839303",
    "method": "source_vote",
    "vote_sources": ["bitbank", "bitflyer", "coinbase"],
    "rejected_sources": ["binance_japan"]
  },
  "sources": {
    "bitbank": {
      "pair": "btc_jpy",
      "native_price": "9839303",
      "native_currency": "JPY",
      "price_jpy": "9839303",
      "price_usd": "61363.4557105392479143",
      "open": "9839303",
      "high": "9839303",
      "low": "9839303",
      "close": "9839303",
      "bid": "9837946",
      "ask": "9837947",
      "transport": "websocket",
      "sample_count": 12
    }
  },
  "updated_at": "2026-06-10T15:02:02.000000000+09:00"
}

Example Client

js
const ws = new WebSocket("wss://api.coinpost.ai/oracle/ws/prices");

ws.addEventListener("open", () => {
  ws.send(JSON.stringify({
    type: "subscribe",
    id: "btc-live",
    symbols: ["BTC"],
    channels: ["aggregate", "sources"],
    include_snapshot: true
  }));
});

ws.addEventListener("message", (event) => {
  const msg = JSON.parse(event.data);
  if (msg.type === "source_update") {
    console.log(msg.source, msg.bid, msg.ask, msg.native_price);
  }
});

運用上の注意

  • GET /prices/sources?symbol=BTC は stale な source tick を除外します。本番 REST Base URL では https://api.coinpost.ai/oracle/prices/sources?symbol=BTC を呼び出します。
  • WebSocket source_update はライブ更新が到着した時点で送信されます。
  • source_update には現在 bucket の OHLC 値が含まれます。finalized historical candle ではありません。
  • このエンドポイントは full order book depth を提供しません。完全な depth が必要な場合は、取引所の order book stream を使ってください。