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

# 4casters 推送 API

4casters 推送 API 透過原始 WebSocket 連線投遞即時的使用者和市場更新。

<h2 id="endpoints">
  端點
</h2>

* **使用者推送**：`wss://streaming-api.4casters.io/v2/user`
* **行情推送**：`wss://streaming-api.4casters.io/price-stream`

行情推送預設廣播全部市場更新。用戶端可以選擇將推送收窄到特定賽事、聯賽或運動項目 — 見 [訂閱](/zh-Hant/pages/streaming/price-feed#subscriptions)。

<h2 id="auth">
  認證
</h2>

兩路推送均使用 4Casters 令牌進行認證。在 WebSocket 握手時於
`Authorization` 請求標頭中傳送令牌。伺服器從令牌推導使用者
— **URL 中無需使用者名稱**。

<h3 id="get-a-token">
  獲取令牌
</h3>

沒有單獨的 API 金鑰。使用你的 4Casters 使用者名稱和密碼，呼叫 4Casters REST API 的
`/user/login` 端點登入。回應中包含可在此處使用的令牌。令牌有效期與輪換見
[認證](/zh-Hant/pages/authentication)。

見 [4Casters REST API 文件中的 `POST /user/login`](/zh-Hant/pages/rest/authentication)。

<h3 id="connect">
  連線
</h3>

<CodeGroup>
  ```javascript JavaScript theme={null}
  const WebSocket = require('ws');
  const token = process.env.FOURCASTERS_TOKEN;
  const ws = new WebSocket('wss://streaming-api.4casters.io/v2/user', {
    headers: { Authorization: token },
  });
  ```
</CodeGroup>


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.