
When I set up my first trading bot, the scariest moment wasn't the code. It was the first time the code could place a real order.
So before any buying logic existed, every order went through one function with one switch in front of it:
import os
DRY_RUN = os.environ.get("DRY_RUN", "true").lower() == "true"
def place_order(client, symbol, qty, side):
if DRY_RUN:
print(f"[DRY RUN] would {side} {qty} {symbol}")
return None
return client.submit_order(symbol=symbol, qty=qty, side=side)
Three things I like about this:
- It defaults to safe. If I forget to set the variable, nothing real happens.
- There's one door. No other part of the bot talks to the broker's order endpoint directly, so there's one place to check.
- Keys and switches live in the environment, not the code. Nothing sensitive ends up in a repo.
I ran in dry-run mode, then on a paper account, for weeks before flipping it. Boring was the goal.
That's one step of nine. I wrote up the full setup, from an empty account to a bot that runs on a schedule, here: How to set up a trading bot from scratch, step by step.
If you're starting from zero like I did, the story of how it began is in Part 1 of the build.
Educational only, not financial advice.
Top comments (0)