POSThistorical-international-oil-prices
国际原油历史价格查询
按日期范围查询 WTI 与布伦特原油历史价格。
接入文档
选择原油品种和日期范围,查询每日开盘价、收盘价、最高价、最低价、涨跌及交易量。
接入示例代码
提供 Shell、Python、Go、Java、PHP 等常见接入示例,便于直接接到现有项目里。
Shell 示例
curl --request POST \
--url 'https://openapi.toolkk.com/v1/historical-international-oil-prices' \
--header 'Content-Type: application/json' \
--header 'X-API-Key: YOUR_API_KEY' \
--data '{\n "code": "wti",\n "beginDate": "20260701",\n "endDate": "20260730"\n}'Python 示例
import os
import requests
url = "https://openapi.toolkk.com/v1/historical-international-oil-prices"
payload = {
"code": "wti",
"beginDate": "20260701",
"endDate": "20260730"
}
headers = {
"Content-Type": "application/json",
"X-API-Key": os.getenv("TOOLKK_API_KEY", "YOUR_API_KEY"),
}
response = requests.request("POST", url, headers=headers, json=payload, timeout=30)
response.raise_for_status()
print(response.json())Go 示例
package main
import (
"bytes"
"fmt"
"io"
"net/http"
)
func main() {
endpoint := "https://openapi.toolkk.com/v1/historical-international-oil-prices"
payload := []byte("{\n \"code\": \"wti\",\n \"beginDate\": \"20260701\",\n \"endDate\": \"20260730\"\n}")
req, err := http.NewRequest("POST", endpoint, bytes.NewBuffer(payload))
if err != nil {
panic(err)
}
req.Header.Set("Content-Type", "application/json")
req.Header.Set("X-API-Key", "YOUR_API_KEY")
resp, err := http.DefaultClient.Do(req)
if err != nil {
panic(err)
}
defer resp.Body.Close()
body, err := io.ReadAll(resp.Body)
if err != nil {
panic(err)
}
fmt.Println(string(body))
}Java 示例
import java.net.URI;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;
public class ToolkkExample {
public static void main(String[] args) throws Exception {
String payload = "{\n \"code\": \"wti\",\n \"beginDate\": \"20260701\",\n \"endDate\": \"20260730\"\n}";
HttpRequest request = HttpRequest.newBuilder()
.uri(URI.create("https://openapi.toolkk.com/v1/historical-international-oil-prices"))
.method("POST", HttpRequest.BodyPublishers.ofString(payload))
.header("Content-Type", "application/json")
.header("X-API-Key", "YOUR_API_KEY")
.build();
HttpResponse<String> response = HttpClient.newHttpClient()
.send(request, HttpResponse.BodyHandlers.ofString());
System.out.println(response.body());
}
}PHP 示例
<?php
$endpoint = 'https://openapi.toolkk.com/v1/historical-international-oil-prices';
$payload = "{\n \"code\": \"wti\",\n \"beginDate\": \"20260701\",\n \"endDate\": \"20260730\"\n}";
$ch = curl_init($endpoint);
curl_setopt_array($ch, [
CURLOPT_RETURNTRANSFER => true,
CURLOPT_CUSTOMREQUEST => 'POST',
CURLOPT_HTTPHEADER => [
'Content-Type: application/json',
'X-API-Key: YOUR_API_KEY',
],
CURLOPT_POSTFIELDS => $payload,
]);
$response = curl_exec($ch);
if ($response === false) {
throw new RuntimeException(curl_error($ch));
}
curl_close($ch);
echo $response;请求示例
{
"code": "wti",
"beginDate": "20260701",
"endDate": "20260730"
}响应示例
{
"data": [
{
"day": "20260730",
"code": "wti",
"open_price": 76.58,
"close_price": 77.12,
"max": 77.56,
"min": 75.98,
"diff": 0.71,
"trade_num": 238560
}
]
}请求字段
以下字段根据示例 JSON 自动提取,仅作接入参考。
| 字段路径 | 类型 | 示例值 |
|---|---|---|
| code | string | wti |
| beginDate | string | 20260701 |
| endDate | string | 20260730 |
响应字段
以下字段根据示例 JSON 自动提取,仅作接入参考。
| 字段路径 | 类型 | 示例值 |
|---|---|---|
| data | array | {"day":"20260730","code":"wti","open_price":76.58,"close_price":77.12,"max":77.56,"min":75.98,"diff":0.71,"trade_num":238560} |
| data[] | object | {...} |
| data[].day | string | 20260730 |
| data[].code | string | wti |
| data[].open_price | number | 76.58 |
| data[].close_price | number | 77.12 |
| data[].max | number | 77.56 |