DEV Community

Ahmed Trading
Ahmed Trading

Posted on Edited on

Building Bots That Survive a Breach: Rate Guards, Kill Switches, and October 29

Building Bots That Survive a Breach: Rate Guards, Kill Switches, and October 29

When a platform gets breached, most trading bots fail in one of three boring ways: they keep hammering endpoints that are being drained, they hold session keys nobody can revoke, or they have no way to stop themselves. October 29, 2026 — when a hijacked script drained $2.73M from 737 Polymarket accounts and Binance lost $6.3B the same day — was a live drill for all three failure modes.

This is the bot-survivability checklist I run after every incident. It assumes you already have a working bot; if you don't, the Polymarket bot build guide covers the foundation.

1. Rate guards: your bot is a client, treat it like one

After a breach, platforms throttle, pause, or reshuffle endpoints while they triage. A bot without request budgeting hammers through the throttle window and gets its key flagged — sometimes permanently, sometimes along with the account.

Concretely: every outbound call goes through a token-bucket limiter keyed by endpoint class, with exponential backoff on 429/5xx and a circuit breaker that trips after N consecutive failures. My rate-guard reference implementation shows the pattern; the same post covers per-endpoint budgets for the current API.

2. Session keys with expiry, never raw keys

The wallets drained on October 29 were not bot wallets — but the lesson transfers. A bot holding your raw private key is a bot that can lose everything your key can lose. A bot holding a scoped session key with an expiry is a bot that can lose a bounded amount for a bounded time.

Issue session keys with the narrowest scope your strategy allows, rotate them on a schedule, and rehearse revocation before you need it. The session keys guide covers issuance and rotation on Polymarket specifically.

3. A kill switch you can hit from your phone

Every trading bot needs a component that stops it — not a config change, not a redeploy, a switch. Mine is a dead-simple endpoint check: the bot polls a local flag file every loop, and if the flag says "halt", it cancels open orders, closes nothing (closing is a decision, not a reflex), and goes idle.

On October 29, the bots that survived were the ones whose operators could halt them in one action from a phone, without SSH-ing into anything. If your kill switch requires infrastructure access during an incident, you don't have one — you have a hope.

4. Breach-day behavior is different from normal behavior

The checklist above is table stakes. Breach-day behavior is a separate mode, and it should be explicit in your code:

  • On circuit-breaker trip: stop quoting, cancel resting orders, hold positions. Don't "wait it out" with live orders in a book that's being repriced by panic.
  • On session-key anomaly (any signature request you didn't initiate): halt, revoke, rotate. Assume compromise first, investigate after.
  • On platform announcement of an incident: assume the announcement lags reality by minutes to hours. Your risk window starts at first anomaly, not first announcement.

The first-24-hours playbook is written for humans with drained wallets, but the ordering logic — move what survives first, revoke second, document third — maps directly onto bot priorities.

5. The audit that costs ten minutes

After any incident: every approval on every wallet the bot touches, every session key, every standing allowance — reviewed and trimmed. Unlimited approvals don't survive my audits anymore, and neither should yours. It's the same revoke discipline human traders need, applied to machine traders.

October 29 didn't create new risks. It priced the ones everyone was already carrying.


Background: the full October 29 double-breach analysis, and API authentication mechanics if you're reviewing your key handling. General reading on the Binance side: 2026 Binance hack.

Top comments (0)