Skip to main content

開始使用 BETA

富果行情 WebSocket API 提供台股即時行情服務。透過 WebSocket API 可以滿足您想要接收即時行情的需求。

建立連線

您可以透過以下位置向富果行情 WebSocket API server 建立連線:

wss://api.fugle.tw/marketdata/v1.0/futopt/streaming

身份驗證

當驗證成功後,會收到以下訊息:

{
"event": "authenticated",
"data": {
"message": "Authenticated successfully"
}
}

若驗證失敗,則收到以下訊息:

{
"event": "error",
"data": {
"message": "Invalid authentication credentials"
}
}

Heartbeat

每隔 30 秒 WebSocket server 會送出一個 heartbeat 訊息:

{
"event": "heartbeat",
"data": {
"time": "<Timestamp>"
}
}

Ping/Pong

將以下 JSON 格式訊息發送到 WebSocket Server (state 為可選):

{
"event": "ping",
"data": {
"state": "<ANY>"
}
}

WebSocket Server 會回應以下訊息 (若 ping 未送 state 則不會有該欄位):

{
"event": "pong",
"data": {
"time": "<TIMESTAMP>",
"state": "<ANY>"
}
}

Channels

富果行情 WebSocket API 目前提供以下可訂閱頻道:

訂閱頻道

要訂閱一個頻道 JSON 格式訊息發送到 WebSocket Server:

{
"event": "subscribe",
"data": {
"channel": "<CHANNEL_NAME>",
"symbol": "<SYMBOL_ID>"
}
}

訂閱成功後,會收到以下事件回應:

{
"event": "subscribed",
"data": {
"id": "<CHANNEL_ID>",
"channel": "<CHANNEL_NAME>",
"symbol": "<SYMBOL_ID>"
}
}

支援訂閱同頻道的多檔股票:

{
"event": "subscribe",
"data": {
"channel": "<CHANNEL_NAME>",
"symbols": ["<SYMBOL_ID_1>", "<SYMBOL_ID_2>"]
}
}

訂閱成功後,會收到以下事件回應:

{
"event": "subscribed",
"data": [
{
"id": "<CHANNEL_ID>",
"channel": "<CHANNEL_NAME>",
"symbol": "<SYMBOL_ID_1>"
},
{
"id": "<CHANNEL_ID>",
"channel": "<CHANNEL_NAME>",
"symbol": "<SYMBOL_ID_2>"
}
]
}

取消訂閱

要取消已訂閱頻道,請將以下 JSON 格式訊息發送到 WebSocket Server:

{
"event": "unsubscribe",
"data": {
"id": "<CHANNEL_ID>"
}
}

取消訂閱成功後,會收到以下事件回應:

{
"event": "unsubscribed",
"data": {
"id": "<CHANNEL_ID>"
}
}

支援取消訂閱多個頻道:

{
"event": "unsubscribe",
"data": {
"ids": ["<CHANNEL_ID_1>", "<CHANNEL_ID_2>"]
}
}

取消訂閱成功後,會收到以下事件回應:

{
"event": "unsubscribed",
"data": [
{
"id": "<CHANNEL_ID_1>"
},
{
"id": "<CHANNEL_ID_2>"
}
]
}

訂閱資訊

要取得已訂閱的頻道,請將以下 JSON 格式訊息發送到 WebSocket Server:

{
"event": "subscriptions"
}

然後會收到以下事件回應:

{
"event": "subscriptions",
"data": [
{
"id": "<CHANNEL_ID>",
"channel": "<CHANNEL_NAME>",
"symbol": "<SYMBOL_ID>"
}
]
}

使用 SDK

富果行情 WebSocket API 提供 Python 與 Node.js SDK。您可以透過以下方式存取 WebSocket API:

from fugle_marketdata import WebSocketClient

client = WebSocketClient(api_key = 'YOUR_API_KEY')
futopt = client.futopt