How artooze/crypto-arbitrager works
Main Components
• Entry Point and Core Arbitrage Engine: The main script (arbitrage/arbitrage.py) acts as a command-line interface and orchestrates the operation. It parses command‐line flags (e.g., “watch”, “get-balance”, “list-public-markets”) and triggers the core arbitrage logic.
• Configuration Module: There is a configurable file (config.py, copied from config.py-example) which holds settings like watched markets and observer preferences.
• Exchanges Interfaces: The project splits the exchange connectivity into “public_markets” and “private_markets” directories. These modules are responsible for fetching public order book data (e.g., from Bitfinex, OkCoin) and handling account‐related data or trading (for authenticated sessions).
• Broker Communication: Within the “lib” folder, modules like broker_api.py and broker.thrift hint at inter-process communication with an external broker service (using thrift). This broker service is required for trade automation.
• Observers (Plugins): In “observers”, various observers (e.g., TraderBot, HedgerBot, Logger, Emailer) encapsulate different behaviors triggered by arbitrage opportunities. They represent reaction or execution strategies.
• Utility Libraries: Common helper functions and settings are located in “lib” and the root “utils.py”. These modules help in formatting data, performing calculations, and managing common tasks.
• Testing and Miscellaneous: The “test” directory holds tests for arbitrage speed and functionality. Auxiliary tools are provided in the “tools” directory (e.g., for autopep8 formatting).
Relationships and Data Flow
• The User (or a scheduled task) initiates execution via the command-line interface (arbitrage.py).
• The core engine reads the configuration and instructs the appropriate market modules (either public or private) to retrieve market data.
• The fetched data flows into the arbitrage algorithm (in modules like arbitrage/arbitrer.py) that calculates possible arbitrage opportunities.
• Once opportunities are detected, control is passed to one or more observers. Each observer (such as TraderBot, BalanceDumper, Logger) handles actions like executing trades, logging activities, or sending notifications.
• For automated trades, the engine may communicate with the external broker service via the broker API (thrift-based) to execute orders on the various exchanges.
• Helper and utility functions from the “lib” and “utils.py” are used throughout these interactions.
• Test modules reside at the periphery for integrity checks.
Architectural Patterns and Key Technologies
• Modular Design: The clear separation between market data access (public/private), core calculation (arbitrage.py and arbitrer.py), and various observers adheres to separation of concerns.
• Observer/Plugin Pattern: The observer modules provide extension points where multiple strategies or logging functions can be attached without altering the central arbitrage engine.
• External Service Integration: Interaction with an external market broker via thrift demonstrates the use of service-oriented communication.
• Language and Libraries: The project uses Python 3, with additional libraries like requests, zmq, thriftpy, and sleekxmpp for messaging. Emphasis is given to real-time data processing and execution.