Bot Failover Setup: A Practical Guide for Crypto Bots

October 25, 2026Updated October 27, 202614 MIN4 views
Bot Failover Setup: A Practical Guide for Crypto Bots

A bot failover setup is a set of rules and components that detect a failed trading process or connection and hand control to a standby, without losing state and without two instances trading at once. For a crypto trading bot, that means five things: detecting the failure, reconnecting cleanly, avoiding duplicate orders, allowing only one active instance, and alerting a human when automation cannot recover on its own. This guide walks through each in the order you would build it.

It is written for traders who run their own bots on a VPS or home server, and for those deciding how much of this infrastructure they want to own. It describes engineering process, not returns. Failover protects execution continuity. It does not make a strategy profitable.

Darkbot
Keep Crypto Bot Trading More Resiliently
Darkbot automates crypto trading across digital asset exchanges, with real-time analytics and portfolio management to help reduce manual oversight.
Run paper trading

TL;DR

  • Treat disconnects as routine events. Design a deterministic recovery path (detect, back off, resynchronize) instead of hoping for a stable connection.
  • Generate client-side order IDs so a retry after a timeout can check status instead of creating a duplicate order.
  • Run exactly one active instance. A standby that wakes up while the primary is still alive is a bigger risk than downtime.
  • Add an external dead man’s switch: a heartbeat that raises an alert when the bot stops reporting, because a crashed process cannot report its own crash.
  • Rehearse failover on paper trading or a testnet before you rely on it with capital.

What failover means for a trading bot

In general infrastructure writing, failover is the switch to a standby component or backup data center when the primary fails, with minimal interruption. Imperva’s overview of instant failover describes the pattern in those terms. For a web server, a brief gap is an inconvenience. For a trading bot, the stakes differ in three ways.

  1. State is financial. The bot holds open orders and positions on an exchange. A standby needs to learn that state, not assume it.
  2. Duplicate action is worse than no action. Two bots placing the same order double exposure. A standby that stays idle only delays a trade.
  3. The exchange is a third party. You control your server, but not the exchange’s connection limits, session expiry or maintenance windows.

That is why the usual web-hosting playbook needs adjustments. A bot failover design is mostly about state reconciliation and mutual exclusion, and only secondarily about moving traffic.

Failure modes to plan for

Before choosing tools, list what can actually break. Most bot outages fall into a short list:

Failure Typical cause What recovery needs
Dropped market data or order stream Network blip, exchange-side session limit Detect, reconnect, resync order book
Expired session credential Server-side token expiry with no notification Scheduled refresh, validity monitoring
Rate-limit rejection Reconnect storms, excessive requests Backoff with jitter, request budgeting
Crashed or hung process Bug, memory exhaustion, infinite loop External heartbeat, automatic restart
Host or region outage Provider incident, power, ISP Standby on a different host or network
Duplicate execution Two instances live after a split Lock or lease with a single owner

The first rows are far more frequent than the last. Many traders build a second server for the rare host outage and leave connection handling naive, which inverts the priorities. Start at the top of the table.

Step 1: Define what recovery has to achieve

Generic failover guides begin with recovery objectives. Trilio’s guide to automatic failover lists defining RTO and RPO first, then choosing an architecture, then configuring health checks. The same order works for a bot.

  • Recovery time objective (RTO): how long can the bot be offline before it matters? A grid or rebalancing strategy that acts every few hours tolerates minutes. A strategy reacting to short-term moves tolerates far less.
  • Recovery point objective (RPO): how much state can you afford to lose? If the bot keeps its order and position records only in memory, the answer is all of it. If it writes them to disk or a database after every change, the answer is close to nothing.
  • Exposure while offline: do open positions have exchange-side stop or protective orders, or does the bot manage exits itself? If the bot is the only thing managing risk, downtime is risk. Exchange-resident protective orders reduce what failover has to cover.

Write these three answers down. They decide whether a simple auto-restart is enough or whether you need a warm standby.

Step 2: Make disconnects deterministic

Streaming feeds are the most common source of trouble. In their guide to execution systems at scale, quant.engineering argue that WebSocket disconnections are normal events to be handled gracefully, not exceptions. The recovery sequence they describe is worth adopting as written:

  1. Detect the drop quickly. Watch for missing heartbeats or stalled sequence numbers rather than waiting for the socket to report an error.
  2. Reconnect with exponential backoff and jitter. Randomized delays prevent many clients from hammering shared exchange infrastructure at the same instant after an outage.
  3. Fetch a fresh REST snapshot. Resynchronize the order book from the snapshot first.
  4. Replay the delta updates that arrived after the snapshot, so the local book matches the exchange.

