How wat-street/ledger-instances works
Main Components
• API Backend: At the core is the Flask-based API (app.py) which exposes endpoints like create_ledger, view_ledger, and delete_ledger.
• Database: A PostgreSQL instance (even if currently named “postgres”) stores ledger and possibly trade order data. The README lists planned tables (order_books_v2, trades).
• Model Interaction: The project is designed to integrate with algorithm models that implement the “trade()” and “update_book_status()” functions. Illustrate how these models interact with the ledger data.
• Utility Modules: Several utility modules (in the “utils” folder) manage configurations (db_config), ledger management (ledger_manager, ledger_utils), and integrations with GitHub and Docker. These support the API and database operations.
• SQL Statements: The “sql_statements” directory holds initialization and testing statements essential for setting up and populating the database.
• Containerization: The Dockerfile suggests that containerization/deployment is considered, so include this as an external component enabling smooth deployment.
Relationships and Interactions
• Utility modules as supporting the API logic. For example, “ledger_manager” encapsulates the creation, update, deletion, and viewing of ledgers, and “db_config” initializes connections to the Postgres DB.
• Integration of external algorithms (using the defined Model interface) by showing that the API passes ledger details and receives trading actions in return.
• Optionally, note the scheduler (Celery or similar) as an upcoming component that will trigger periodic tasks (like “update_book_status”).
Architectural Patterns and Important Technologies
• Use a layered architecture: Present the API layer interfacing with lower-level services (database, utilities, integration with trading models).
• A loosely coupled design where each component – the Flask app, database, utility modules, and external algorithm models – interacts via clearly defined interfaces.
• Technologies/Frameworks: Python (Flask), PostgreSQL, Celery (for scheduling, if adopted), Docker (for containerization), and pytest (for testing).
Detailed Elements
• Clear, descriptive labels for components such as “API Endpoints (create, view, delete ledger)”, “Utility Modules (helper functions and integrations)”, “Database (Postgres – order_books_v2, trades)” and “Scheduler (pending Celery integration)”.
– API receives a request → ledger_manager module performs ledger creation logic → SQL scripts or direct queries update the Postgres DB.
– A triggered trade via the API flows into the algorithm’s trade() function and sends back trade execution data.