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

# 安全流

> 通过 WebSocket 实时流式传输代币安全信号——狙击买入、捆绑上线、内部交易、开发者持仓与持有者数量变化，构建 rug 检测系统。

Datastream WebSocket 提供实时安全信号。可用于实时关注狙击活动、打包交易、内部人动向、开发者抛售和持有者集中度变化。

<Info>
  **URL:** `wss://datastream.solanatracker.io/{apiKey}`\
  适用于 Premium、Business 和 Enterprise 方案。
</Info>

## 狙击者追踪

订阅 `sniper:{tokenAddress}` 以在狙击钱包的余额发生变化(买入、卖出或部分退出)时获得通知。

```javascript theme={null}
const token = "6p6xgHyF7AeE6TZkSmFsko444wqoP15icUSqi2jfGiPN";
const ws = new WebSocket("wss://datastream.solanatracker.io/YOUR_API_KEY");

ws.onopen = () => {
  ws.send(JSON.stringify({ type: "join", room: `sniper:${token}` }));
};

ws.onmessage = (event) => {
  const msg = JSON.parse(event.data);
  if (msg.type !== "message") return;

  const d = msg.data;
  const direction = d.percentage > d.previousPercentage ? "INCREASED" : "DECREASED";
  console.log(`Sniper ${d.wallet} ${direction}`);
  console.log(`  Balance: ${d.tokenAmount} (${d.percentage}%)`);
  console.log(`  Previous: ${d.previousAmount} (${d.previousPercentage}%)`);
  console.log(`  Total sniper hold: ${d.totalSniperPercentage}%`);
  console.log(`  Total insider hold: ${d.totalInsiderPercentage}%`);
};
```

**Payload:**

```json theme={null}
{
  "wallet": "WalletAddress",
  "amount": "1000000000",
  "tokenAmount": 1000000,
  "percentage": 0.15,
  "previousAmount": 500000,
  "previousPercentage": 0.075,
  "totalSniperPercentage": 5.25,
  "totalInsiderPercentage": 12.5
}
```

***

## Bundler 追踪

订阅 `bundlers:{tokenAddress}` 以追踪参与打包交易的钱包。这通常意味着钱包是有意一起移动的。

```javascript theme={null}
ws.send(JSON.stringify({ type: "join", room: `bundlers:${token}` }));

ws.onmessage = (event) => {
  const msg = JSON.parse(event.data);
  if (msg.type !== "message") return;

  const d = msg.data;
  const action = d.tokenAmount > d.previousAmount ? "BOUGHT" : "SOLD";
  console.log(`Bundler ${d.wallet} ${action}`);
  console.log(`  Holdings: ${d.tokenAmount} (${d.percentage}%)`);
  console.log(`  Total bundler hold: ${d.totalBundlerPercentage}%`);
};
```

**Payload:**

```json theme={null}
{
  "wallet": "4ZwYf8okEL7vgyBDZEcas2mcpDAVujsgtthxRHCMDqyP",
  "amount": "7965607901843",
  "tokenAmount": 7965607.901843,
  "percentage": 0.79656,
  "previousAmount": 8997866.309773,
  "previousPercentage": 0.89979,
  "boughtAmount": 0,
  "boughtPercentage": 0,
  "totalBundlerPercentage": 22.83809
}
```

<Warning>
  `totalBundlerPercentage` 超过 20% 是强烈的危险信号——意味着大量供应量由打包钱包持有。
</Warning>

***

## 内部人追踪

订阅 `insider:{tokenAddress}` 以关注内部人钱包的动向。内部人是被识别为对代币有特权访问的钱包,例如部署者关联钱包或早期协调买家。

```javascript theme={null}
ws.send(JSON.stringify({ type: "join", room: `insider:${token}` }));

ws.onmessage = (event) => {
  const msg = JSON.parse(event.data);
  if (msg.type !== "message") return;

  const d = msg.data;
  console.log(`Insider ${d.wallet}: ${d.percentage}% (was ${d.previousPercentage}%)`);
  console.log(`  Total insider hold: ${d.totalInsiderPercentage}%`);
};
```

***

## 开发者持仓

订阅 `dev_holding:{tokenAddress}` 实时追踪代币创建者的持仓。创建者大量卖出是最强的风险信号之一。

```javascript theme={null}
ws.send(JSON.stringify({ type: "join", room: `dev_holding:${token}` }));

ws.onmessage = (event) => {
  const msg = JSON.parse(event.data);
  if (msg.type !== "message") return;

  const d = msg.data;
  const change = d.percentage - d.previousPercentage;
  const emoji = change < 0 ? "SOLD" : "ADDED";
  console.log(`Dev ${d.creator} ${emoji}: ${d.percentage}% (was ${d.previousPercentage}%)`);
};
```

**Payload:**

```json theme={null}
{
  "token": "6p6xgHyF7AeE6TZkSmFsko444wqoP15icUSqi2jfGiPN",
  "creator": "4Rz5xqikxtZ2s7wE9uQ6n2oLXQi6K65XGoYpKxf24Hqo",
  "amount": "150000000000",
  "percentage": 15.0,
  "previousPercentage": 20.0,
  "timestamp": 1739318753652
}
```

***

## 持有者变化

### 持有者数量

订阅 `holders:{tokenAddress}` 获取实时持有者数量更新:

