📡 REST APIStock DataK-line Data

📊 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

ItemValue
API Endpointhttps://api.dataapi.io/v1/stock/kline
Request MethodGET
Data FormatJSON

📋 Request Parameters

Required Parameters ✅

ParameterTypeDescriptionExample
tickerstringStock symbolAAPL, GOOGL, TSLA
klineTypestringK-line type1m, 5m, 1h, 1d, 1w, 1M, 1y
tokenstringAPI access tokenyour_api_token

Optional Parameters ⚪

ParameterTypeDefaultDescriptionExample
startTimestringLast 7 daysStart time, auto-calculated if not provided2024-01-01 or 2024-01-01 09:30:00
endTimestringCurrent timeEnd time, uses current time if not provided2024-01-31 or 2024-01-31 16:00:00
limitnumber50Return quantity limit, default 50 records50 (maximum 1000)

📊 Response Parameters

Response Structure

FieldTypeDescription
codenumberResponse status code
statusstringResponse status
messagestringResponse message
dataarrayK-line data array

Data Fields

FieldTypeDescriptionExample
timestampnumberUnix timestamp (seconds)1704067200
datetimestringReadable datetime2024-01-01 09:30:00
opennumberOpening price150.25
highnumberHighest price152.80
lownumberLowest price149.90
closenumberClosing price151.75
volumenumberTrading volume1250000
amountnumberTrading amount189562500.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 data
  • 1h, 2h, 4h, 6h, 8h, 12h - Hour-level data
  • 1d, 3d - Day-level data
  • 1w - Week-level data
  • 1M - Month-level data
  • 1y - Year-level data

Time Format

  • Supports both YYYY-MM-DD and YYYY-MM-DD HH:MM:SS formats
  • 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

CodeDescriptionSolution
400Invalid parametersCheck parameter format and values
401Invalid tokenVerify API token is correct
403Permission deniedCheck token permissions
429Rate limit exceededReduce request frequency
500Server errorContact technical support