How ebolaboy/gridbnb-usdt works
Project type and purpose
• This is a Python‑based automated grid trading bot tailored for the Binance BNB/USDT pair.
• Core features: grid order execution, dynamic grid sizing, risk management, web UI for monitoring, state persistence, notification, and logging.
File structure
• Top‑level scripts/modules:
• main.py – orchestrator.
• exchange_client.py – interface with Binance REST/WebSocket APIs.
• trader.py – implements the grid order logic.
• position_controller_s1.py – manages position sizing.
• risk_manager.py – enforces drawdown/ daily loss/position ratio limits.
• order_tracker.py – tracks live orders & fills.
• monitor.py – collects metrics (e.g., PnL, open orders).
• web_server.py – minimal Flask/Tornado web UI.
• helpers.py – shared utilities (e.g., JSON I/O for data/).
• config.py – all strategy parameters (grid, risk, symbol).
• Config & environment: .env.example, config.py, requirements.txt.
• Persistence: JSON files under data/ (though not shown in file tree, mentioned in README).
• Logging: trading_system.log.
• Deployment: simple script update_git.ps1 (for Windows).
README for additional insights
• Describes dynamic grid adjustment based on volatility.
• Web UI on port 8080, live metrics & manual adjustments.
• PushPlus integration for notifications.
• Emphasis on state recovery on restart.
Main components and interactions
a. Components
1. Orchestrator (main.py)
2. Configuration (config.py + .env)
3. Exchange Client (exchange_client.py)
4. Risk Manager (risk_manager.py)
5. Controller (position_controller_s1.py)
6. Trader/Grid Logic (trader.py)
7. Order Tracker (order_tracker.py)
8. Monitor & Notification (monitor.py + PushPlus)
9. Persistence (helpers.py → JSON under data/)
10. Web Server (web_server.py)
11. Logging (built‑in Python logger → trading_system.log)
12. External Services: Binance API, PushPlus API
b. Relationships & data flows
• main.py reads config & .env → initializes modules
• main.py → Exchange Client for market data & order placement
• Trader uses Exchange Client → places grid orders
• Order Tracker listens to fills/status via Exchange Client or WebSocket
• Controller receives fill events → adjusts target positions
• Risk Manager intercepts trade proposals → allows/blocks based on drawdown/daily loss
• Monitor collects snapshots from all modules → stores via helpers & optionally pushes alerts
• Web Server fetches state via helpers (JSON) & in‑memory caches → serves UI
• Notifications module (in monitor or risk_manager) calls PushPlus when thresholds breached
• Logging across every module for audit trail
c. Architectural patterns & design principles
• Modular service‑layer design: each concern (execution, risk, persistence, UI) in its own module
• Single orchestrator entry point (main.py)
• Dependency injection via config.py & environment variables
• Event‑driven flow: fills & market data trigger reactions in tracker, controller, risk manager
• State persistence for fault tolerance and restart recovery
d. Key technologies & libraries
• Python 3.8+
• Requests or ccxt for REST calls (in exchange_client.py)
• Web framework: Flask or asyncio HTTP server (in web_server.py)
• dotenv for environment loading
• PushPlus HTTP API for notifications
• Python logging module
• Layer 1 (Orchestration): main.py, config.py, .env
• Layer 2 (Core Engine): exchange_client, trader, order_tracker, position_controller, risk_manager
• Layer 3 (Support): monitor, helpers (for JSON), logger
• Layer 4 (External): Binance REST/WebSocket, PushPlus API
• Layer 5 (UI): web_server.py → browser