Every developer who gets into crypto eventually has the same thought: "I could write a bot for this." And you can. Most big exchanges expose an API, and the core loop of a trading bot fits on one screen. The hard part isn't the loop. It's everything around it: the key you hand the bot, what happens when it misbehaves at 3 a.m., and whether the backtest that convinced you was ever honest.
This post looks at automated trading the way you'd look at any production service that can spend money. For the plain-English background on bot types and their risks, NutshellCrypto has a full explainer on how automated crypto trading and trading bots work.
A bot is just a loop with a wallet attached
Strip away the marketing and nearly every bot does the same four things: read data (prices, the order book, or just the clock), compare it against rules, place or cancel orders, then repeat. It has no idea where the price is going. A recurring buy, a grid bot and a moving-average crossover bot are all variations on that loop with different rules.
That framing matters because it tells you where the risk lives. The rules can be wrong, the code can be buggy, and the credentials can leak. None of those risks shrink because the bot calls itself "AI".
Treat the API key like a production secret
Your bot talks to the exchange with an API key and secret. Whoever holds that pair can do whatever its permissions allow, so scope it the way you'd scope a cloud IAM role:
- Trade-only. The bot needs to place and cancel orders. It almost never needs withdrawal permission, so leave that off.
- IP allowlist. If the exchange supports it, lock the key to the server your bot runs on. A leaked key that only works from one IP is far less useful to a thief.
- One key per bot. Separate keys make it obvious what to revoke when something goes wrong.
- No secrets in the repo. Load them from environment variables or a secrets manager, rotate them, and delete keys you no longer use.
Even a trade-only key isn't harmless. Someone with it can still place terrible trades on your account, so 2FA on the exchange account and a quick revocation path still matter.
Put guardrails outside the strategy
The strategy decides what to do. Guardrails decide what the bot is never allowed to do, no matter what the strategy says. Keep them in a separate layer so a bug in one doesn't disable the other. Here's a minimal sketch with a dry-run mode (no exchange calls, illustrative limits):
import os
MAX_ORDER_USD = 25.0 # hard cap per order
MAX_DAILY_USD = 100.0 # hard cap per day
DRY_RUN = os.getenv("DRY_RUN", "1") == "1"
class GuardrailError(Exception):
pass
class Guardrails:
def __init__(self):
self.spent_today = 0.0
def check(self, side, usd_amount):
if os.path.exists("KILL_SWITCH"):
raise GuardrailError("kill switch file present, refusing to trade")
if side not in ("buy", "sell"):
raise GuardrailError(f"unknown side {side!r}")
if usd_amount <= 0 or usd_amount > MAX_ORDER_USD:
raise GuardrailError(f"order size {usd_amount} outside limits")
if self.spent_today + usd_amount > MAX_DAILY_USD:
raise GuardrailError("daily limit reached")
def place(self, side, usd_amount, send_order):
self.check(side, usd_amount)
if DRY_RUN:
print(f"[dry run] would {side} ${usd_amount:.2f}")
else:
send_order(side, usd_amount)
self.spent_today += usd_amount
g = Guardrails()
g.place("buy", 25.0, send_order=None) # prints a dry-run line
A few habits worth copying: default to dry run, make the kill switch something you can trigger without a deploy (a file, a flag, a revoked key), and log every intended order before it's sent so you can reconstruct what happened.
Backtests lie politely
A backtest replays your rules over historical data. It's useful, and it's also the easiest place to fool yourself. If you tweak parameters until the equity curve looks great, you've likely fitted noise rather than found an edge. That's overfitting, and it tends to fall apart on new data.
To keep it honest, test across different market conditions, include every cost (maker/taker fees, spread, slippage), hold out a period you never tuned on, and then paper trade before going live. A bot that trades often can hand most of its gross gains back in fees.
The simplest bot is often the sensible one
The lowest-risk automation is a plain recurring buy: a fixed amount on a fixed schedule, no prediction involved. If you want to see what that looks like with your own numbers before writing any code, NutshellCrypto has a free crypto DCA calculator and a guide to dollar cost averaging in crypto.
Leverage is the opposite end. A bot trading futures or margin can get a position force-closed after a short run of small mistakes, which is why spot-only is the safer place to learn.
Spotting the scams
Regulators such as the CFTC, SEC and FTC repeatedly warn that "trading bot" is a favorite cover story for fraud. Red flags: guaranteed or fixed returns, being asked to deposit funds into the bot company's own wallet, surprise "fees" before withdrawals, and "AI" claims with no explanation of the actual strategy. Real automation runs against your exchange account with a key you control.
Takeaways
- A bot follows rules; it can't predict prices.
- Scope API keys to trade-only, add an IP allowlist, and keep secrets out of your repo.
- Keep guardrails (order caps, daily caps, kill switch) separate from strategy code.
- Count fees and slippage, hold out data, and paper trade before risking money.
- Guaranteed returns are a scam signal, not a feature.
Read the full guide on NutshellCrypto
This is educational content, not financial, investment or tax advice. Automated strategies can lose money.
This post was written with AI assistance.
Top comments (0)