```javascript theme={null}
ws.send(JSON.stringify({ type: "join", room: `holders:${token}` }));

ws.onmessage = (event) => {
  const msg = JSON.parse(event.data);
  if (msg.type === "message") {
    console.log(`Holders: ${msg.data.total}`);
  }
};
```

### 前 10 持有者

订阅 `top10:{tokenAddress}` 追踪前 10 个钱包之间的集中度:

```javascript theme={null}
ws.send(JSON.stringify({ type: "join", room: `top10:${token}` }));

ws.onmessage = (event) => {
  const msg = JSON.parse(event.data);
  if (msg.type !== "message") return;

  const totalPct = msg.data.holders.reduce((sum, h) => sum + h.percentage, 0);
  console.log(`Top 10 hold ${totalPct.toFixed(1)}% of supply`);
  msg.data.holders.forEach((h, i) => {
    console.log(`  #${i + 1} ${h.address}: ${h.percentage}%`);
  });
};
```

***

## 钱包监控

### 钱包交易

订阅 `wallet:{walletAddress}` 实时查看钱包的每次兑换:

```javascript theme={null}
const wallet = "FV1r15rbNKkJanXLheoJA7fXEq6NDuMJ3bukXuhJWyV1";

ws.send(JSON.stringify({ type: "join", room: `wallet:${wallet}` }));

ws.onmessage = (event) => {
  const msg = JSON.parse(event.data);
  if (msg.type !== "message") return;

  const t = msg.data;
  const fromToken = t.from?.token?.symbol;
  const toToken = t.to?.token?.symbol;
  console.log(`${fromToken} → ${toToken}: $${t.volume?.usd?.toFixed(2)}`);
};
```

### 钱包余额变化

订阅 `wallet:{walletAddress}:balance` 获取整体余额变化:

```javascript theme={null}
ws.send(JSON.stringify({ type: "join", room: `wallet:${wallet}:balance` }));
```

### 特定代币余额

订阅 `wallet:{walletAddress}:{tokenAddress}:balance` 监视单一代币余额:

```javascript theme={null}
ws.send(JSON.stringify({
  type: "join",
  room: `wallet:${wallet}:${token}:balance`
}));
```

***

## 费用追踪

订阅 `fees:{tokenAddress}` 以追踪代币的平台和网络费用:

```javascript theme={null}
ws.send(JSON.stringify({ type: "join", room: `fees:${token}` }));
```

***

## 示例:代币安全监视器

组合多个安全流以构建实时风险面板:

```javascript theme={null}
const token = "6p6xgHyF7AeE6TZkSmFsko444wqoP15icUSqi2jfGiPN";
const ws = new WebSocket("wss://datastream.solanatracker.io/YOUR_API_KEY");

const alerts = [];

ws.onopen = () => {
  // Subscribe to all safety signals
  ws.send(JSON.stringify({ type: "join", room: `sniper:${token}` }));
  ws.send(JSON.stringify({ type: "join", room: `bundlers:${token}` }));
  ws.send(JSON.stringify({ type: "join", room: `insider:${token}` }));
  ws.send(JSON.stringify({ type: "join", room: `dev_holding:${token}` }));
  ws.send(JSON.stringify({ type: "join", room: `top10:${token}` }));
  ws.send(JSON.stringify({ type: "join", room: `holders:${token}` }));
};

ws.onmessage = (event) => {
  const msg = JSON.parse(event.data);
  if (msg.type !== "message") return;

  const room = msg.room;
  const d = msg.data;

  if (room.startsWith("sniper:") && d.percentage < d.previousPercentage) {
    alerts.push(`Sniper selling: ${d.wallet} (${d.previousPercentage}% → ${d.percentage}%)`);
  }

  if (room.startsWith("bundlers:") && d.totalBundlerPercentage > 20) {
    alerts.push(`High bundler concentration: ${d.totalBundlerPercentage}%`);
  }

  if (room.startsWith("dev_holding:") && d.percentage < d.previousPercentage) {
    alerts.push(`Dev selling: ${d.percentage}% (was ${d.previousPercentage}%)`);
  }

  if (room.startsWith("top10:")) {
    const totalPct = d.holders.reduce((sum, h) => sum + h.percentage, 0);
    if (totalPct > 50) {
      alerts.push(`Top 10 hold ${totalPct.toFixed(1)}% — high concentration`);
    }
  }

  if (alerts.length > 0) {
    console.log(`[ALERT] ${alerts[alerts.length - 1]}`);
  }
};
```

***

## Room 参考

| Room                              | 您获得的内容       |
| --------------------------------- | ------------ |
| `sniper:{token}`                  | 狙击钱包余额变化     |
| `bundlers:{token}`                | Bundler 钱包活动 |
| `insider:{token}`                 | 内部人钱包动向      |
| `dev_holding:{token}`             | 开发者/创建者持仓    |
| `holders:{token}`                 | 总持有者数量       |
| `top10:{token}`                   | 前 10 持有者百分比  |
| `wallet:{wallet}`                 | 钱包的所有兑换      |
| `wallet:{wallet}:balance`         | 钱包余额变化       |
| `wallet:{wallet}:{token}:balance` | 特定代币余额       |
| `fees:{token}`                    | 费用追踪         |

<CardGroup cols={2}>
  <Card title="狙击检测(REST)" href="/cn/guides/sniper-detection">
    用于首批买家、bundler 和基于图表检测的 REST 端点。
  </Card>

  <Card title="实时价格与图表" href="/cn/guides/datastream-prices">
    流式传输实时价格并构建实时图表。
  </Card>
</CardGroup>
