NDRC Fuel Price Query API: 60-Day Historical Data for Gasoline and Diesel
This document describes a REST API interface for retrieving recent fuel price data published by China's National Development and Reform Commission (NDRC). The API provides pricing information for various fuel types across all Chinese provinces for the past 60 days.
API Overview
The endpoint returns fuel price records including:
- Date of price update
- Province/region name
- 92-octane gasoline price
- 95-octane gasoline price
- 98-octane gasoline price
- 0-diesel price
Request Parameters
Endpoint
GET https://www.xujian.tech/atlapi/data/oil/query/list
Query Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
| code | string | Yes | Authentication code obtained from the WeChat mini-program "数字续坚" by checking in on the homepage |
Response Format
The API returns a JSON object with the following structure:
{
"code": 200,
"msg": "succeed.",
"data": [
{
"id": "1",
"dateStr": "2023-11-26",
"city": "安徽",
"updatedAt": "2023-11-26 23:35:01",
"dataAt": "2023-11-26 10:00:01",
"y92": 7.87,
"y95": 8.42,
"y98": 9.44,
"y0": 7.62
}
]
}
Response Fields
| Field | Type | Description |
|---|---|---|
| code | integer | HTTP status code, 200 indicates success |
| msg | string | Status message ("succeed." on success) |
| data | array | Array of fuel price records |
Data Record Fields
| Field | Type | Description |
|---|---|---|
| id | string | Unique identifier for the record |
| dateStr | string | Date of the fuel pricce (YYYY-MM-DD format) |
| city | string | Province/region name (e.g., "安徽", "北京") |
| updatedAt | datetime | Timestamp when the record was updated in the database |
| dataAt | datetime | Timestamp when the data was fetched from NDRC |
| y92 | double | Price of 92-octane gasoline (元/升) |
| y95 | double | Price of 95-octane gasoline (元/升) |
| y98 | double | Price of 98-octane gasoline (元/升) |
| y0 | double | Price of 0-diesel (元/升) |
Example Request
curl "https://www.xujian.tech/atlapi/data/oil/query/list?code=YOUR_AUTH_CODE"
Example Response
{
"code": 200,
"msg": "succeed.",
"data": [
{
"id": "1",
"dateStr": "2023-11-26",
"city": "安徽",
"updatedAt": "2023-11-26 23:35:01",
"dataAt": "2023-11-26 10:00:01",
"y92": 7.87,
"y95": 8.42,
"y98": 9.44,
"y0": 7.62
},
{
"id": "2",
"dateStr": "2023-11-26",
"city": "北京",
"updatedAt": "2023-11-26 23:35:01",
"dataAt": "2023-11-26 10:00:01",
"y92": 7.92,
"y95": 8.43,
"y98": 9.39,
"y0": 7.63
}
]
}
Implementation Notes
- The data is updated daily around 10:00 AM Beijing time
- The database records are refreshed hourly
- The API returns data for all 31 Chinese provinces/municipalities
- Each province has one price record per date
- Historical data covers the most recent 60 days
JavaScript Example
async function fetchFuelPrices(authCode) {
const endpoint = 'https://www.xujian.tech/atlapi/data/oil/query/list';
const response = await fetch(`${endpoint}?code=${authCode}`);
const result = await response.json();
if (result.code === 200) {
return result.data;
} else {
throw new Error(`API Error: ${result.msg}`);
}
}
// Usage
const prices = await fetchFuelPrices('YOUR_CODE');
const latestDate = prices[0].dateStr;
console.log(`Latest prices from: ${latestDate}`);
Python Example
import requests
from datetime import datetime
def get_fuel_prices(auth_code: str) -> list:
"""Fetch fuel prices from NDRC API."""
endpoint = "https://www.xjian.tech/atlapi/data/oil/query/list"
params = {"code": auth_code}
response = requests.get(endpoint, params=params)
data = response.json()
if data.get("code") == 200:
return data.get("data", [])
else:
raise ValueError(f"API Error: {data.get('msg')}")
# Usage example
prices = get_fuel_prices("YOUR_AUTH_CODE")
for record in prices[:5]:
print(f"{record['city']}: 92# {record['y92']}, 0#柴油 {record['y0']}")