Indices
接收訂閱股票最新指數行情資料
Example
Subscribe channel
- Python
- Node.js
from masterlink_sdk import MasterlinkSDK, Order
def handle_message(message):
print(f'market data message: {message}')
sdk = MasterlinkSDK()
accounts = sdk.login("Your ID", "Your password", "Your cert path", "Your cert password") # 需登入後,才能取得行情權限
sdk.init_realtime(accounts[0]) # 建立行情連線
stock = sdk.marketdata.websocket_client.stock
stock.on('message', handle_message)
stock.connect()
stock.subscribe({
'channel': 'indices',
'symbol': 'IR0001'
})
const { MasterlinkSDK } = require('masterlink');
const sdk = new MasterlinkSDK();
const accounts = sdk.login("Your ID", "Your password", "Your cert path", "Your cert password");
sdk.initRealtime(accounts[0]); // 建立行情連線
const stock = sdk.marketdata.webSocketClient.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"
}