📊 Stock K-line Data API
Get stock K-line/candlestick data, including OHLCV data such as open price, high price, low price, close price, and volume
🔗 API Information
| Item | Value |
|---|---|
| API Endpoint | https://api.dataapi.io/v1/stock/kline |
| Request Method | GET |
| Data Format | JSON |
📋 Request Parameters
Required Parameters ✅
| Parameter | Type | Description | Example |
|---|---|---|---|
ticker | string | Stock symbol | AAPL, GOOGL, TSLA |
klineType | string | K-line type | 1m, 5m, 1h, 1d, 1w, 1M, 1y |
token | string | API access token | your_api_token |
Optional Parameters ⚪
| Parameter | Type | Default | Description | Example |
|---|---|---|---|---|
startTime | string | Last 7 days | Start time, auto-calculated if not provided | 2024-01-01 or 2024-01-01 09:30:00 |
endTime | string | Current time | End time, uses current time if not provided | 2024-01-31 or 2024-01-31 16:00:00 |
limit | number | 50 | Return quantity limit, default 50 records | 50 (maximum 1000) |
📊 Response Parameters
Response Structure
| Field | Type | Description |
|---|---|---|
code | number | Response status code |
status | string | Response status |
message | string | Response message |
data | array | K-line data array |
Data Fields
| Field | Type | Description | Example |
|---|---|---|---|
timestamp | number | Unix timestamp (seconds) | 1704067200 |
datetime | string | Readable datetime | 2024-01-01 09:30:00 |
open | number | Opening price | 150.25 |
high | number | Highest price | 152.80 |
low | number | Lowest price | 149.90 |
close | number | Closing price | 151.75 |
volume | number | Trading volume | 1250000 |
amount | number | Trading amount | 189562500.00 |
💡 Usage Examples
cURL Example
curl -X GET "https://api.dataapi.io/v1/stock/kline" \
-H "Content-Type: application/json" \
-d '{
"ticker": "AAPL",
"klineType": "1d",
"startTime": "2024-01-01",
"endTime": "2024-01-31",
"limit": 100,
"token": "your_api_token"
}'JavaScript Example
const response = await fetch('https://api.dataapi.io/v1/stock/kline', {
method: 'GET',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({
ticker: 'AAPL',
klineType: '1d',
startTime: '2024-01-01',
endTime: '2024-01-31',
limit: 100,
token: 'your_api_token'
})
});
const data = await response.json();
console.log(data);Python Example
import requests
import json
url = "https://api.dataapi.io/v1/stock/kline"
payload = {
"ticker": "AAPL",
"klineType": "1d",
"startTime": "2024-01-01",
"endTime": "2024-01-31",
"limit": 100,
"token": "your_api_token"
}
response = requests.get(url, json=payload)
data = response.json()
print(json.dumps(data, indent=2))✅ Success Response
{
"code": 200,
"status": "success",
"message": "Data retrieved successfully",
"data": [
{
"timestamp": 1704067200,
"datetime": "2024-01-01 09:30:00",
"open": 150.25,
"high": 152.80,
"low": 149.90,
"close": 151.75,
"volume": 1250000,
"amount": 189562500.00
},
{
"timestamp": 1704153600,
"datetime": "2024-01-02 09:30:00",
"open": 151.75,
"high": 154.20,
"low": 151.20,
"close": 153.40,
"volume": 1380000,
"amount": 211492000.00
}
]
}❌ Error Response
{
"code": 400,
"status": "error",
"message": "Invalid ticker symbol",
"data": null
}📝 Notes
K-line Types
1m,3m,5m,15m,30m- Minute-level data1h,2h,4h,6h,8h,12h- Hour-level data1d,3d- Day-level data1w- Week-level data1M- Month-level data1y- Year-level data
Time Format
- Supports both
YYYY-MM-DDandYYYY-MM-DD HH:MM:SSformats - If time is not specified, uses market opening/closing times by default
- All times are in market local timezone
Rate Limits
- Free plan: 100 requests/minute
- Professional plan: 1000 requests/minute
- Enterprise plan: Custom limits
🔧 Error Codes
| Code | Description | Solution |
|---|---|---|
| 400 | Invalid parameters | Check parameter format and values |
| 401 | Invalid token | Verify API token is correct |
| 403 | Permission denied | Check token permissions |
| 429 | Rate limit exceeded | Reduce request frequency |
| 500 | Server error | Contact technical support |