> ## Documentation Index
> Fetch the complete documentation index at: https://docs.chainstream.io/llms.txt
> Use this file to discover all available pages before exploring further.

# WebSocket API

> WebSocket API リアルタイムデータサブスクリプションサービス

## 概要

ChainStream DEX WebSocket APIは、以下のデータタイプをサポートするリアルタイムデータサブスクリプションサービスを提供します：

* ローソク足データ (Candles)
* トークン関連 (Token Series)
* ウォレット関連 (Wallet Series)
* ランキング関連 (Ranking Series)
* 取引関連 (Trade Series)
* DEXプール関連 (DexPool Series)

**ベースURL**

```bash theme={null}
wss://realtime-dex.chainstream.io/connection/websocket
```

## クイックスタート

### 1. 接続の確立

まず、WebSocket接続を作成します。WebSocket接続はURL内の`token`クエリパラメータによる認証が必要です。

<Tabs>
  <Tab title="SDK使用（推奨）">
    GoまたはJavaScript SDKを使用する場合、認証は自動的に処理されます：

    ```typescript theme={null}
    import { ChainStreamClient } from '@chainstream-io/sdk';
    import { Resolution } from '@chainstream-io/sdk/openapi';

    const client = new ChainStreamClient('YOUR_ACCESS_TOKEN');

    // 直接サブスクライブするだけで、SDKがWebSocket接続と認証を自動処理
    client.stream.subscribeTokenCandles({
      chain: 'sol',
      tokenAddress: '6p6xgHyF7AeE6TZkSmFsko444wqoP15icUSqi2jfGiPN',
      resolution: Resolution._1m,
      callback: (data) => {
        console.log('受信データ:', data);
      }
    });
    ```

    <Note>
      `subscribeXXX`メソッドを呼び出す際、SDKは自動的に接続状態を確認し、未接続の場合は自動的に接続を確立します。手動で`connect()`を呼び出す必要はありません。
    </Note>

    SDKインストール：

    * **TypeScript/JavaScript**: `npm install @chainstream-io/sdk` ([npm](https://www.npmjs.com/package/@chainstream-io/sdk))
    * **Python**: `pip install chainstream-sdk` ([PyPI](https://pypi.org/project/chainstream-sdk))
    * **Go**: `go get github.com/chainstream-io/chainstream-go-sdk` ([GitHub](https://github.com/chainstream-io/chainstream-go-sdk))
    * **Rust**: `Cargo.toml`に`chainstream-sdk`を追加 ([crates.io](https://crates.io/crates/chainstream-sdk))
  </Tab>

  <Tab title="ネイティブWebSocket使用">
    ブラウザネイティブWebSocketまたはその他のWebSocketライブラリを使用する場合、URLに`token`パラメータを追加します：

    ```typescript theme={null}
    // ブラウザとNode.jsの両方で使用可能
    const token = 'YOUR_ACCESS_TOKEN';
    const ws = new WebSocket(
      `wss://realtime-dex.chainstream.io/connection/websocket?token=${token}`
    );

    ws.onopen = () => {
      console.log('接続確立');
    };

    ws.onmessage = (event) => {
      const data = JSON.parse(event.data);
      console.log('受信データ:', data);
    };
    ```

    <Note>
      URLパラメータでtokenを渡すことで、ブラウザネイティブWebSocketや各種サードパーティライブラリを、ヘッダーの特別な処理なしに使用できます。
    </Note>
  </Tab>

  <Tab title="コマンドラインテスト">
    `wscat`を使用したテスト：

    ```bash theme={null}
    $ wscat -c "wss://realtime-dex.chainstream.io/connection/websocket?token=YOUR_ACCESS_TOKEN"
    ```
  </Tab>
</Tabs>

### 2. データのサブスクライブ

サブスクライブしたいデータタイプを選択します：

```typescript theme={null}
// ローソク足データのサブスクライブ例
ws.send(JSON.stringify({
  type: "subscribe",
  channel: "dex-candle:sol_6p6xgHyF7AeE6TZkSmFsko444wqoP15icUSqi2jfGiPN_1m"
}));
```

### 3. データの処理

```typescript theme={null}
ws.onmessage = (event) => {
  const data = JSON.parse(event.data);
  console.log('受信データ:', data);
};
```

## データサブスクリプション

### ローソク足

#### ローソク足データ

トークンの価格推移データをリアルタイムで取得します。

**サブスクリプション形式**

```text theme={null}
dex-candle:{chain}_{tokenAddress}_{resolution}
```

**パラメータ**

<ParamField query="chain" type="string" required>
  ブロックチェーン名、例：sol
</ParamField>

<ParamField query="tokenAddress" type="string" required>
  トークンコントラクトアドレス、例：6p6xgHyF7AeE6TZkSmFsko444wqoP15icUSqi2jfGiPN
</ParamField>

<ParamField query="resolution" type="string" required>
  ローソク足期間、対応：1m, 5m, 15m, 1h, 4h, 1d
</ParamField>

<ParamField query="filter" type="string" required={false}>
  オプションのフィルター条件。Google Common Expression Language（CEL）構文を使用。例：volume > 1000
</ParamField>

**レスポンスデータ形式**

<Tip>
  WebSocket APIは転送効率を最適化するために短縮フィールド名を返し、SDKはコードの可読性を向上させるために完全なフィールド名を返します。
</Tip>

<Tabs>
  <Tab title="WebSocket API">
    ```typescript theme={null}
    {
      "o": number,    // Open price
      "c": number,    // Close price
      "h": number,    // High price
      "l": number,    // Low price
      "v": number,    // Volume
      "r": string,    // Resolution
      "t": number     // Timestamp
    }
    ```
  </Tab>

  <Tab title="SDK">
    ```typescript theme={null}
    {
      "open": number,       // Open price
      "close": number,      // Close price
      "high": number,       // High price
      "low": number,        // Low price
      "volume": number,     // Volume
      "resolution": string, // Resolution
      "time": number       // Timestamp
    }
    ```
  </Tab>
</Tabs>

### トークン関連

#### トークン統計

トークンのリアルタイム市場統計データを取得します。

**サブスクリプション形式**

```text theme={null}
dex-token-stats:{chain}_{tokenAddress}
```

**パラメータ**

<ParamField query="chain" type="string" required>
  ブロックチェーン名、例：sol
</ParamField>

<ParamField query="tokenAddress" type="string" required>
  トークンコントラクトアドレス、例：6p6xgHyF7AeE6TZkSmFsko444wqoP15icUSqi2jfGiPN
</ParamField>

<ParamField query="filter" type="string" required={false}>
  オプションのフィルター条件。Google Common Expression Language（CEL）構文を使用。例：price > 0.01
</ParamField>

**レスポンスデータ形式**

<Tip>
  WebSocket APIは転送効率を最適化するために短縮フィールド名を返し、SDKはコードの可読性を向上させるために完全なフィールド名を返します。
</Tip>

<Tabs>
  <Tab title="WebSocket API">
    ```typescript theme={null}
    {
      "a": string,      // Token address
      "t": number,      // Timestamp
      "b1m": number,    // Buys in 1m
      "s1m": number,    // Sells in 1m
      "be1m": number,   // Buyers in 1m
      "se1m": number,   // Sellers in 1m
      "bviu1m": number, // Buy volume in USD 1m
      "sviu1m": number, // Sell volume in USD 1m
      "p1m": number,    // Price 1m
      "oiu1m": number,  // Open price in USD 1m
      "ciu1m": number,  // Close price in USD 1m
      "b5m": number,    // Buys in 5m
      "s5m": number,    // Sells in 5m
      "be5m": number,   // Buyers in 5m
      "se5m": number,   // Sellers in 5m
      "bviu5m": number, // Buy volume in USD 5m
      "sviu5m": number, // Sell volume in USD 5m
      "p5m": number,    // Price 5m
      "oiu5m": number,  // Open price in USD 5m
      "ciu5m": number,  // Close price in USD 5m
      "b15m": number,   // Buys in 15m
      "s15m": number,   // Sells in 15m
      "be15m": number,  // Buyers in 15m
      "se15m": number,  // Sellers in 15m
      "bviu15m": number,// Buy volume in USD 15m
      "sviu15m": number,// Sell volume in USD 15m
      "p15m": number,   // Price 15m
      "oiu15m": number, // Open price in USD 15m
      "ciu15m": number, // Close price in USD 15m
      "b30m": number,   // Buys in 30m
      "s30m": number,   // Sells in 30m
      "be30m": number,  // Buyers in 30m
      "se30m": number,  // Sellers in 30m
      "bviu30m": number,// Buy volume in USD 30m
      "sviu30m": number,// Sell volume in USD 30m
      "p30m": number,   // Price 30m
      "oiu30m": number, // Open price in USD 30m
      "ciu30m": number, // Close price in USD 30m
      "b1h": number,    // Buys in 1h
      "s1h": number,    // Sells in 1h
      "be1h": number,   // Buyers in 1h
      "se1h": number,   // Sellers in 1h
      "bviu1h": number, // Buy volume in USD 1h
      "sviu1h": number, // Sell volume in USD 1h
      "p1h": number,    // Price 1h
      "oiu1h": number,  // Open price in USD 1h
      "ciu1h": number,  // Close price in USD 1h
      "b4h": number,    // Buys in 4h
      "s4h": number,    // Sells in 4h
      "be4h": number,   // Buyers in 4h
      "se4h": number,   // Sellers in 4h
      "bviu4h": number, // Buy volume in USD 4h
      "sviu4h": number, // Sell volume in USD 4h
      "p4h": number,    // Price 4h
      "oiu4h": number,  // Open price in USD 4h
      "ciu4h": number,  // Close price in USD 4h
      "b24h": number,   // Buys in 24h
      "s24h": number,   // Sells in 24h
      "be24h": number,  // Buyers in 24h
      "se24h": number,  // Sellers in 24h
      "bviu24h": number,// Buy volume in USD 24h
      "sviu24h": number,// Sell volume in USD 24h
      "p24h": number,   // Price 24h
      "oiu24h": number, // Open price in USD 24h
      "ciu24h": number, // Close price in USD 24h
      "p": number       // Current price
    }
    ```
  </Tab>

  <Tab title="SDK">
    ```typescript theme={null}
    {
      "address": string,           // Token address
      "timestamp": number,         // Timestamp
      "buys1m": number,           // Buys in 1m
      "sells1m": number,          // Sells in 1m
      "buyers1m": number,         // Buyers in 1m
      "sellers1m": number,        // Sellers in 1m
      "buyVolumeInUsd1m": number, // Buy volume in USD 1m
      "sellVolumeInUsd1m": number,// Sell volume in USD 1m
      "price1m": number,          // Price 1m
      "openInUsd1m": number,      // Open price in USD 1m
      "closeInUsd1m": number,     // Close price in USD 1m
      "buys5m": number,           // Buys in 5m
      "sells5m": number,          // Sells in 5m
      "buyers5m": number,         // Buyers in 5m
      "sellers5m": number,        // Sellers in 5m
      "buyVolumeInUsd5m": number, // Buy volume in USD 5m
      "sellVolumeInUsd5m": number,// Sell volume in USD 5m
      "price5m": number,          // Price 5m
      "openInUsd5m": number,      // Open price in USD 5m
      "closeInUsd5m": number,     // Close price in USD 5m
      "buys15m": number,          // Buys in 15m
      "sells15m": number,         // Sells in 15m
      "buyers15m": number,        // Buyers in 15m
      "sellers15m": number,       // Sellers in 15m
      "buyVolumeInUsd15m": number,// Buy volume in USD 15m
      "sellVolumeInUsd15m": number,// Sell volume in USD 15m
      "price15m": number,         // Price 15m
      "openInUsd15m": number,     // Open price in USD 15m
      "closeInUsd15m": number,    // Close price in USD 15m
      "buys30m": number,          // Buys in 30m
      "sells30m": number,         // Sells in 30m
      "buyers30m": number,        // Buyers in 30m
      "sellers30m": number,       // Sellers in 30m
      "buyVolumeInUsd30m": number,// Buy volume in USD 30m
      "sellVolumeInUsd30m": number,// Sell volume in USD 30m
      "price30m": number,         // Price 30m
      "openInUsd30m": number,     // Open price in USD 30m
      "closeInUsd30m": number,    // Close price in USD 30m
      "buys1h": number,           // Buys in 1h
      "sells1h": number,          // Sells in 1h
      "buyers1h": number,         // Buyers in 1h
      "sellers1h": number,        // Sellers in 1h
      "buyVolumeInUsd1h": number, // Buy volume in USD 1h
      "sellVolumeInUsd1h": number,// Sell volume in USD 1h
      "price1h": number,          // Price 1h
      "openInUsd1h": number,      // Open price in USD 1h
      "closeInUsd1h": number,     // Close price in USD 1h
      "buys4h": number,           // Buys in 4h
      "sells4h": number,          // Sells in 4h
      "buyers4h": number,         // Buyers in 4h
      "sellers4h": number,        // Sellers in 4h
      "buyVolumeInUsd4h": number, // Buy volume in USD 4h
      "sellVolumeInUsd4h": number,// Sell volume in USD 4h
      "price4h": number,          // Price 4h
      "openInUsd4h": number,      // Open price in USD 4h
      "closeInUsd4h": number,     // Close price in USD 4h
      "buys24h": number,          // Buys in 24h
      "sells24h": number,         // Sells in 24h
      "buyers24h": number,        // Buyers in 24h
      "sellers24h": number,       // Sellers in 24h
      "buyVolumeInUsd24h": number,// Buy volume in USD 24h
      "sellVolumeInUsd24h": number,// Sell volume in USD 24h
      "price24h": number,         // Price 24h
      "openInUsd24h": number,     // Open price in USD 24h
      "closeInUsd24h": number,    // Close price in USD 24h
      "price": number            // Current price
    }
    ```
  </Tab>
</Tabs>

#### トークン保有者統計

トークン保有者のリアルタイム統計情報を取得します。

**サブスクリプション形式**

```text theme={null}
dex-token-holding:{chain}_{tokenAddress}
```

**パラメータ**

<ParamField query="chain" type="string" required>
  ブロックチェーン名、例：sol
</ParamField>

<ParamField query="tokenAddress" type="string" required>
  トークンコントラクトアドレス、例：6p6xgHyF7AeE6TZkSmFsko444wqoP15icUSqi2jfGiPN
</ParamField>

<ParamField query="filter" type="string" required={false}>
  オプションのフィルター条件。Google Common Expression Language（CEL）構文を使用。例：holders > 200
</ParamField>

**レスポンスデータ形式**

<Tip>
  WebSocket APIは転送効率を最適化するために短縮フィールド名を返し、SDKはコードの可読性を向上させるために完全なフィールド名を返します。
</Tip>

<Tabs>
  <Tab title="WebSocket API">
    ```typescript theme={null}
    {
      "a": string,      // Token address
      "h": number,      // Number of holders
      "t100a": number,  // Top 100 holders total amount
      "t10a": number,   // Top 10 holders total amount
      "t100h": number,  // Top 100 holders count
      "t10h": number,   // Top 10 holders count
      "t100r": number,  // Top 100 holders ratio
      "t10r": number,   // Top 10 holders ratio
      "ch": number,     // Creators holders count
      "ca": number,     // Creators amount
      "cr": number,     // Creators ratio
      "ts": number      // Timestamp
    }
    ```
  </Tab>

  <Tab title="SDK">
    ```typescript theme={null}
    {
      "tokenAddress": string,    // Token address
      "holders": number,         // Number of holders
      "top100Amount": number,    // Top 100 holders total amount
      "top10Amount": number,     // Top 10 holders total amount
      "top100Holders": number,   // Top 100 holders count
      "top10Holders": number,    // Top 10 holders count
      "top100Ratio": number,     // Top 100 holders ratio
      "top10Ratio": number,      // Top 10 holders ratio
      "creatorsHolders": number, // Creators holders count
      "creatorsAmount": number,  // Creators amount
      "creatorsRatio": number,   // Creators ratio
      "timestamp": number        // Timestamp
    }
    ```
  </Tab>
</Tabs>

#### 新規トークンメタデータ

新規上場トークンのリアルタイムメタデータを取得します。

**サブスクリプション形式**

```text theme={null}
dex-new-tokens-metadata:{chain}
```

**パラメータ**

<ParamField query="chain" type="string" required>
  ブロックチェーン名、例：sol
</ParamField>

<ParamField query="filter" type="string" required={false}>
  オプションのフィルター条件。Google Common Expression Language（CEL）構文を使用。例：name == "USDC"
</ParamField>

**レスポンスデータ形式**

<Tip>
  WebSocket APIは転送効率を最適化するために短縮フィールド名を返し、SDKはコードの可読性を向上させるために完全なフィールド名を返します。
</Tip>

<Tabs>
  <Tab title="WebSocket API">
    ```typescript theme={null}
    [
      {
        "a": string,      // Token address
        "n": string,      // Name
        "s": string,      // Symbol
        "iu": string,     // Image URL
        "de": string,     // Description
        "sm": {           // Social media
          "tw": string,   // Twitter
          "tg": string,   // Telegram
          "w": string,    // Website
          "tt": string,   // TikTok
          "dc": string,   // Discord
          "fb": string,   // Facebook
          "gh": string,   // GitHub
          "ig": string,   // Instagram
          "li": string,   // LinkedIn
          "md": string,   // Medium
          "rd": string,   // Reddit
          "yt": string,   // YouTube
          "bb": string    // BitBucket
        },
        "cts": number     // Created timestamp (ms)
      }
    ]
    ```
  </Tab>

  <Tab title="SDK">
    ```typescript theme={null}
    [
      {
        "tokenAddress": string,     // Token address
        "name": string,             // Name
        "symbol": string,           // Symbol
        "imageUrl": string,         // Image URL
        "description": string,      // Description
        "socialMedia": {            // Social media
          "twitter": string,        // Twitter
          "telegram": string,       // Telegram
          "website": string,        // Website
          "tiktok": string,         // TikTok
          "discord": string,        // Discord
          "facebook": string,       // Facebook
          "github": string,         // GitHub
          "instagram": string,      // Instagram
          "linkedin": string,       // LinkedIn
          "medium": string,         // Medium
          "reddit": string,         // Reddit
          "youtube": string,        // YouTube
          "bitbucket": string       // BitBucket
        },
        "createdAtMs": number       // Created timestamp (ms)
      }
    ]
    ```
  </Tab>
</Tabs>

#### 新規トークン

新しく作成されたトークンの情報を取得します。

**サブスクリプション形式**

```text theme={null}
dex-new-token:{chain}
```

**パラメータ**

<ParamField query="chain" type="string" required>
  ブロックチェーン名、例：sol
</ParamField>

**レスポンスデータ形式**

<Tip>
  WebSocket APIは転送効率を最適化するために短縮フィールド名を返し、SDKはコードの可読性を向上させるために完全なフィールド名を返します。
</Tip>

<Tabs>
  <Tab title="WebSocket API">
    ```typescript theme={null}
    {
      "a": string,      // Token address
      "n": string,      // Name
      "s": string,      // Symbol
      "dec": number,    // Decimals
      "cts": number,    // Created timestamp (ms)
      "lf": {           // Launch from information
        "pa": string,   // Program address
        "pf": string,   // Protocol family
        "pn": string    // Protocol name
      }
    }
    ```
  </Tab>

  <Tab title="SDK">
    ```typescript theme={null}
    {
      "tokenAddress": string,     // Token address
      "name": string,             // Name
      "symbol": string,           // Symbol
      "decimals": number,         // Decimals
      "createdAtMs": number,      // Created timestamp (ms)
      "launchFrom": {             // Launch from information
        "programAddress": string, // Program address
        "protocolFamily": string, // Protocol family
        "protocolName": string    // Protocol name
      }
    }
    ```
  </Tab>
</Tabs>

#### トークン供給量

トークンの供給量と時価総額のリアルタイム情報を取得します。

**サブスクリプション形式**

```text theme={null}
dex-token-supply:{chain}_{tokenAddress}
```

**パラメータ**

<ParamField query="chain" type="string" required>
  ブロックチェーン名、例：sol
</ParamField>

<ParamField query="tokenAddress" type="string" required>
  トークンコントラクトアドレス、例：6p6xgHyF7AeE6TZkSmFsko444wqoP15icUSqi2jfGiPN
</ParamField>

<ParamField query="filter" type="string" required={false}>
  オプションのフィルター条件。Google Common Expression Language（CEL）構文を使用。例：supply > 1000000
</ParamField>

**レスポンスデータ形式**

<Tip>
  WebSocket APIは転送効率を最適化するために短縮フィールド名を返し、SDKはコードの可読性を向上させるために完全なフィールド名を返します。
</Tip>

<Tabs>
  <Tab title="WebSocket API">
    ```typescript theme={null}
    {
      "a": string,    // Token address
      "s": number,    // Supply
      "mc": number,   // Market cap in USD
      "ts": number    // Timestamp
    }
    ```
  </Tab>

  <Tab title="SDK">
    ```typescript theme={null}
    {
      "tokenAddress": string,    // Token address
      "supply": number,          // Supply
      "marketCapInUsd": number,  // Market cap in USD
      "timestamp": number        // Timestamp
    }
    ```
  </Tab>
</Tabs>

#### トークン流動性

トークンのリアルタイム流動性統計を取得します。

**サブスクリプション形式**

```text theme={null}
dex-token-general-stat-num:{chain}_{tokenAddress}
```

**パラメータ**

<ParamField query="chain" type="string" required>
  ブロックチェーン名、例：sol
</ParamField>

<ParamField query="tokenAddress" type="string" required>
  トークンコントラクトアドレス
</ParamField>

<ParamField query="filter" type="string" required={false}>
  オプションのフィルター条件。Google Common Expression Language（CEL）構文を使用。例：value > 1000000
</ParamField>

**レスポンスデータ形式**

<Tip>
  WebSocket APIは転送効率を最適化するために短縮フィールド名を返し、SDKはコードの可読性を向上させるために完全なフィールド名を返します。
</Tip>

<Tabs>
  <Tab title="WebSocket API">
    ```typescript theme={null}
    {
      "a": string,    // Token address
      "t": string,    // Metric type
      "v": number,    // Value
      "ts": number    // Timestamp
    }
    ```
  </Tab>

  <Tab title="SDK">
    ```typescript theme={null}
    {
      "tokenAddress": string,  // Token address
      "metricType": string,    // Metric type
      "value": number,         // Value
      "timestamp": number      // Timestamp
    }
    ```
  </Tab>
</Tabs>

#### トークン最大流動性

単一プール内のトークンのリアルタイム最大流動性情報を取得します。

**サブスクリプション形式**

```text theme={null}
dex-token-liquidity:{chain}_{tokenAddress}
```

**パラメータ**

<ParamField query="chain" type="string" required>
  ブロックチェーン名、例：sol
</ParamField>

<ParamField query="tokenAddress" type="string" required>
  トークンコントラクトアドレス
</ParamField>

<ParamField query="filter" type="string" required={false}>
  オプションのフィルター条件。Google Common Expression Language（CEL）構文を使用。例：liquidityInUsd > 10000
</ParamField>

**レスポンスデータ形式**

<Tip>
  WebSocket APIは転送効率を最適化するために短縮フィールド名を返し、SDKはコードの可読性を向上させるために完全なフィールド名を返します。
</Tip>

<Tabs>
  <Tab title="WebSocket API">
    ```typescript theme={null}
    {
      "a": string,     // Token address
      "p": string,     // Pool address
      "liu": string,   // Liquidity in USD
      "lin": string,   // Liquidity in native token
      "ts": number     // Timestamp
    }
    ```
  </Tab>

  <Tab title="SDK">
    ```typescript theme={null}
    {
      "tokenAddress": string,       // Token address
      "poolAddress": string,        // Pool address
      "liquidityInUsd": string,     // Liquidity in USD
      "liquidityInNative": string,  // Liquidity in native token
      "timestamp": number           // Timestamp
    }
    ```
  </Tab>
</Tabs>

#### トークン合計流動性

全プールにわたるトークンのリアルタイム合計流動性情報を取得します。

**サブスクリプション形式**

```text theme={null}
dex-token-total-liquidity:{chain}_{tokenAddress}
```

**パラメータ**

<ParamField query="chain" type="string" required>
  ブロックチェーン名、例：sol
</ParamField>

<ParamField query="tokenAddress" type="string" required>
  トークンコントラクトアドレス
</ParamField>

<ParamField query="filter" type="string" required={false}>
  オプションのフィルター条件。Google Common Expression Language（CEL）構文を使用。例：liquidityInUsd > 50000
</ParamField>

**レスポンスデータ形式**

<Tip>
  WebSocket APIは転送効率を最適化するために短縮フィールド名を返し、SDKはコードの可読性を向上させるために完全なフィールド名を返します。
</Tip>

<Tabs>
  <Tab title="WebSocket API">
    ```typescript theme={null}
    {
      "a": string,     // Token address
      "liu": string,   // Total liquidity in USD
      "lin": string,   // Total liquidity in native token
      "pc": number,    // Pool count
      "ts": number     // Timestamp
    }
    ```
  </Tab>

  <Tab title="SDK">
    ```typescript theme={null}
    {
      "tokenAddress": string,       // Token address
      "liquidityInUsd": string,     // Total liquidity in USD
      "liquidityInNative": string,  // Total liquidity in native token
      "poolCount": number,          // Pool count
      "timestamp": number           // Timestamp
    }
    ```
  </Tab>
</Tabs>

### ランキング関連

#### ランキングトークン統計

ランキングトークンのリアルタイム市場統計データを取得します。

**サブスクリプション形式**

```text theme={null}
dex-ranking-token-stats-list:{chain}_{channelType}
```

**パラメータ**

<ParamField query="chain" type="string" required>
  ブロックチェーン名、例：sol
</ParamField>

<ParamField query="channelType" type="string" required>
  チャンネルタイプ、対応：new、trending、us\_stocks、completed、graduated
</ParamField>

**レスポンスデータ形式**

<Tip>
  WebSocket APIは転送効率を最適化するために短縮フィールド名を返し、SDKはコードの可読性を向上させるために完全なフィールド名を返します。
</Tip>

<Tabs>
  <Tab title="WebSocket API">
    ```typescript theme={null}
    [
      {
        "a": string,      // Token address
        "t": number,      // Timestamp
        "b1m": number,    // Buys in 1m
        "s1m": number,    // Sells in 1m
        "be1m": number,   // Buyers in 1m
        "se1m": number,   // Sellers in 1m
        "bviu1m": number, // Buy volume in USD 1m
        "sviu1m": number, // Sell volume in USD 1m
        "p1m": number,    // Price 1m
        "oiu1m": number,  // Open price in USD 1m
        "ciu1m": number,  // Close price in USD 1m
        "b5m": number,    // Buys in 5m
        "s5m": number,    // Sells in 5m
        "be5m": number,   // Buyers in 5m
        "se5m": number,   // Sellers in 5m
        "bviu5m": number, // Buy volume in USD 5m
        "sviu5m": number, // Sell volume in USD 5m
        "p5m": number,    // Price 5m
        "oiu5m": number,  // Open price in USD 5m
        "ciu5m": number,  // Close price in USD 5m
        "b15m": number,   // Buys in 15m
        "s15m": number,   // Sells in 15m
        "be15m": number,  // Buyers in 15m
        "se15m": number,  // Sellers in 15m
        "bviu15m": number,// Buy volume in USD 15m
        "sviu15m": number,// Sell volume in USD 15m
        "p15m": number,   // Price 15m
        "oiu15m": number, // Open price in USD 15m
        "ciu15m": number, // Close price in USD 15m
        "b30m": number,   // Buys in 30m
        "s30m": number,   // Sells in 30m
        "be30m": number,  // Buyers in 30m
        "se30m": number,  // Sellers in 30m
        "bviu30m": number,// Buy volume in USD 30m
        "sviu30m": number,// Sell volume in USD 30m
        "p30m": number,   // Price 30m
        "oiu30m": number, // Open price in USD 30m
        "ciu30m": number, // Close price in USD 30m
        "b1h": number,    // Buys in 1h
        "s1h": number,    // Sells in 1h
        "be1h": number,   // Buyers in 1h
        "se1h": number,   // Sellers in 1h
        "bviu1h": number, // Buy volume in USD 1h
        "sviu1h": number, // Sell volume in USD 1h
        "p1h": number,    // Price 1h
        "oiu1h": number,  // Open price in USD 1h
        "ciu1h": number,  // Close price in USD 1h
        "b4h": number,    // Buys in 4h
        "s4h": number,    // Sells in 4h
        "be4h": number,   // Buyers in 4h
        "se4h": number,   // Sellers in 4h
        "bviu4h": number, // Buy volume in USD 4h
        "sviu4h": number, // Sell volume in USD 4h
        "p4h": number,    // Price 4h
        "oiu4h": number,  // Open price in USD 4h
        "ciu4h": number,  // Close price in USD 4h
        "b24h": number,   // Buys in 24h
        "s24h": number,   // Sells in 24h
        "be24h": number,  // Buyers in 24h
        "se24h": number,  // Sellers in 24h
        "bviu24h": number,// Buy volume in USD 24h
        "sviu24h": number,// Sell volume in USD 24h
        "p24h": number,   // Price 24h
        "oiu24h": number, // Open price in USD 24h
        "ciu24h": number, // Close price in USD 24h
        "p": number       // Current price
      }
    ]
    ```
  </Tab>

  <Tab title="SDK">
    ```typescript theme={null}
    [
      {
        "address": string,           // Token address
        "timestamp": number,         // Timestamp
        "buys1m": number,           // Buys in 1m
        "sells1m": number,          // Sells in 1m
        "buyers1m": number,         // Buyers in 1m
        "sellers1m": number,        // Sellers in 1m
        "buyVolumeInUsd1m": number, // Buy volume in USD 1m
        "sellVolumeInUsd1m": number,// Sell volume in USD 1m
        "price1m": number,          // Price 1m
        "openInUsd1m": number,      // Open price in USD 1m
        "closeInUsd1m": number,     // Close price in USD 1m
        "buys5m": number,           // Buys in 5m
        "sells5m": number,          // Sells in 5m
        "buyers5m": number,         // Buyers in 5m
        "sellers5m": number,        // Sellers in 5m
        "buyVolumeInUsd5m": number, // Buy volume in USD 5m
        "sellVolumeInUsd5m": number,// Sell volume in USD 5m
        "price5m": number,          // Price 5m
        "openInUsd5m": number,      // Open price in USD 5m
        "closeInUsd5m": number,     // Close price in USD 5m
        "buys15m": number,          // Buys in 15m
        "sells15m": number,         // Sells in 15m
        "buyers15m": number,        // Buyers in 15m
        "sellers15m": number,       // Sellers in 15m
        "buyVolumeInUsd15m": number,// Buy volume in USD 15m
        "sellVolumeInUsd15m": number,// Sell volume in USD 15m
        "price15m": number,         // Price 15m
        "openInUsd15m": number,     // Open price in USD 15m
        "closeInUsd15m": number,    // Close price in USD 15m
        "buys30m": number,          // Buys in 30m
        "sells30m": number,         // Sells in 30m
        "buyers30m": number,        // Buyers in 30m
        "sellers30m": number,       // Sellers in 30m
        "buyVolumeInUsd30m": number,// Buy volume in USD 30m
        "sellVolumeInUsd30m": number,// Sell volume in USD 30m
        "price30m": number,         // Price 30m
        "openInUsd30m": number,     // Open price in USD 30m
        "closeInUsd30m": number,    // Close price in USD 30m
        "buys1h": number,           // Buys in 1h
        "sells1h": number,          // Sells in 1h
        "buyers1h": number,         // Buyers in 1h
        "sellers1h": number,        // Sellers in 1h
        "buyVolumeInUsd1h": number, // Buy volume in USD 1h
        "sellVolumeInUsd1h": number,// Sell volume in USD 1h
        "price1h": number,          // Price 1h
        "openInUsd1h": number,      // Open price in USD 1h
        "closeInUsd1h": number,     // Close price in USD 1h
        "buys4h": number,           // Buys in 4h
        "sells4h": number,          // Sells in 4h
        "buyers4h": number,         // Buyers in 4h
        "sellers4h": number,        // Sellers in 4h
        "buyVolumeInUsd4h": number, // Buy volume in USD 4h
        "sellVolumeInUsd4h": number,// Sell volume in USD 4h
        "price4h": number,          // Price 4h
        "openInUsd4h": number,      // Open price in USD 4h
        "closeInUsd4h": number,     // Close price in USD 4h
        "buys24h": number,          // Buys in 24h
        "sells24h": number,         // Sells in 24h
        "buyers24h": number,        // Buyers in 24h
        "sellers24h": number,       // Sellers in 24h
        "buyVolumeInUsd24h": number,// Buy volume in USD 24h
        "sellVolumeInUsd24h": number,// Sell volume in USD 24h
        "price24h": number,         // Price 24h
        "openInUsd24h": number,     // Open price in USD 24h
        "closeInUsd24h": number,    // Close price in USD 24h
        "price": number            // Current price
      }
    ]
    ```
  </Tab>
</Tabs>

#### ランキングトークン保有者統計

ランキングトークンのリアルタイム保有者統計情報を取得します。

**サブスクリプション形式**

```text theme={null}
dex-ranking-token-holding-list:{chain}_{channelType}
```

**パラメータ**

<ParamField query="chain" type="string" required>
  ブロックチェーン名、例：sol
</ParamField>

<ParamField query="channelType" type="string" required>
  チャンネルタイプ、対応：new、trending、us\_stocks、completed、graduated
</ParamField>

**レスポンスデータ形式**

<Tip>
  WebSocket APIは転送効率を最適化するために短縮フィールド名を返し、SDKはコードの可読性を向上させるために完全なフィールド名を返します。
</Tip>

<Tabs>
  <Tab title="WebSocket API">
    ```typescript theme={null}
    [
      {
        "a": string,      // Token address
        "h": number,      // Number of holders
        "t100a": number,  // Top 100 holders total amount
        "t10a": number,   // Top 10 holders total amount
        "t100h": number,  // Top 100 holders count
        "t10h": number,   // Top 10 holders count
        "t100r": number,  // Top 100 holders ratio
        "t10r": number,   // Top 10 holders ratio
        "ts": number      // Timestamp
      }
    ]
    ```
  </Tab>

  <Tab title="SDK">
    ```typescript theme={null}
    [
      {
        "tokenAddress": string,    // Token address
        "holders": number,         // Number of holders
        "top100Amount": number,    // Top 100 holders total amount
        "top10Amount": number,     // Top 10 holders total amount
        "top100Holders": number,   // Top 100 holders count
        "top10Holders": number,    // Top 10 holders count
        "top100Ratio": number,     // Top 100 holders ratio
        "top10Ratio": number,      // Top 10 holders ratio
        "timestamp": number        // Timestamp
      }
    ]
    ```
  </Tab>
</Tabs>

#### ランキングトークン供給量データ

ランキングトークンの供給量と時価総額のリアルタイム情報を取得します。

**サブスクリプション形式**

```text theme={null}
dex-ranking-token-supply-list:{chain}_{channelType}
```

**パラメータ**

<ParamField query="chain" type="string" required>
  ブロックチェーン名、例：sol
</ParamField>

<ParamField query="channelType" type="string" required>
  チャンネルタイプ、対応：new、trending、us\_stocks、completed、graduated
</ParamField>

**レスポンスデータ形式**

<Tip>
  WebSocket APIは転送効率を最適化するために短縮フィールド名を返し、SDKはコードの可読性を向上させるために完全なフィールド名を返します。
</Tip>

<Tabs>
  <Tab title="WebSocket API">
    ```typescript theme={null}
    [
      {
        "a": string,    // Token address
        "s": number,    // Supply
        "mc": number,   // Market cap in USD
        "ts": number    // Timestamp
      }
    ]
    ```
  </Tab>

  <Tab title="SDK">
    ```typescript theme={null}
    [
      {
        "tokenAddress": string,    // Token address
        "supply": number,          // Supply
        "marketCapInUsd": number,  // Market cap in USD
        "timestamp": number        // Timestamp
      }
    ]
    ```
  </Tab>
</Tabs>

#### ランキングトークン流動性データ

ランキングトークンのリアルタイム流動性統計を取得します。

**サブスクリプション形式**

```text theme={null}
dex-ranking-token-general_stat_num-list:{chain}_{channelType}
```

**パラメータ**

<ParamField query="chain" type="string" required>
  ブロックチェーン名、例：sol
</ParamField>

<ParamField query="channelType" type="string" required>
  チャンネルタイプ、対応：new、trending、us\_stocks、completed、graduated
</ParamField>

**レスポンスデータ形式**

<Tip>
  WebSocket APIは転送効率を最適化するために短縮フィールド名を返し、SDKはコードの可読性を向上させるために完全なフィールド名を返します。
</Tip>

<Tabs>
  <Tab title="WebSocket API">
    ```typescript theme={null}
    [
      {
        "a": string,    // Token address
        "t": string,    // Metric type
        "v": number,    // Value
        "ts": number    // Timestamp
      }
    ]
    ```
  </Tab>

  <Tab title="SDK">
    ```typescript theme={null}
    [
      {
        "tokenAddress": string,  // Token address
        "metricType": string,    // Metric type
        "value": number,         // Value
        "timestamp": number      // Timestamp
      }
    ]
    ```
  </Tab>
</Tabs>

#### ランキングトークンリスト

ランキングトークンの完全な情報リストをリアルタイムで取得します。メタデータ、保有者統計、供給量、市場データを含みます。

**サブスクリプション形式**

```text theme={null}
dex-ranking-list:{chain}_{ranking_type}
# またはDEXを指定
dex-ranking-list:{chain}_{ranking_type}_{dex}
```

**パラメータ**

<ParamField query="chain" type="string" required>
  ブロックチェーン名、例：sol
</ParamField>

<ParamField query="ranking_type" type="string" required>
  ランキングタイプ、対応：new、trending、us\_stocks、completed、graduated
</ParamField>

<ParamField query="dex" type="string" required={false}>
  オプションのDEXプラットフォーム、対応：pump\_fun、raydium\_launchpad、meteora\_dynamic\_bounding\_curve、bonk\_fun、boop\_fun、moonit\_fun
</ParamField>

**レスポンスデータ形式**

<Tip>
  WebSocket APIは転送効率を最適化するために短縮フィールド名を返し、SDKはコードの可読性を向上させるために完全なフィールド名を返します。
</Tip>

<Tabs>
  <Tab title="WebSocket API">
    ```typescript theme={null}
    [
      {
        // TokenMetadata (t)
        "t": {
          "a": string,      // Token address
          "n": string,      // Name
          "s": string,      // Symbol
          "iu": string,     // Image URL
          "de": string,     // Description
          "dec": number,    // Decimals
          "cts": number,    // Created timestamp (ms)
          "lf": {           // Launch from information
            "pa": string,   // Program address
            "pf": string,   // Protocol family
            "pn": string    // Protocol name
          },
          "mt": {           // Migrated to information
            "pa": string,   // Program address
            "pf": string,   // Protocol family
            "pn": string    // Protocol name
          },
          "sm": {           // Social media
            "tw": string,   // Twitter
            "tg": string,   // Telegram
            "w": string,    // Website
            "tt": string,   // TikTok
            "dc": string,   // Discord
            "fb": string,   // Facebook
            "gh": string,   // GitHub
            "ig": string,   // Instagram
            "li": string,   // LinkedIn
            "md": string,   // Medium
            "rd": string,   // Reddit
            "yt": string,   // YouTube
            "bb": string    // BitBucket
          }
          },
        // TokenBondingCurve (bc)
        "bc": {
          "pr": number      // Progress ratio
        },
        // TokenHolder (h)
        "h": {
          "a": string,      // Token address
          "h": number,      // Number of holders
          "t100a": number,  // Top 100 holders total amount
          "t10a": number,   // Top 10 holders total amount
          "t100h": number,  // Top 100 holders count
          "t10h": number,   // Top 10 holders count
          "t100r": number,  // Top 100 holders ratio
          "t10r": number,   // Top 10 holders ratio
          "ts": number      // Timestamp
        },
        // TokenSupply (s)
        "s": {
          "a": string,    // Token address
          "s": number,    // Supply
          "mc": number,   // Market cap in USD
          "ts": number    // Timestamp
        },
        // TokenStat (ts)
        "ts": {
          "a": string,      // Token address
          "t": number,      // Timestamp
          "b1m": number,    // Buys in 1m
          "s1m": number,    // Sells in 1m
          "be1m": number,   // Buyers in 1m
          "se1m": number,   // Sellers in 1m
          "bviu1m": number, // Buy volume in USD 1m
          "sviu1m": number, // Sell volume in USD 1m
          "p1m": number,    // Price 1m
          "oiu1m": number,  // Open price in USD 1m
          "ciu1m": number,  // Close price in USD 1m
          "b5m": number,    // Buys in 5m
          "s5m": number,    // Sells in 5m
          "be5m": number,   // Buyers in 5m
          "se5m": number,   // Sellers in 5m
          "bviu5m": number, // Buy volume in USD 5m
          "sviu5m": number, // Sell volume in USD 5m
          "p5m": number,    // Price 5m
          "oiu5m": number,  // Open price in USD 5m
          "ciu5m": number,  // Close price in USD 5m
          "b15m": number,   // Buys in 15m
          "s15m": number,   // Sells in 15m
          "be15m": number,  // Buyers in 15m
          "se15m": number,  // Sellers in 15m
          "bviu15m": number,// Buy volume in USD 15m
          "sviu15m": number,// Sell volume in USD 15m
          "p15m": number,   // Price 15m
          "oiu15m": number, // Open price in USD 15m
          "ciu15m": number, // Close price in USD 15m
          "b30m": number,   // Buys in 30m
          "s30m": number,   // Sells in 30m
          "be30m": number,  // Buyers in 30m
          "se30m": number,  // Sellers in 30m
          "bviu30m": number,// Buy volume in USD 30m
          "sviu30m": number,// Sell volume in USD 30m
          "p30m": number,   // Price 30m
          "oiu30m": number, // Open price in USD 30m
          "ciu30m": number, // Close price in USD 30m
          "b1h": number,    // Buys in 1h
          "s1h": number,    // Sells in 1h
          "be1h": number,   // Buyers in 1h
          "se1h": number,   // Sellers in 1h
          "bviu1h": number, // Buy volume in USD 1h
          "sviu1h": number, // Sell volume in USD 1h
          "p1h": number,    // Price 1h
          "oiu1h": number,  // Open price in USD 1h
          "ciu1h": number,  // Close price in USD 1h
          "b4h": number,    // Buys in 4h
          "s4h": number,    // Sells in 4h
          "be4h": number,   // Buyers in 4h
          "se4h": number,   // Sellers in 4h
          "bviu4h": number, // Buy volume in USD 4h
          "sviu4h": number, // Sell volume in USD 4h
          "p4h": number,    // Price 4h
          "oiu4h": number,  // Open price in USD 4h
          "ciu4h": number,  // Close price in USD 4h
          "b24h": number,   // Buys in 24h
          "s24h": number,   // Sells in 24h
          "be24h": number,  // Buyers in 24h
          "se24h": number,  // Sellers in 24h
          "bviu24h": number,// Buy volume in USD 24h
          "sviu24h": number,// Sell volume in USD 24h
          "p24h": number,   // Price 24h
          "oiu24h": number, // Open price in USD 24h
          "ciu24h": number, // Close price in USD 24h
          "p": number       // Current price
        }
      }
    ]
    ```
  </Tab>

  <Tab title="SDK">
    ```typescript theme={null}
    [
      {
        // Token metadata
        "metadata": {
        "tokenAddress": string,     // Token address
        "name": string,             // Name
        "symbol": string,           // Symbol
        "imageUrl": string,         // Image URL
        "description": string,      // Description
          "decimals": number,         // Decimals
          "createdAtMs": number,      // Created timestamp (ms)
          "launchFrom": {             // Launch from information
            "programAddress": string, // Program address
            "protocolFamily": string, // Protocol family
            "protocolName": string    // Protocol name
          },
          "migratedTo": {             // Migrated to information
            "programAddress": string, // Program address
            "protocolFamily": string, // Protocol family
            "protocolName": string    // Protocol name
          },
        "socialMedia": {            // Social media
          "twitter": string,        // Twitter
          "telegram": string,       // Telegram
          "website": string,        // Website
          "tiktok": string,         // TikTok
          "discord": string,        // Discord
          "facebook": string,       // Facebook
          "github": string,         // GitHub
          "instagram": string,      // Instagram
          "linkedin": string,       // LinkedIn
          "medium": string,         // Medium
          "reddit": string,         // Reddit
          "youtube": string,        // YouTube
          "bitbucket": string       // BitBucket
          }
        },
        
        // Bonding curve information
        "bondingCurve": {
          "progressRatio": number     // Progress ratio
        },
        
        // Holder statistics
        "holder": {
          "tokenAddress": string,     // Token address
          "timestamp": number,        // Timestamp
        "holders": number,          // Number of holders
        "top100Amount": number,     // Top 100 holders total amount
        "top10Amount": number,      // Top 10 holders total amount
        "top100Holders": number,    // Top 100 holders count
        "top10Holders": number,     // Top 10 holders count
        "top100Ratio": number,      // Top 100 holders ratio
          "top10Ratio": number        // Top 10 holders ratio
        },
        
        // Supply information
        "supply": {
          "tokenAddress": string,     // Token address
          "timestamp": number,        // Timestamp
        "supply": number,           // Supply
          "marketCapInUsd": number    // Market cap in USD
        },
        
        // Market statistics
        "stat": {
          "address": string,          // Token address
          "timestamp": number,        // Timestamp
        "buys1m": number,           // Buys in 1m
        "sells1m": number,          // Sells in 1m
        "buyers1m": number,         // Buyers in 1m
        "sellers1m": number,        // Sellers in 1m
        "buyVolumeInUsd1m": number, // Buy volume in USD 1m
        "sellVolumeInUsd1m": number,// Sell volume in USD 1m
        "price1m": number,          // Price 1m
        "openInUsd1m": number,      // Open price in USD 1m
        "closeInUsd1m": number,     // Close price in USD 1m
          "buys5m": number,           // Buys in 5m
          "sells5m": number,          // Sells in 5m
          "buyers5m": number,         // Buyers in 5m
          "sellers5m": number,        // Sellers in 5m
          "buyVolumeInUsd5m": number, // Buy volume in USD 5m
          "sellVolumeInUsd5m": number,// Sell volume in USD 5m
          "price5m": number,          // Price 5m
          "openInUsd5m": number,      // Open price in USD 5m
          "closeInUsd5m": number,     // Close price in USD 5m
          "buys15m": number,          // Buys in 15m
          "sells15m": number,         // Sells in 15m
          "buyers15m": number,        // Buyers in 15m
          "sellers15m": number,       // Sellers in 15m
          "buyVolumeInUsd15m": number,// Buy volume in USD 15m
          "sellVolumeInUsd15m": number,// Sell volume in USD 15m
          "price15m": number,         // Price 15m
          "openInUsd15m": number,     // Open price in USD 15m
          "closeInUsd15m": number,    // Close price in USD 15m
          "buys30m": number,          // Buys in 30m
          "sells30m": number,         // Sells in 30m
          "buyers30m": number,        // Buyers in 30m
          "sellers30m": number,       // Sellers in 30m
          "buyVolumeInUsd30m": number,// Buy volume in USD 30m
          "sellVolumeInUsd30m": number,// Sell volume in USD 30m
          "price30m": number,         // Price 30m
          "openInUsd30m": number,     // Open price in USD 30m
          "closeInUsd30m": number,    // Close price in USD 30m
          "buys1h": number,           // Buys in 1h
          "sells1h": number,          // Sells in 1h
          "buyers1h": number,         // Buyers in 1h
          "sellers1h": number,        // Sellers in 1h
          "buyVolumeInUsd1h": number, // Buy volume in USD 1h
          "sellVolumeInUsd1h": number,// Sell volume in USD 1h
          "price1h": number,          // Price 1h
          "openInUsd1h": number,      // Open price in USD 1h
          "closeInUsd1h": number,     // Close price in USD 1h
          "buys4h": number,           // Buys in 4h
          "sells4h": number,          // Sells in 4h
          "buyers4h": number,         // Buyers in 4h
          "sellers4h": number,        // Sellers in 4h
          "buyVolumeInUsd4h": number, // Buy volume in USD 4h
          "sellVolumeInUsd4h": number,// Sell volume in USD 4h
          "price4h": number,          // Price 4h
          "openInUsd4h": number,      // Open price in USD 4h
          "closeInUsd4h": number,     // Close price in USD 4h
          "buys24h": number,          // Buys in 24h
          "sells24h": number,         // Sells in 24h
          "buyers24h": number,        // Buyers in 24h
          "sellers24h": number,       // Sellers in 24h
          "buyVolumeInUsd24h": number,// Buy volume in USD 24h
          "sellVolumeInUsd24h": number,// Sell volume in USD 24h
          "price24h": number,         // Price 24h
          "openInUsd24h": number,     // Open price in USD 24h
          "closeInUsd24h": number,    // Close price in USD 24h
          "price": number             // Current price
        }
      }
    ]
    ```
  </Tab>
</Tabs>

#### ランキングトークンボンディングカーブ

新規上場トークンのリアルタイムボンディングカーブ進捗を取得します。

**サブスクリプション形式**

```text theme={null}
dex-ranking-token-bounding-curve-list:{chain}_new
```

**パラメータ**

<ParamField query="chain" type="string" required>
  ブロックチェーン名、例：sol
</ParamField>

**レスポンスデータ形式**

<Tip>
  WebSocket APIは転送効率を最適化するために短縮フィールド名を返し、SDKはコードの可読性を向上させるために完全なフィールド名を返します。
</Tip>

<Tabs>
  <Tab title="WebSocket API">
    ```typescript theme={null}
    [
      {
        "a": string,    // Token address
        "pr": string    // Progress ratio (0-1)
      }
    ]
    ```
  </Tab>

  <Tab title="SDK">
    ```typescript theme={null}
    [
      {
        "tokenAddress": string,   // Token address
        "progressRatio": string   // Progress ratio (0-1)
      }
    ]
    ```
  </Tab>
</Tabs>

### ウォレット関連

#### ウォレット残高

ウォレットのリアルタイム残高情報を取得します。

**サブスクリプション形式**

```text theme={null}
dex-wallet-balance:{chain}_{walletAddress}
```

**パラメータ**

<ParamField query="chain" type="string" required>
  ブロックチェーン名、例：sol
</ParamField>

<ParamField query="walletAddress" type="string" required>
  ウォレットアドレス、例：HN7cABqLq46Es1jh92dQQisAq662SmxELLLsHHe4YWrH
</ParamField>

<ParamField query="filter" type="string" required={false}>
  オプションのフィルター条件。Google Common Expression Language（CEL）構文を使用。例：balance > 1000
</ParamField>

**レスポンスデータ形式**

<Tip>
  WebSocket APIは転送効率を最適化するために短縮フィールド名を返し、SDKはコードの可読性を向上させるために完全なフィールド名を返します。
</Tip>

<Tabs>
  <Tab title="WebSocket API">
    ```typescript theme={null}
    [
      {
        "a": string,      // Wallet address
        "ta": string,     // Token address
        "tpiu": number,   // Token price in USD
        "b": number,      // Balance
        "t": number       // Timestamp
      }
    ]
    ```
  </Tab>

  <Tab title="SDK">
    ```typescript theme={null}
    [
      {
        "walletAddress": string,    // Wallet address
        "tokenAddress": string,     // Token address
        "tokenPriceInUsd": number, // Token price in USD
        "balance": number,          // Balance
        "timestamp": number         // Timestamp
      }
    ]
    ```
  </Tab>
</Tabs>

#### ウォレットPnLデータ（トークンレベル）

ウォレットのリアルタイム損益（PnL）統計を取得します。

**サブスクリプション形式**

```text theme={null}
dex-wallet-token-pnl:{chain}_{walletAddress}
```

**パラメータ**

<ParamField query="chain" type="string" required>
  ブロックチェーン名、例：sol
</ParamField>

<ParamField query="walletAddress" type="string" required>
  ウォレットアドレス
</ParamField>

<ParamField query="filter" type="string" required={false}>
  オプションのフィルター条件。Google Common Expression Language（CEL）構文を使用。例：buyAmount > 1000
</ParamField>

**レスポンスデータ形式**

<Tip>
  WebSocket APIは転送効率を最適化するために短縮フィールド名を返し、SDKはコードの可読性を向上させるために完全なフィールド名を返します。
</Tip>

<Tabs>
  <Tab title="WebSocket API">
    ```typescript theme={null}
    {
      "a": string,      // Wallet address
      "ta": string,     // Token address
      "tpiu": number,   // Token price in USD
      "t": number,      // Timestamp
      "ot": number,     // Open time
      "lt": number,     // Last time
      "ct": number,     // Close time
      "ba": number,     // Buy amount
      "baiu": number,   // Buy amount in USD
      "bs": number,     // Buy count
      "bs30d": number,  // Buy count 30d
      "bs7d": number,   // Buy count 7d
      "sa": number,     // Sell amount
      "saiu": number,   // Sell amount in USD
      "ss": number,     // Sell count
      "ss30d": number,  // Sell count 30d
      "ss7d": number,   // Sell count 7d
      "hdts": number,   // Held duration timestamp
      "abpiu": number,  // Average buy price in USD
      "aspiu": number,  // Average sell price in USD
      "upiu": number,   // Unrealized profit in USD
      "upr": number,    // Unrealized profit ratio
      "rpiu": number,   // Realized profit in USD
      "rpr": number,    // Realized profit ratio
      "trpiu": number,  // Total realized profit in USD
      "trr": number     // Total realized profit ratio
    }
    ```
  </Tab>

  <Tab title="SDK">
    ```typescript theme={null}
    {
      "walletAddress": string,         // Wallet address
      "tokenAddress": string,          // Token address
      "tokenPriceInUsd": number,       // Token price in USD
      "timestamp": number,             // Timestamp
      "opentime": number,              // Open time
      "lasttime": number,              // Last time
      "closetime": number,             // Close time
      "buyAmount": number,             // Buy amount
      "buyAmountInUsd": number,        // Buy amount in USD
      "buyCount": number,              // Buy count
      "buyCount30d": number,           // Buy count 30d
      "buyCount7d": number,            // Buy count 7d
      "sellAmount": number,            // Sell amount
      "sellAmountInUsd": number,       // Sell amount in USD
      "sellCount": number,             // Sell count
      "sellCount30d": number,          // Sell count 30d
      "sellCount7d": number,           // Sell count 7d
      "heldDurationTimestamp": number, // Held duration timestamp
      "averageBuyPriceInUsd": number,  // Average buy price in USD
      "averageSellPriceInUsd": number, // Average sell price in USD
      "unrealizedProfitInUsd": number, // Unrealized profit in USD
      "unrealizedProfitRatio": number, // Unrealized profit ratio
      "realizedProfitInUsd": number,   // Realized profit in USD
      "realizedProfitRatio": number,   // Realized profit ratio
      "totalRealizedProfitInUsd": number, // Total realized profit in USD
      "totalRealizedProfitRatio": number  // Total realized profit ratio
    }
    ```
  </Tab>
</Tabs>

#### ウォレットPnLデータ（ウォレットレベル）

ウォレットのリアルタイム全体損益統計を取得します。

**サブスクリプション形式**

```text theme={null}
dex-wallet-pnl-list:{chain}_{walletAddress}
```

**パラメータ**

<ParamField query="chain" type="string" required>
  ブロックチェーン名、例：sol
</ParamField>

<ParamField query="walletAddress" type="string" required>
  ウォレットアドレス
</ParamField>

**レスポンスデータ形式**

<Tip>
  WebSocket APIは転送効率を最適化するために短縮フィールド名を返し、SDKはコードの可読性を向上させるために完全なフィールド名を返します。
</Tip>

<Tabs>
  <Tab title="WebSocket API">
    ```typescript theme={null}
    [
      {
        "a": string,     // Wallet address
        "bs": number,    // Number of buys
        "ba": number,    // Buy amount
        "baiu": number,  // Buy amount in USD
        "abpiu": number, // Average buy price in USD
        "sa": number,    // Sell amount
        "saiu": number,  // Sell amount in USD
        "ss": number,    // Number of sells
        "ws": number,    // Number of wins
        "wr": number,    // Win ratio
        "piu": number,   // PnL in USD
        "apiu": number,  // Average PnL in USD
        "pr": number,    // PnL ratio
        "pd": number,    // Profitable days
        "ld": number,    // Losing days
        "ts": number,    // Number of tokens traded
        "r": string      // Resolution
      }
    ]
    ```
  </Tab>

  <Tab title="SDK">
    ```typescript theme={null}
    [
      {
        "walletAddress": string,         // Wallet address
        "buys": number,                  // Number of buys
        "buyAmount": number,             // Buy amount
        "buyAmountInUsd": number,        // Buy amount in USD
        "averageBuyPriceInUsd": number,  // Average buy price in USD
        "sellAmount": number,            // Sell amount
        "sellAmountInUsd": number,       // Sell amount in USD
        "sells": number,                 // Number of sells
        "wins": number,                  // Number of wins
        "winRatio": number,              // Win ratio
        "pnlInUsd": number,              // PnL in USD
        "averagePnlInUsd": number,       // Average PnL in USD
        "pnlRatio": number,              // PnL ratio
        "profitableDays": number,        // Profitable days
        "losingDays": number,            // Losing days
        "tokens": number,                // Number of tokens traded
        "resolution": string             // Resolution
      }
    ]
    ```
  </Tab>
</Tabs>

### 取引関連

#### トークン取引

トークンのリアルタイム取引イベントを取得します。

**サブスクリプション形式**

```text theme={null}
dex-trade:{chain}_{tokenAddress}
```

**パラメータ**

<ParamField query="chain" type="string" required>
  ブロックチェーン名、例：sol
</ParamField>

<ParamField query="tokenAddress" type="string" required>
  トークンコントラクトアドレス、例：6p6xgHyF7AeE6TZkSmFsko444wqoP15icUSqi2jfGiPN
</ParamField>

<ParamField query="filter" type="string" required={false}>
  オプションのフィルター条件。Google Common Expression Language（CEL）構文を使用。例：buyAmount > 100
</ParamField>

**レスポンスデータ形式**

<Tip>
  WebSocket APIは転送効率を最適化するために短縮フィールド名を返し、SDKはコードの可読性を向上させるために完全なフィールド名を返します。
</Tip>

<Tabs>
  <Tab title="WebSocket API">
    ```typescript theme={null}
    {
      "a": string,      // Token address
      "t": number,      // Timestamp
      "k": string,      // Trade type
      "ba": number,     // Buy amount
      "baiu": number,   // Buy amount in USD
      "btma": string,   // Buy token address
      "btn": string,    // Buy token name
      "bts": string,    // Buy token symbol
      "bwa": string,    // Buy wallet address
      "sa": number,     // Sell amount
      "saiu": number,   // Sell amount in USD
      "stma": string,   // Sell token address
      "stn": string,    // Sell token name
      "sts": string,    // Sell token symbol
      "swa": string,    // Sell wallet address
      "h": string       // Transaction hash
    }
    ```
  </Tab>

  <Tab title="SDK">
    ```typescript theme={null}
    {
      "tokenAddress": string,    // Token address
      "timestamp": number,       // Timestamp
      "kind": string,            // Trade type
      "buyAmount": number,       // Buy amount
      "buyAmountInUsd": number,  // Buy amount in USD
      "buyTokenAddress": string, // Buy token address
      "buyTokenName": string,    // Buy token name
      "buyTokenSymbol": string,  // Buy token symbol
      "buyWalletAddress": string,// Buy wallet address
      "sellAmount": number,      // Sell amount
      "sellAmountInUsd": number,// Sell amount in USD
      "sellTokenAddress": string,// Sell token address
      "sellTokenName": string,   // Sell token name
      "sellTokenSymbol": string,// Sell token symbol
      "sellWalletAddress": string,// Sell wallet address
      "txHash": string          // Transaction hash
    }
    ```
  </Tab>
</Tabs>

#### ウォレット取引

ウォレットのリアルタイム取引イベントを取得します。

**サブスクリプション形式**

```text theme={null}
dex-wallet-trade:{chain}_{walletAddress}
```

**パラメータ**

<ParamField query="chain" type="string" required>
  ブロックチェーン名、例：sol
</ParamField>

<ParamField query="walletAddress" type="string" required>
  ウォレットアドレス、例：GDekof7TtgeBKJtoVpkvzPin5mvhxSDyoUY2c1FK1T3i
</ParamField>

**レスポンスデータ形式**

<Tip>
  WebSocket APIは転送効率を最適化するために短縮フィールド名を返し、SDKはコードの可読性を向上させるために完全なフィールド名を返します。
</Tip>

<Tabs>
  <Tab title="WebSocket API">
    ```typescript theme={null}
    {
      "bwa": string,     // Maker address
      "ba": number,      // Base token amount
      "sa": number,      // Quote token amount
      "swa": string,     // Quote token address
      "bais": number,    // USD amount
      "t": number,       // Timestamp
      "k": string,       // Event type
      "h": string,       // Transaction hash
      "a": string        // Token address
    }
    ```
  </Tab>

  <Tab title="SDK">
    ```typescript theme={null}
    {
      "maker": string,        // Maker address
      "baseAmount": number,   // Base token amount
      "quoteAmount": number,  // Quote token amount
      "quoteAddress": string, // Quote token address
      "amountInUsd": number,  // USD amount
      "timestamp": number,    // Timestamp
      "event": string,       // Event type
      "txHash": string,      // Transaction hash
      "tokenAddress": string  // Token address
    }
    ```
  </Tab>
</Tabs>

### DEXプール関連

#### DEXプール残高

DEXプールのリアルタイム残高情報を取得します。

**サブスクリプション形式**

```text theme={null}
dex-pool-balance:{chain}_{poolAddress}
```

**パラメータ**

<ParamField query="chain" type="string" required>
  ブロックチェーン名、例：sol
</ParamField>

<ParamField query="poolAddress" type="string" required>
  プールアドレス
</ParamField>

**レスポンスデータ形式**

<Tip>
  WebSocket APIは転送効率を最適化するために短縮フィールド名を返し、SDKはコードの可読性を向上させるために完全なフィールド名を返します。
</Tip>

<Tabs>
  <Tab title="WebSocket API">
    ```typescript theme={null}
    {
      "a": string,     // Pool address
      "taa": string,   // Token A address
      "taliu": number, // Token A liquidity in USD
      "tba": string,   // Token B address
      "tbliu": number  // Token B liquidity in USD
    }
    ```
  </Tab>

  <Tab title="SDK">
    ```typescript theme={null}
    {
      "poolAddress": string,           // Pool address
      "tokenAAddress": string,         // Token A address
      "tokenALiquidityInUsd": number,  // Token A liquidity in USD
      "tokenBAddress": string,         // Token B address
      "tokenBLiquidityInUsd": number   // Token B liquidity in USD
    }
    ```
  </Tab>
</Tabs>

## 使用例

```typescript theme={null}
import { ChainStreamClient } from '@chainstream-io/sdk';
import { Resolution } from '@chainstream-io/sdk/openapi';

const client = new ChainStreamClient('YOUR_ACCESS_TOKEN');

// 直接サブスクライブするだけで、SDKが接続状態を自動検出し必要に応じて接続
client.stream.subscribeTokenCandles({
  chain: 'sol',
  tokenAddress: '6p6xgHyF7AeE6TZkSmFsko444wqoP15icUSqi2jfGiPN',
  resolution: Resolution._1m,
  callback: (data) => {
    console.log('ローソク足データ:', data);
  }
});

// ウォレット残高のサブスクライブ
client.stream.subscribeWalletBalance({
  chain: 'sol',
  walletAddress: 'YOUR_WALLET_ADDRESS',
  callback: (data) => {
    console.log('ウォレット残高:', data);
  }
});
```

### 再接続戦略

指数バックオフによる再接続を推奨します：

```typescript theme={null}
function reconnect(attempt) {
  const delay = Math.min(1000 * Math.pow(2, attempt), 10000);
  setTimeout(() => {
    connect();
  }, delay);
}
```

## 使用制限

| 制限項目         | 制限値    | 説明              |
| ------------ | ------ | --------------- |
| 最大サブスクリプション数 | 100/接続 | 超過分は拒否されます      |
| メッセージサイズ     | 100KB  | 超過分は切り捨てられます    |
| ハートビート間隔     | 30秒    | 定期的なハートビートが必要です |

## ベストプラクティス

1. **接続管理**
   * 単一のWebSocket接続を維持
   * 自動再接続を実装
   * 定期的なハートビートの送信

2. **エラーハンドリング**
   * 完全なエラー処理を実装
   * 詳細なエラー情報をログに記録
   * 指数バックオフによる再接続を使用

3. **パフォーマンス最適化**
   * サブスクリプション数を制御
   * メッセージキューメカニズムを実装
   * 使用していないサブスクリプションをクリーンアップ

## 完全な例

<Tabs>
  <Tab title="SDK使用（推奨）">
    ```typescript theme={null}
    import { ChainStreamClient } from '@chainstream-io/sdk';
    import { Resolution } from '@chainstream-io/sdk/openapi';

    const client = new ChainStreamClient('YOUR_ACCESS_TOKEN');

    // 直接サブスクライブするだけで、SDKが接続状態を自動検出し必要に応じて接続
    const subscription = client.stream.subscribeTokenCandles({
      chain: 'sol',
      tokenAddress: '6p6xgHyF7AeE6TZkSmFsko444wqoP15icUSqi2jfGiPN',
      resolution: Resolution._1m,
      callback: (data) => {
        console.log('ローソク足データ:', data);
      }
    });

    // サブスクリプション解除
    subscription.unsubscribe();
    ```

    <Note>
      SDKを使用する場合、認証、再接続、ハートビートなどはすべて自動的に処理されます。本番環境での使用を推奨します。

      * **TypeScript/JavaScript SDK**: [@chainstream-io/sdk](https://www.npmjs.com/package/@chainstream-io/sdk)
      * **Python SDK**: [chainstream-sdk](https://pypi.org/project/chainstream-sdk)
      * **Go SDK**: [chainstream-go-sdk](https://github.com/chainstream-io/chainstream-go-sdk)
      * **Rust SDK**: [chainstream-sdk](https://crates.io/crates/chainstream-sdk)
    </Note>
  </Tab>

  <Tab title="ネイティブWebSocket">
    ```typescript theme={null}
    class DexWebSocket {
      private ws: WebSocket;
      private reconnectAttempts = 0;
      private maxReconnectAttempts = 5;
      private subscriptions = new Set<string>();

      constructor(
        private baseUrl: string,
        private accessToken: string
      ) {
        this.connect();
      }

      private connect() {
        // Append token parameter to URL for authentication
        const url = `${this.baseUrl}?token=${this.accessToken}`;
        this.ws = new WebSocket(url);
        
        this.ws.onopen = () => {
          console.log('WebSocket connection established');
          this.reconnectAttempts = 0;
          // Resubscribe to previous channels
          this.resubscribe();
        };

        this.ws.onmessage = (event) => {
          this.handleMessage(JSON.parse(event.data));
        };

        this.ws.onclose = () => {
          console.log('WebSocket connection closed');
          this.reconnect();
        };

        this.ws.onerror = (error) => {
          console.error('WebSocket error:', error);
        };
      }

      private reconnect() {
        if (this.reconnectAttempts < this.maxReconnectAttempts) {
          const delay = Math.min(1000 * Math.pow(2, this.reconnectAttempts), 10000);
          this.reconnectAttempts++;
          console.log(`Attempting reconnection in ${delay}ms...`);
          setTimeout(() => this.connect(), delay);
        }
      }

      private resubscribe() {
        this.subscriptions.forEach(channel => {
          this.send({ type: "subscribe", channel });
        });
      }

      private handleMessage(data: any) {
        // Handle message
      }

      private send(data: any) {
        if (this.ws.readyState === WebSocket.OPEN) {
          this.ws.send(JSON.stringify(data));
        }
      }

      public subscribe(channel: string) {
        this.subscriptions.add(channel);
        this.send({ type: "subscribe", channel });
      }

      public unsubscribe(channel: string) {
        this.subscriptions.delete(channel);
        this.send({ type: "unsubscribe", channel });
      }
    }

    // Usage example
    const client = new DexWebSocket(
      "wss://realtime-dex.chainstream.io/connection/websocket",
      "YOUR_ACCESS_TOKEN"
    );
    ```
  </Tab>
</Tabs>
