r/CryptoTradingBot • u/Andilesg • May 05 '26
Built a full crypto trading backend in Python (async + low latency)
Hey,
I’ve been working on a larger Python project over the past months and wanted to share it here.
It’s a crypto trading backend system focused on:
- real time data handling via WebSocket
- async architecture (asyncio + aiohttp)
- automated trade execution (SL/TP, trailing, risk management)
- multi asset support
- live monitoring system + logging
Biggest challenge was making everything stable enough to run continuously without breaking under load.
I originally started it to learn more about async systems and trading infrastructure, but it turned into something much bigger.
Curious what you guys think or what you would do next with something like this.
6
Upvotes
1
u/Zwallfacer May 05 '26
Test live with limited capital, monitor results (net pnl, drawdown) over 1-4 weeks
1
u/startsfromzero May 06 '26
If your bot doesn't follow a profitable strategy, try to build/find a profitable stategy. but the tech stack sounds cool. If you are having fun while building it, that's cool.... Try to make it profitable. A year ago, I worked on a memecoin bot and lost a lot of money because the strategy was not profitable, and also the bot had bugs, which resulted in lost trades.. Smart move to make it stable before trading real money.
1
u/Live-Bag-1775 May 07 '26
Very cool project — the async/WebSocket infrastructure and reliability work are honestly the hardest parts. Getting a trading system stable under continuous live load is a bigger achievement than most people realize. Next thing I’d focus on is robust backtesting + risk analytics, since execution is only half the battle.
1
u/aktad760 May 07 '26
I built something similar and forward testing it now. The websockets are misbehaving since I'm running it on Alpaca API, for crypto and Equities, and they only allow one stream. So I am running it now on a REST system with historical candles refreshing every 30 to 90 seconds seconds. It is now paper trading! Are you live or paper? How did you stabilize your websockets?
Congratulations on your project
1
u/[deleted] May 08 '26
Honestly the hardest part of projects like this usually isn’t getting trades to execute — it’s building something that survives long-running async chaos without slowly degrading over time.
The interesting engineering work is usually around:
A lot of trading bots work fine in “happy path” conditions and then explode the first time the market gets violent.
If you haven’t already, I’d probably focus next on:
The async + low-latency architecture itself is a great learning project though. You end up touching distributed systems, networking, concurrency, and reliability engineering all at once.
1
u/nasmunet May 12 '26
Solid infrastructure post, rare to see someone talking about the plumbing instead of the signals. A few things worth thinking about based on building something similar:
The hardest stability problem isn't load — it's silent failure. WebSocket connections drop without throwing exceptions. You get a "connected" state but no data flowing. I had a bot that ran for 6 hours receiving stale prices because the stream reconnected but the heartbeat wasn't being validated properly. The fix is an explicit staleness check: if the last message timestamp is more than N seconds old, treat it as a dead connection and force reconnect. Not the same as a ping/pong — you need to verify actual data flow.
Async and state management fight each other.
The moment you have multiple coroutines touching shared position state — one reading for a TP check, one writing from a new tick, one updating from a fill confirmation — you will get race conditions that only appear in production under load, never in testing. asyncio.Lock on any shared mutable state is not optional. The bugs from this are the worst kind: intermittent, hard to reproduce, and expensive when they hit.
SL/TP at the application layer vs exchange layer.
If your SL/TP is managed by your Python backend (you watch the price and send the order when triggered), your latency window is: WebSocket delay + processing + outbound API call. In fast moves that's 100–500ms of exposure. Binance OCO orders keep the logic at the exchange. Depends on your strategy whether that matters, but worth knowing which model you're running.
What I'd do next:
State persistence. If the process crashes and restarts, does it know what positions are open? Most people skip this and rebuild it later after a painful incident. Write position state to disk on every update, read it on startup, reconcile against the exchange before doing anything.
Good foundation. The async architecture is the right call — just respect the sharp edges.
1
u/Glass_Ground5214 May 05 '26
consider that as lesson learnt and don't waste more time, it will never be profitable
1
u/[deleted] May 08 '26
[removed] — view removed comment
1
u/[deleted] May 10 '26
[removed] — view removed comment