The logic is cause and effect. If you resume streaming deltas without a snapshot, any missed message leaves your local book silently wrong, and every decision downstream inherits the error. A bot that trades on a stale book is worse than one that is offline, because nothing signals the problem.

A related design principle comes from adapter-layer engineering. One open-source exchange adapter write-up recommends validating payloads strictly and normalizing upstream failures into consistent error categories, such as one for connectivity problems and another for rate limiting. The benefit is isolation: your strategy logic receives a clean “exchange unavailable” or “slow down” signal and never needs to parse exchange-specific glitches. Your failover code can then branch on those categories. Retry on rate limits after waiting. Escalate on repeated connectivity failures.

Step 3: Protect against duplicate orders

The most dangerous moment in failover is an order request that times out. Did it reach the exchange or not? If the bot simply retries, it may place the order twice.

The standard remedy, described in the same quant.engineering guide, is to generate a unique order ID on the client side before sending anything. The ID makes the operation idempotent. After a timeout the bot queries the status of that ID. If the order exists, it carries on. If not, it resubmits with the same ID.

In practice:

  • Create the ID, and persist it, before the request goes out.
  • After any ambiguous failure, query by that ID before doing anything else.
  • On startup, whether a normal restart or a standby taking over, reconcile open orders and balances from the exchange before the strategy is allowed to act. Treat the exchange as the source of truth and your local database as a cache.

This reconciliation step is what separates a failover that resumes safely from one that merely resumes.

Step 4: Allow only one active instance

A classic question in developer forums is how to run a secondary server for a bot, for example a hosted primary with a spare machine at home, while ensuring only one instance runs at a time. A Stack Overflow thread on a redundant failover server for a Discord bot frames exactly this requirement. For a trading bot, the consequence of getting it wrong is financial rather than cosmetic.

Three workable approaches, from simplest to most robust:

  • Cold standby, manual promotion. The standby is configured but stopped. When an alert fires, you confirm the primary is truly down (and stop it if unsure), then start the standby. Slow, but it cannot double-trade by accident.
  • Lease or lock in shared storage. Each instance must hold a lease, a small record with an expiry time stored in a database or key-value store, to trade. The primary renews it regularly. If renewal stops, the lease expires and the standby may claim it. Because the primary stops trading when it cannot renew, a network split pauses it instead of duplicating it.
  • Orchestrator-managed single replica. A container scheduler configured for one replica restarts a failed process and, with correct settings, avoids running two at once.

In all three, the rule is the same: the instance that cannot prove it holds the lock does not place orders. Make the bot fail closed.

If you use virtual IP tools such as keepalived, remember that moving an IP address does not by itself guarantee the old node stopped trading. Pair address failover with a trading lock.

Step 5: Monitor with a dead man’s switch

Standard health endpoints answer “is the server up?” They often miss a process that is alive but stuck in an infinite loop, or one that has crashed silently. VoiceOfChain’s academy guide on WebSocket failover recommends a dead man’s switch: the bot sends a heartbeat to an external service every minute, and an alert triggers if heartbeats stop for a threshold such as five minutes.

The key property is direction. The bot reports in, rather than a monitor polling it. Silence itself is the alarm, so it works even when the bot cannot say anything. Run the monitor on infrastructure separate from the bot, otherwise a single host failure silences both.

A useful alert includes:

  • the last successful heartbeat time,
  • the last known open orders and positions,
  • the instance that held the lock.

That lets whoever receives the alert decide quickly whether to promote the standby or wait.

Watch for silent credential expiry

The same guide notes that Binance’s user-data stream key (listenKey) is a common silent failure, because it expires server-side with no push notification. Bots that do not renew and verify it keep running while no longer receiving account updates. Schedule a renewal well inside the expiry window, and treat an unexpected silence on the account stream as a fault in its own right.

Step 6: Respect exchange connection constraints

Failover logic that reconnects aggressively can break exchange rules and make an outage longer. Check the documentation of each venue you trade on. For Binance, the research notes three constraints relevant here:

  • Connections are closed after 24 hours, so a healthy bot reconnects on schedule, not only after failure. VoiceOfChain reports the same limit.
  • The server pings periodically and expects a pong in return. The Binance WebSocket API documentation covers this behavior, including the response window.
  • New connections are limited per IP address. Binance’s rate limit page gives 300 connection attempts per 5 minutes per IP.

The third point matters for failover design. If a standby in the same network shares an IP with the primary, a reconnect storm from both counts against one budget. Backoff with jitter keeps you well inside the limit.

