1. 接口概述
StockTV提供印度股票市場的實時行情數據接口,包括:
- 印度NSE和BSE交易所的股票實時行情
- 指數數據(Nifty 50, SENSEX等)
- 歷史K線數據
- 公司基本信息
- IPO新股信息
- 漲跌排行榜
支持HTTP REST API和WebSocket兩種接入方式,毫秒級延遲,7×24小時穩定服務。
2. 獲取API Key
使用前需聯繫StockTV獲取API Key:
- 官網
- 聯繫方式
3. 印度股票接口列表
3.1 獲取印度股票列表
接口地址
GET /stock/stocks
請求參數
| 參數名 | 必填 | 類型 | 説明 |
|---|---|---|---|
| countryId | 是 | int | 印度國家ID為14 |
| pageSize | 否 | int | 每頁數量,默認10 |
| page | 否 | int | 頁碼,默認1 |
| key | 是 | string | API密鑰 |
請求示例
GET https://api.stocktv.top/stock/stocks?countryId=14&pageSize=10&page=1&key=您的API_KEY
響應示例
{
"code": 200,
"message": "操作成功",
"data": {
"records": [
{
"id": 41602,
"symbol": "TCS",
"name": "Tata Consultancy",
"last": 3856.15,
"chg": 12.45,
"chgPct": 0.32,
"high": 3872.30,
"low": 3825.60,
"volume": 1254875,
"exchangeId": 46, // 46=NSE, 74=BSE
"countryId": 14,
"open": true // 是否開市
},
...
],
"total": 1850
}
}
3.2 查詢特定股票
接口地址
GET /stock/queryStocks
請求參數
| 參數名 | 必填 | 類型 | 説明 |
|---|---|---|---|
| id | 否 | int | 股票ID |
| symbol | 否 | string | 股票代碼如"RELIANCE" |
| name | 否 | string | 股票名稱 |
| key | 是 | string | API密鑰 |
請求示例
GET https://api.stocktv.top/stock/queryStocks?symbol=RELIANCE&key=您的API_KEY
3.3 獲取印度指數數據
接口地址
GET /stock/indices
請求參數
| 參數名 | 必填 | 類型 | 説明 |
|---|---|---|---|
| countryId | 是 | int | 印度國家ID為14 |
| key | 是 | string | API密鑰 |
響應示例
{
"code": 200,
"data": [
{
"id": 17940,
"name": "Nifty 50",
"symbol": "NSEI",
"last": 22967.65,
"chg": 369.85,
"chgPct": 1.64
},
{
"id": 17941,
"name": "S&P BSE SENSEX",
"symbol": "BSESN",
"last": 75385.24,
"chg": 412.56,
"chgPct": 0.55
}
]
}
3.4 獲取K線數據
接口地址
GET /stock/kline
請求參數
| 參數名 | 必填 | 類型 | 説明 |
|---|---|---|---|
| pid | 是 | int | 股票ID |
| interval | 是 | string | 時間間隔: PT5M,PT15M,PT1H,P1D等 |
| key | 是 | string | API密鑰 |
請求示例
GET https://api.stocktv.top/stock/kline?pid=7310&interval=PT15M&key=您的API_KEY
響應示例
{
"code": 200,
"data": [
{
"time": 1719818400000,
"open": 239.42,
"high": 239.6,
"low": 239.42,
"close": 239.6,
"volume": 12500
},
...
]
}
3.5 WebSocket實時數據
連接地址
wss://ws-api.stocktv.top/connect?key=您的API_KEY
訂閲消息格式
{
"action": "subscribe",
"pids": [41602, 17940] // 股票ID和指數ID數組
}
實時推送數據示例
{
"pid": 41602,
"symbol": "TCS",
"last": 3856.75,
"chg": 12.45,
"chgPct": 0.32,
"volume": 1254875,
"timestamp": 1725002394
}
4. 示例代碼
Python HTTP請求示例
import requests
# 獲取印度股票列表
url = "https://api.stocktv.top/stock/stocks"
params = {
"countryId": 14,
"pageSize": 10,
"key": "您的API_KEY"
}
response = requests.get(url, params=params)
print(response.json())
# 獲取Nifty 50指數數據
index_url = "https://api.stocktv.top/stock/indices"
index_params = {
"countryId": 14,
"key": "您的API_KEY"
}
index_data = requests.get(index_url, params=index_params).json()
print(index_data)
JavaScript WebSocket示例
const ws = new WebSocket("wss://ws-api.stocktv.top/connect?key=您的API_KEY");
ws.onopen = () => {
console.log("Connected");
// 訂閲TCS股票和Nifty指數
ws.send(JSON.stringify({
action: "subscribe",
pids: [41602, 17940]
}));
};
ws.onmessage = (event) => {
const data = JSON.parse(event.data);
console.log("Received:", data);
};
5. 注意事項
- 所有API請求必須包含有效的key參數
- 印度市場交易時間:IST 9:15-15:30(週一至週五)
- 實時數據通過WebSocket推送更高效
- 歷史數據可通過K線接口獲取
如需更多幫助,請聯繫:
- 官網
- 文檔
- Demo代碼