Building BlackOrigin: A Scalable Trading Bot for SaaS Marketplaces
We built BlackOrigin, a SaaS trading automation platform designed to execute lightning-fast trades on Bybit, powered by real-time TradingView signals.
The mission was simple yet demanding:
βExecute buy and sell orders instantly, size positions optimally, and compare cross-market prices β all while ensuring safety, reliability, and low latency.β
This post walks you through the architecture, technology choices (especially RabbitMQ), implementation highlights, hard lessons learned, and the results achieved.
π§ Project Overview
BlackOrigin is a scalable SaaS trading application built for high-volume, real-time automated trading.
It listens to TradingView signals, computes trade quantities and risks, executes orders on Bybit, and continuously compares prices across multiple exchanges to optimize trading outcomes.
Core Capabilities
β‘ Real-Time Signal Processing: Instantly reacts to TradingView alerts.
π Automated Trade Lifecycle: Signal reception β position sizing β execution β confirmation β monitoring.
π Cross-Market Price Comparison: Checks multiple exchanges for optimal trade execution.
π Concurrency Safety: Redis-based distributed locks prevent overlapping trades.
π§ Resilience & Observability: Prometheus, Grafana, and Loki ensure transparent monitoring and error recovery.
π’ User Notifications: Telegram, email, and browser alerts (via OneSignal).
π¨ Error Alerts: Slack notifications instantly notify admins and superadmins of system errors.
π§© Technology Stack
| Layer | Technology | |||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Backend | Laravel (PHP) |
|||||||||||||
Frontend | Next.js |
|||||||||||||
Message Broker / Queue | RabbitMQ (high-throughput async processing) |
|||||||||||||
Caching & Locks | Redis |
|||||||||||||
Database | MySQL |
|||||||||||||
WebSocket | Laravel Reverb & Pusher |
|||||||||||||
Monitoring | Prometheus, Grafana, Loki, Promtail |
|||||||||||||
Payment Gateways | Stripe, Zip, Klarna, AfterPay, Volet (Crypto) |
|||||||||||||
APIs | REST, SOAP |
|||||||||||||
Authentication | JWT-based |
|||||||||||||
Third-Party Logins | Google, Telegram, Apple, Twitter, Facebook |
|||||||||||||
Notifications | Telegram, Email, Browser (OneSignal), Slack |
TradingView signals arrive fast β sometimes sending exit signals before entry trades are fully executed or when an entry signal fails.
To maintain consistent, safe trading logic, order dependencies must be preserved.
Rule: βAn exit signal must never execute unless the corresponding entry trade succeeded.β
The Real Problem
- TradingView sends ENTRY β system enqueues entry job.
- Entry job fails (timeout/API error).
- The exit signal arrives soon after.
- Without correlation, the bot tries to close a trade that never opened β false or damaging orders.
Limitations of Laravelβs Default Queue
- β No built-in message correlation (entry β exit).
- β No dead-letter exchanges (DLX) for structured retries.
- β No conditional routing or delayed requeue logic.
- β No management UI for inspecting or replaying messages.
- β Manual DB checks needed β inefficient and error-prone.
Why RabbitMQ Wins
β Native support for dependency-based routing
β Built-in delayed retries and DLX
β Strong message ordering and visibility
β Full control via management UI
β Scales horizontally for live trading systems
βοΈ Architecture & Workflow (High-Level)
- TradingView sends a signal via webhook or REST endpoint.
- The backend normalizes the signal and enqueues it in RabbitMQ.
- Worker consumers calculate trade size and place orders on Bybit.
- Redis distributed locks ensure no conflicting trades occur for the same symbol.
- Prometheus, Grafana, and Loki handle monitoring and logs.
- Notifications are pushed to users and admins in real time.
π Implementation Highlights
1. Concurrency Safety
Redis distributed locks serialize operations to prevent race conditions (e.g., two simultaneous signals for the same pair).
2. Retry & Idempotency
Each job uses unique idempotency keys, ensuring retries never cause duplicate executions.
3. Queue Specialization
RabbitMQ queues are separated by task type and priority β entry, exit, and settlement β ensuring ordered and controlled message flow.
4. Data Aggregator
A dedicated microservice normalizes price feeds from multiple exchanges, merging them into a canonical market feed for real-time price comparison.
5. Real-Time Frontend
Next.js frontend receives live WebSocket updates on trade status and price changes for a seamless dashboard experience.
π§ Challenges & Lessons Learned
1. Payment Integration Complexity
Integrating multiple gateways (Stripe, AfterPay, Zip, Klarna, Volet) required handling different currencies, payment flows, and asynchronous webhooks.
Solution:
- Added multi-currency validation layers.
- Implemented conversion and reconciliation logic.
- Enhanced webhook retry and logging systems.
2. Queue Ordering & Concurrency
Ensuring entry-before-exit message flow in concurrent systems was critical.
Solutions:
- Created priority queues and routing keys for order-sensitive jobs.
- Used Redis locks and idempotency keys to enforce sequencing and avoid duplication.
3. Real-Time Multi-Exchange Synchronization
Different exchange APIs had varying latencies and formats, complicating trade reconciliation.
Solutions:
- Built a data aggregator to normalize and timestamp feeds.
- Optimized WebSocket multiplexing to reduce latency.
- Designed a lightweight reconciliation loop to match trade executions with market snapshots using tolerance windows.
π Results & Impact
β Low-Latency Execution: Trades executed in real time, even under heavy signal loads.
β Reliable Payment Support: Seamless integration of fiat and crypto gateways with secure webhook recovery.
β Scalable Architecture: RabbitMQ + Redis + Worker clusters enabled horizontal scalability.
β Robust Operations: Retry, idempotency, and distributed locks reduced trade conflicts drastically.
β Maintainable Foundation: Modular architecture supports future expansion to new exchanges, markets, and strategies.
Building BlackOrigin wasnβt just about coding a trading bot β it was about designing a scalable, fault-tolerant, and observant SaaS architecture capable of handling real-world trading chaos.
By leveraging RabbitMQ, Redis, and observability stacks, BlackOrigin achieved speed, stability, and transparency β three pillars essential for any automated trading platform.