← Back to Documentation

API文档

TradeWar Insight API使用指南

API概述

TradeWar Insight提供强大的API接口,允许开发者将我们的预测数据和分析工具集成到自己的应用中。 我们的API采用RESTful架构,支持JSON格式的数据交换。

认证与授权

所有API请求都需要进行认证。我们使用API密钥进行认证:

curl -H "Authorization: Bearer YOUR_API_KEY" https://api.tradewarinsight.com/v1/predictions

您可以在开发者控制台生成和管理您的API密钥。不同的API密钥有不同的访问权限和速率限制。

主要API端点

预测市场API

  • GET /v1/predictions - 获取预测列表
  • GET /v1/predictions/{id} - 获取特定预测详情
  • GET /v1/predictions/{id}/history - 获取预测历史数据
  • POST /v1/predictions/{id}/forecast - 提交预测

数据分析API

  • GET /v1/data/trade - 获取贸易数据
  • GET /v1/data/indicators - 获取经济指标数据
  • GET /v1/data/countries/{code} - 获取特定国家数据
  • GET /v1/data/visualization - 获取可视化数据

用户API

  • GET /v1/user/profile - 获取用户资料
  • GET /v1/user/forecasts - 获取用户预测历史
  • GET /v1/user/points - 获取用户积分信息

请求限制

为了确保API的稳定性和公平使用,我们对API请求实施了速率限制:

  • 基础计划: 60次请求/分钟
  • 专业计划: 300次请求/分钟
  • 企业计划: 1000次请求/分钟

超出限制的请求将收到429状态码(Too Many Requests)。

响应格式

所有API响应都使用JSON格式。成功的响应通常包含以下结构:

{
  "status": "success",
  "data": { ... },
  "meta": {
    "page": 1,
    "per_page": 20,
    "total": 100
  }
}

错误响应包含错误代码和详细信息:

{
  "status": "error",
  "error": {
    "code": "invalid_parameter",
    "message": "Invalid date range specified"
  }
}

示例代码

JavaScript示例:

// 获取最新预测
fetch('https://api.tradewarinsight.com/v1/predictions?limit=10', {
  headers: {
    'Authorization': `Bearer ${apiKey}`
  }
})
.then(response => response.json())
.then(data => console.log(data))
.catch(error => console.error('Error:', error));

Python示例:

import requests

# 获取特定国家的贸易数据
url = "https://api.tradewarinsight.com/v1/data/countries/CN"
headers = {"Authorization": f"Bearer {api_key}"}
params = {"start_date": "2023-01-01", "end_date": "2023-12-31"}

response = requests.get(url, headers=headers, params=params)
data = response.json()
print(data)