Skip to content

接口限頻 ​

接口調用頻率與歷史/訂閲額度是不同限制;請求通過其中一項,不代表其他限制也通過。

入口與業務限頻 ​

  • 入口層按 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)

返回後仍需檢查業務錯誤碼。