Distributed High-Frequency Triangular Arbitrage System
TRIB APEX is a high-performance, event-driven trading engine designed to identify and exploit market inefficiencies in the cryptocurrency market. It models currency pairs as a directed weighted graph and utilizes a modified Bellman-Ford algorithm to detect negative cycles (arbitrage opportunities) in real-time.
Unlike simple bots, TRIB functions as a distributed system. It decouples high-throughput data ingestion from analysis and execution using Redis as an atomic message broker, ensuring the UI remains responsive without adding latency to the trading engine.
- Graph Theory Implementation: Models 20+ currency pairs (USDT, BTC, ETH, SOL, BNB, etc.) as nodes in a dynamic graph.
- O(V·E) Algo: Runs concurrent Bellman-Ford algorithms to detect profit loops (e.g.,
USDT->SOL->BTC->USDT) in sub-millisecond time. - Smart Math: Converts exchange rates to negative logarithms (
-log(price)) to transform the "maximize product" problem into a "shortest path" problem. - Fee Awareness: Automatically deducts exchange fees (0.1%) during path calculation to prevent slippage losses.
- Atomic Pipeline: Uses Redis Lists and Pub/Sub to handle state management, ensuring thread-safe operations between the Engine and the API.
- WebSocket Ingestion: Consumes raw
@bookTickerstreams from Binance for the absolute latest bid/ask data. - Fault Tolerance: Dockerized microservices with strict
healthcheckdependencies ensure the system self-recovers.
- Live Visualizer: Custom SVG components animated with Framer Motion to visualize the active search path and return rates.
- Zero-Latency Feed: Uses optimized polling hooks to display trade executions the millisecond they are processed by the engine.
- Cyberpunk UI: A sleek, "Linear-style" dark mode interface built with TailwindCSS and Shadcn/UI.
| Component | Technology | Description |
|---|---|---|
| Engine | Go (Golang) | High-concurrency processing, WebSocket handling, Graph algos. |
| API | Go (Fiber) | Fast HTTP layer to expose Redis data to the frontend. |
| Database | Redis (Alpine) | In-memory message broker, state store, and atomic locking. |
| Frontend | Next.js 14 | App Router, TypeScript, Server Components. |
| Styling | TailwindCSS | With clsx, tailwind-merge, and Shadcn/UI components. |
| Animation | Framer Motion | Complex SVG path animations and layout transitions. |
| DevOps | Docker Compose | Multi-container orchestration with health checks. |
graph TD
WS[Binance WebSocket] -->|Ticks| GE[Go Engine]
GE -->|Update Weights| Graph[In-Memory Graph]
Graph -->|Bellman-Ford| Detect{Negative Cycle?}
Detect -->|Yes| Exec[Execute Trade]
Exec -->|Push Data| Redis[(Redis)]
Redis -->|Read State| API[Go Fiber API]
API -->|JSON| Client[Next.js Dashboard]
##
