接口限频
接口调用频率与历史/订阅额度是不同限制;请求通过其中一项,不代表其他限制也通过。
入口与业务限频
- 入口层按 IP 限制:同一个 IP 对行情、交易、加密货币、模拟交易各类接口的访问频率,每类每分钟不超过 100 次。
- 行情网关还执行当前业务限频策略,可按用户、用户与接口、用户与接口组、单接口或全局统计。多连接、多个应用实例可能共享同一计数。
- 各规则可以同时生效;达到任一限制即可能被拒绝。阈值和时间窗口由当前策略决定,不应把入口 IP 限制视为账号可用调用量。
- 对历史 K 线,只有有效
page_token才能豁免被标记为“首请求”的历史规则;全局、接口及其他用户规则仍执行。仅传next_time仍按首请求计数。
如何识别限频
行情网关的业务限频通常仍返回 HTTP 200。旧信封检查 ret_code=-11 与 error.code=rate_limited;使用新信封的接口检查 code=-11 与 message。不能只判断 HTTP 429。
Retry-After 响应头表示建议等待的秒数。历史同标的正在预占时也返回 -11,但 error.code=history_quota_busy,建议 1 秒后重试。-12 history_quota_exceeded 是新历史目标额度不足,需等待额度释放;-13 quota_unavailable 表示相关服务暂时不可用,不能当成零用量。
json
{
"ret_code": -11,
"ret_msg": "rate limit exceeded",
"error": {
"code": "rate_limited",
"message": "too many requests, retry after 2s"
}
}查询与重试建议
批量查询、缓存静态数据,避免并发重复请求。对可安全重试的 GET 查询,可按以下方式同时处理入口 HTTP 429 与行情业务限频。不要把此示例直接用于下单等写操作。
python
import time
import requests
def get_with_backoff(url, headers, params=None, attempts=3):
for attempt in range(attempts):
response = requests.get(url, headers=headers, params=params, timeout=15)
payload = response.json() if response.status_code == 200 else {}
retryable = response.status_code == 429 or (
response.status_code == 200
and payload.get("ret_code", payload.get("code")) in (-11, -13)
)
if not retryable or attempt == attempts - 1:
response.raise_for_status()
return payload
delay = response.headers.get("Retry-After", "")
time.sleep(max(1, int(delay)) if delay.isdigit() else 2 ** attempt)返回后仍需检查业务错误码。