My trading bot worked fine on stocks. Then I pointed it at crypto and found an assumption I didn't know I'd written: that the market closes.
A lot of stock logic quietly depends on that. Daily opens and closes, overnight gaps, "run this after the bell." None of it exists in a market that trades all day, every day.
The first fix was making the assumption explicit instead of buried:
from datetime import datetime, time
from zoneinfo import ZoneInfo
ET = ZoneInfo("America/New_York")
OPEN, CLOSE = time(9, 30), time(16, 0)
def market_is_open(asset_class: str, now: datetime | None = None) -> bool:
if asset_class == "crypto":
return True # no bell, no weekends off
now = now or datetime.now(ET)
if now.weekday() >= 5: # Saturday, Sunday
return False
return OPEN <= now.time() < CLOSE # holidays need their own check
Small function, big consequences:
- Every scheduled job asks this first, so stock-only logic can't accidentally run against a 24/7 market.
- It forced a harder question: if crypto never closes, who's watching at 3 AM? The answer had to be the bot itself, so every protective rule became automatic.
- Testing changed too. A crypto change isn't tested until it has run on paper through a full weekend, because weekends are where the differences show up.
The rest of what changed (the safety net, the signals, position sizing) is in the full write-up: How I added crypto to my trading bot.
If you're setting up your first bot, the step-by-step setup is in Part 2 of the build.
Educational only, not financial advice.

Top comments (0)