Efficient Modules
Embracing Modularity in Crypto Arbitrage: Leveraging (a.o) Docker, Redis, and NATS
Last updated
Embracing Modularity in Crypto Arbitrage: Leveraging (a.o) Docker, Redis, and NATS
Last updated
In the rapidly evolving domain of cryptocurrency arbitrage, the capacity to swiftly adapt to market changes is crucial. Our system is meticulously architected to encapsulate modularity, utilizing a combination of Docker, Redis, and NATS to create a robust, scalable, and efficient trading bot ecosystem.
Docker: The Foundation of Flexibility
Docker containers are at the heart of our system's modularity. Each container operates as an isolated microservice, executing specific tasks within the arbitrage process. For instance:
wsBybit.py, wsOKX.py, wsHuobi.py, wsBitget.py (can be any exchange): These containers are responsible for connecting to various exchange websockets, each tailored to handle the nuances of its respective exchange's API. This modular approach allows for easy plug-and-play functionality if we decide to integrate additional exchanges or replace existing ones.
Redis: The Memory Cache for Real-Time Data Management
Redis serves as our in-memory data store, ensuring lightning-fast access to data which is critical in the time-sensitive environment of trading. It maintains two key datasets:
Arbs Current: This Redis cache holds the current arbitrage opportunities detected across exchanges. It is constantly updated in real time, providing a snapshot of the most immediate trading opportunities.
Arbs History: This Redis dataset stores historical arbitrage data, offering a valuable resource for analysis and machine learning model training. It aids in identifying patterns and trends over time, which is essential for refining our trading algorithms.
NATS: The Nerve Center for Communication and Execution
NATS is a messaging system that acts as the central communication hub of our arbitrage system. It orchestrates the flow of information between the various Docker containers:
Orderbooks Synchronization: NATS ensures that all microservices have access to the latest order book data from every exchange. It is the backbone that enables our system to maintain a coherent and synchronized state across the different trading pairs and exchanges.
Trade Execution: Once an optimal arbitrage opportunity is identified (The best Arb), NATS communicates this information to the trading module (trading.py
). This module then executes the trade, taking advantage of the identified opportunity.
Workflow: From Detection to Execution
The workflow of our system is a testament to the power of modularity:
Data Ingestion: Individual websocket containers (wsBybit.py
, etc.) ingest real-time data from their respective exchanges.
Data Aggregation and Analysis: The data flows into the Arbs Current
and Arbs History
in Redis, where it is processed and analyzed.
Opportunity Identification: The system monitors (monitoring.py
) the current arbitrage opportunities and evaluates them against eachother to identify the most profitable trades.
Trade Execution: Upon identification of the best arbitrage opportunity, NATS signals the trading.py
module to execute the trade.
Our modular system is a well-oiled machine, with Docker ensuring flexible and isolated execution environments, Redis providing rapid access to real-time and historical data, and NATS facilitating seamless communication and trade execution. This modularity is not just about maintaining an organized codebase; it's about enabling our system to be resilient, adaptable, and consistently ahead in the high-stakes world of crypto arbitrage.