Setups that route signals from charting tools into exchanges add another layer: alert delivery, webhook handling and exchange limits all become part of the chain. If that is your architecture, a walkthrough on how to automate TradingView alerts on Bybit shows how exchange-specific details shape the setup, and each hop is a place your failover plan must cover.

Limits change, so confirm current values in each exchange’s documentation before you hard-code them.

Step 7: Rehearse the failure

An untested failover plan is an assumption. Build a short drill list and run it on paper trading or an exchange testnet (Binance publishes a testnet endpoint in the same documentation):

  1. Kill the bot process mid-cycle. Confirm restart, reconciliation and no duplicate orders.
  2. Block outbound network access for several minutes. Confirm backoff, snapshot resync and correct book state afterward.
  3. Pause the primary without killing it, so that it stays alive but cannot renew its lease. Confirm the standby takes over and the primary stops trading.
  4. Stop sending heartbeats. Confirm the alert arrives on a channel you actually watch, within the threshold you set.
  5. Simulate an order timeout. Confirm the bot queries by client ID before retrying.

Record results and rerun after any significant change to the bot or hosting. Many failures in real incidents trace to a path nobody exercised.

Our perspective: where failover belongs in the stack

We see failover as one expression of a broader principle: automation is only as dependable as its worst-handled exception. A trading system earns trust through the unglamorous parts: how it reconnects, how it avoids duplicate orders, and how it tells a person that it cannot continue.

Our perspective: where failover belongs in the stack — overview diagram

That is why we build around systematic execution and structured risk control, with human oversight kept in the loop. Orders go directly from the platform to your exchange through API keys you create and scope yourself, which keeps the number of moving parts you must secure and monitor small. For a deeper look at that layer, our articles on API-based exchange integration and on crypto trading bot security cover key permissions and data handling.

Our view on the build-versus-use question is plain. Running your own failover is a legitimate choice if you enjoy infrastructure and can test it regularly. For many traders, the time goes to maintaining servers instead of reviewing strategy logic and risk settings. Whichever route you take, no failover design removes market risk. It only removes one class of operational risk. Our overview of the risks of crypto bot automation sets out the rest.

— Grisha

Running less of this yourself

If you would rather not operate servers, locks and heartbeat monitors, Darkbot is an AI-based crypto trading automation platform that runs strategies against your exchange accounts through API keys. You can start on the Free plan, or choose Standard at $12.50 per month or Premium at $25.00 per month. Enterprise is available on request. Compare the tiers on the Darkbot pricing page. To see how bots connect to a major venue first, read our guide to using trading bots on Binance.

A minimal checklist

Use this as a final review before going live:

  • Recovery time and state-loss tolerance are written down.
  • Reconnect uses backoff with jitter, then a REST snapshot, then deltas.
  • Every order carries a persisted client-side ID.
  • Startup always reconciles orders and balances with the exchange.
  • Only the lock holder may trade, and the bot fails closed.
  • An external heartbeat alerts you on silence, on a channel you watch.
  • Session credentials are renewed on schedule and monitored.
  • Scheduled reconnects respect exchange connection limits.
  • Drills have been run on paper trading or a testnet.

For the surrounding workflow, our step by step trading workflow shows where monitoring fits in a full automation routine.

FAQ

Do I need a second server for a crypto bot failover setup?

Not always. If your strategy tolerates several minutes of downtime and the bot persists its state, an automatic process restart plus an external heartbeat alert covers most failures. A second server protects against host or provider outages, and it only adds safety if a lock ensures a single active instance.

How do I stop a standby bot from trading while the primary is still running?

Require every instance to hold a lease or lock before placing orders, and make the bot stop trading if it cannot renew it. This way a network split pauses the primary instead of producing two active bots. Moving a virtual IP alone does not guarantee this.

What happens to open orders when my bot loses connection?

Orders already accepted by the exchange stay on the exchange. The bot just cannot see or change them. This is why a recovering bot should reconcile open orders and balances from the exchange before acting, and why protective orders that live on the exchange reduce what failover must cover.

How often should a bot send a heartbeat?

A common pattern is one heartbeat per minute with an alert after a gap of about five minutes, as described by VoiceOfChain. Tune the threshold to your strategy: the faster it needs to act, the shorter the gap you can accept, and the more false alarms you may have to manage.

Sources

Grisha Chasovskih
Written by

Founder & CEO, Darkbot

More articles

Start trading on Darkbot with ease

Come and explore our crypto trading platform by connecting your free account!

Start Free Trial

Free plan available • No credit card required

Contents

Free access for 7 days

Full-access to Darkbot Premium plan

Start now

Free plan available • No credit card required

Cryptocurrency trading involves substantial risk of loss. Past performance does not guarantee future results. Articles are for informational purposes only and do not constitute financial advice.