Start from the task, not the strategy
A trading bot project begins with what the bot is for, what it may lose and what it must never do. The signal comes last, and it is the smallest part of the work.
Ask a trader what a bot does and you get a strategy: it buys breakouts, it fades extremes. Ask the person who has to keep it running and you get a different list: what happens when the exchange times out, what happens when it fills half an order, what happens at 3am when nobody is looking.
That second list is most of the work. So we start there.
Three questions before any code#
- What is the bot for? Collecting a yield, testing an idea, cleaning up an account, watching a feed. Different jobs, different bots.
- What is it allowed to lose? In money, in a day, in a row. This becomes numbers in the risk layer before the first order exists.
- What must it never do? Hold a position without a stop. Trade something not on a list. Send money out. These become code paths that do not exist.
Bot types we tailor to a task#
| Type | What it is for | Main risk |
|---|---|---|
| Trend and breakout | Riding sustained moves once price leaves a range | Whipsaw: a run of false breakouts bleeds money through stops and fees |
| Mean reversion | Fading stretched moves back toward an average | The stretch turns out to be a new trend, and the signal keeps saying "cheaper, buy more" |
| Funding rate carry | Long spot and an equal short perpetual, collecting funding while it is positive | Funding flips, the basis moves, a thin short leg gets squeezed, rebalancing fees eat the carry |
| DCA and martingale ladders | Scaling into a position in rungs as price moves against the entry | Concentrated tail risk when the ladder has no ceiling |
| Grid | Resting orders at fixed steps to harvest back and forth movement | Price leaves the range and inventory piles up on the wrong side |
| Coin toss control group | A baseline entering on a random signal with the same sizing, stops and fees | None in the logic. The risk is skipping the baseline and fooling yourself |
| Announcement and listing watcher | Reacting to exchange announcements on predefined rules | Latency, thin books, misreading an announcement |
| Treasury collector | Sweeping dust and leftovers into the trading currency | Selling into a thin book, or converting something meant to be held |
Tailoring a ladder#
A classic martingale has no ceiling: each rung doubles the last. For a client who wants ladders, we keep the shape and put one shared stop and one fixed risk budget over the whole thing, so the worst case is known before the first order goes out.
def dca_ladder(entry: float, stop: float, risk_budget: float, *, rungs: int = 4,
spacing: float = 0.02, mult: float = 1.6, fee_rate: float = 0.0006):
"""Long ladder: rung k rests spacing*k below entry; every rung shares ONE stop.
Rung k gets a slice of the risk budget proportional to mult**k * (loss per unit
from rung k to the stop). Sizes grow geometrically, yet if every rung fills and
the stop hits, the total loss equals risk_budget, never more."""
prices = [entry * (1 - spacing * k) for k in range(rungs)]
if prices[-1] <= stop:
raise ValueError("the deepest rung must sit above the stop")
loss_per_unit = [p - stop + (p + stop) * fee_rate for p in prices]
weights = [mult ** k * d for k, d in enumerate(loss_per_unit)]
total = sum(weights)
ladder = []
for k, (p, d, w) in enumerate(zip(prices, loss_per_unit, weights)):
risk_k = risk_budget * w / total
ladder.append({"rung": k, "price": p, "qty": risk_k / d, "risk_at_stop": risk_k})
return ladderWith mult = 2 this is the familiar martingale shape. The difference is the shared stop and the fixed budget. All parameters in the code on this site are illustrative defaults, not recommendations.
Demo first, always#
Every bot runs on a demo or testnet account before it is trusted with real funds. The rest of the bots page and the posts below are about what makes that step worth anything.
This is how trading software can be built. It is not investment advice. Trading crypto assets, especially with leverage, carries a risk of losing money, and results from tests or simulations do not guarantee anything in live markets. The studio builds trading software and tooling. It does not manage anyone's money, hold client funds or trade on anyone's behalf.
The best of a hundred coin flips looks like talent
Try enough strategies and one of them will look brilliant, even when every one is a coin toss. The number of tries is part of the result, and it is the part nobody prints.
Slippage is a fee nobody prints
The exchange prints its fee. It does not print the spread, the thin book or the stop that fills worse than its trigger. A test that leaves them out is flattering itself.
A stop that lives in your bot is not a stop
When the process crashes, the server reboots or the connection drops, a stop that exists only in the bot's memory does not exist. The stop belongs on the exchange, at entry.