Skip to content
AllTick
Troubleshooting

Market Data API: 401 & 429 Troubleshooting

Systematically diagnose 401 authentication failures and 429 rate limits by inspecting HTTP status, business return codes, token scope, and QPS.

Updated:
Maintained by:AllTick Technical Team
Audience:Developers troubleshooting failed API requests or rate-limit rejections

Core Takeaway · 30-Second Brief

Inspect both the HTTP status code and the JSON ret field to separate authentication errors (invalid, expired, or mismatched endpoint token) from rate limiting (excessive QPS). Fix auth issues immediately without retrying; handle rate limits by batching symbols, switching real-time workloads to WebSocket, and applying jittered exponential backoff.

01

Step-by-Step Diagnostic Flow

1Log the full HTTP status code, response body, and UTC timestamp (redact your API Token).
2When ret != 200, inspect msg to determine whether the failure is authentication/permission or rate limiting.
3For auth errors: verify the token string has no trailing whitespace, newline characters, or truncation.
4For permission errors: confirm the endpoint matches the asset class (e.g., do not query forex tickers on quote-stock-b-api).
5For rate limits: measure actual requests per second across all workers against your plan tier limit.

02

Symptom-to-Cause Reference

SymptomMost Likely CauseRemediation
Every request fails immediatelyMissing or mistyped tokenPrint token length and first/last characters to verify
Works locally, fails in productionEnvironment variable missing in deploymentCheck container/CI secret injection
Stocks succeed, Forex failsEndpoint prefix mismatchUse quote-b-api for FX/metals and quote-stock-b-api for equities
Succeeds initially, then failsQPS or quota limit exceededThrottle request rate and add exponential backoff
Multi-worker spikes fail togetherMultiple processes sharing one tokenCentralize scheduling or cache shared responses

03

Exponential Backoff Retry Pattern

pythonpython
import os, random, time
import requests
def get_with_backoff(url: str, params: dict, retries: int = 5) -> dict:
delay = 1.0
for attempt in range(retries):
resp = requests.get(url, params=params, timeout=10)
body = resp.json() if resp.content else {}
if resp.status_code == 401 or body.get("ret") == 401:
raise RuntimeError(f"Auth failed (ret=401): {body.get('msg', 'token invalid')}")
if resp.ok and body.get("ret") == 200:
return body
if attempt == retries - 1:
raise RuntimeError(f"Retries exhausted: status={resp.status_code} body={body}")
time.sleep(delay + random.uniform(0, 0.5))
delay = min(delay * 2, 30)
return {}
if __name__ == "__main__":
url = "https://quote.alltick.co/quote-stock-b-api/trade-tick"
params = {
"token": os.getenv("ALLTICK_API_TOKEN", "YOUR_API_TOKEN"),
"query": '{"trace":"backoff-test","data":{"symbol_list":[{"code":"700.HK"}]}}',
}
print(get_with_backoff(url, params))

04

How to Reduce Request Volume

  • Batch multiple tickers into a single symbol_list request instead of polling one symbol per HTTP call.
  • Migrate real-time price monitoring from high-frequency REST polling to WebSocket streaming.
  • Cache responses briefly in Redis or memory when multiple downstream services read the same symbols.
  • Funnel outbound API requests through a central rate limiter when running multiple worker processes.

Sources & Verification · 2026-10-13

Relevant endpoint, field, and exchange rules were checked against the primary specifications linked below.

Python examples passed ast.parse on Python 3.14.0. This checks syntax only; dependencies, runtime compatibility, and network responses were not tested.

Authenticated AllTick requests and production end-to-end tests were not run for this review. Record your token plan, library versions, market session, ret/trace, and observed results when reproducing these checks.

Reproduce before deployment

  • Test missing, revoked, and wrong-scope tokens; inspect HTTP status and JSON ret/msg independently. Permission and quota errors do not necessarily use HTTP 401/429.
  • Coordinate limits across token-sharing workers, use bounded jittered backoff, and stop permanent authentication retries. Retain a redacted trace and timestamp.