You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Retry: include Cloudflare 5xx (520–524) and 408 in RETRYABLE_STATUS_CODES #192
RETRYABLE_STATUS_CODES = {429, 500, 502, 503, 504} omits the Cloudflare-origin transient 5xx range. Kalshi's production endpoint (api.elections.kalshi.com) is fronted by Cloudflare; brief origin blips surface as 520 (Unknown Error), 521 (Web Server Down), 522 (Connection Timed Out), 523 (Origin Unreachable), 524 (A Timeout Occurred), 525 (SSL Handshake Failed), and are designed to be retried by clients.
Today the SDK maps them to KalshiServerError (via the status >= 500 branch at _base_client.py:71) but fails fast instead of retrying — a production trader polling markets.get_orderbook() will see avoidable hard failures whenever the CDN→origin link has a hiccup during market-open bursts.
Standard codes also worth widening: 408 Request Timeout and 425 Too Early are both safe to retry on idempotent verbs.
Location
kalshi/_base_client.py:31
Evidence
# kalshi/_base_client.py:31RETRYABLE_STATUS_CODES= {429, 500, 502, 503, 504}
# DELETE excluded: cancel/batch_cancel are not safely idempotentRETRYABLE_METHODS= {"GET", "HEAD", "OPTIONS"}
Activity