Skip to content

Watchdog

The watchdog is an independent safety service that guards your exchange accounts against naked (unprotected) positions. Run it on a separate machine from your trading bot: it reads your account straight from the exchange and alerts — or automatically closes — any position that's missing its stop-loss, its take-profit, or both.

It exists for one reason: a bot's protection can disappear the moment the bot has trouble. A virtual stop-loss lives in the bot's memory and only fires while the bot is alive. If the bot crashes, freezes, or loses its connection, that protection silently vanishes and the position is exposed. A real stop order on the exchange survives the bot dying — a virtual one does not. The watchdog is the backstop for exactly that gap.

Setup

Two commands, then finish in the Lab.

bash
# 1. Log in (so the watchdog shows up in the Lab automatically)
tradectl login

# 2. Run it — it boots ready but unconfigured, and stays running in the background
tradectl watchdog run --daemon

That's it for the terminal. The watchdog is now running and will appear in the Lab under My bots.

Configure it in the Lab

Open the Lab, click the watchdog, and set it up:

  1. Guard a bot — pick the bot you want to protect. The watchdog detects its market (e.g. Binance COIN-M / USD-M).
  2. Add the account's exchange API keys — trade-only keys are enough; they're stored encrypted and used only to read positions and, if you allow it, close them.
  3. Choose what it may do:
    • Alert only (default, safe) — it watches and warns you, but never trades.
    • Auto-close — it closes any unprotected position for you, and also clears out a dead bot's other leftover orders. This needs a Telegram channel so it can tell you what it did.

Everything applies live — no restart. You can attach more bots or accounts (even on different markets) the same way, all guarded by the one watchdog.

Start with Alert only

Leave it on Alert only at first and watch what it reports. Switch to Auto-close once you trust its verdicts.

What it does

Every few seconds the watchdog reads your open positions and resting orders from the exchange. For each position it checks whether both a stop-loss and a take-profit are resting on the exchange — a take-profit alone doesn't count as protection, since a position that reverses after going into profit would otherwise have no floor. If either is missing, it starts a timer, confirms the position stays unprotected, then alerts you — and, on Auto-close, closes it with a reduce-only market order (it can only ever close a position, never open one).

The Lab's Watchdog view shows exactly what it sees: each position's protection verdict with the reasoning, the bot's declared stop-loss, and the raw orders it read from the exchange.

Panic

Need everything flat immediately? Run:

bash
tradectl watchdog panic

This market-closes every position on every guarded account right now (after a confirmation prompt). It's a manual emergency button — the watchdog never triggers it automatically.

Notes

  • Run it on a separate machine from your bot, so a crash of the bot's host doesn't take the watchdog with it. Supervise it (e.g. systemd Restart=always) — it sends a STOPPED alert if it ever exits.
  • Manual trading on a guarded account: while your bot is up and reporting normally, the watchdog leaves an unclaimed manual position alone by default — it only alerts. But if the bot itself goes unreachable or loses track of its own positions, the watchdog can no longer tell your manual trade apart from one the bot abandoned, and Auto-close will close it too. Keep such accounts on Alert only, or put a stop on your manual position, if you'd rather avoid that risk entirely.

See also

tradectl — Automate Crypto Trading