Indices
接收訂閱股票最新指數行情資料
Example
Subscribe channel
- Python
- Node.js
from fugle_marketdata import WebSocketClient
def handle_message(message):
print(message)
def main():
client = WebSocketClient(api_key='YOUR_API_KEY')
stock = client.stock
stock.on('message', handle_message)
stock.connect()
stock.subscribe({
'channel': 'indices',
'symbol': 'IR0001'
})
if __name__ == '__main__':
main()
const { WebSocketClient } = require('@fugle/marketdata');
const client = new WebSocketClient({ apiKey: 'YOUR_API_KEY' });
const stock = client.stock;
stock.connect().then(() => {
stock.subscribe({ channel: 'indices', symbol: 'IR0001' });
});
stock.on('message', (message) => {
const data = JSON.parse(message);
console.log(data);
});
Receive data
{
"event": "data",
"data": {
"symbol": "IR0001",
"type": "INDEX",
"exchange": "TWSE",
"index": 35276.44,
"time": 1686114510000000
},
"id": "<CHANNEL_ID>",
"channel": "indices"
}