Enhance strategy execution with CSV logging and dashboard support#70
Enhance strategy execution with CSV logging and dashboard support#70
Conversation
0xghXst
commented
Jan 23, 2026
- Introduced CSV logging for strategy execution, allowing tracking of NAV, positions, and orders over time.
- Added a new FastAPI-based web dashboard for real-time monitoring of strategy performance.
- Updated strategy initialization to include parameters for enabling CSV logging and specifying log directory.
- Created a CSVLogger utility for managing log file creation and data writing.
- Implemented API endpoints to serve strategy data and logs for the dashboard.
- Added documentation for CSV logging features and dashboard usage.
- Introduced CSV logging for strategy execution, allowing tracking of NAV, positions, and orders over time. - Added a new FastAPI-based web dashboard for real-time monitoring of strategy performance. - Updated strategy initialization to include parameters for enabling CSV logging and specifying log directory. - Created a CSVLogger utility for managing log file creation and data writing. - Implemented API endpoints to serve strategy data and logs for the dashboard. - Added documentation for CSV logging features and dashboard usage.
Pull Request Review: CSV Logging and Dashboard SupportSummaryThis PR adds CSV logging capabilities and a web dashboard for strategy execution monitoring. The implementation is well-structured and adds valuable observability features to the trading strategies. Code Quality & Best PracticesStrengths
Issues to Address1. CRITICAL: Linting FailuresThe PR has failing lint checks. Please run 2. Documentation Violates CLAUDE.md Rule #2Per CLAUDE.md line 2: "DO NOT create a new document. Purge unnecessary code and files."
3. Configuration Management (CLAUDE.md Rule #4)The
4. File I/O Performance Concerns
with open(self.filepath, "a", newline="") as f:
writer = csv.writer(f)
writer.writerow(row)Recommendation: Consider buffering writes or keeping the file handle open during strategy execution, flushing periodically. 5. Error Handling Gaps
Recommendation: Add try-except blocks with proper logging for file operations. 6. Security: Hardcoded Host Binding
uvicorn.run(app, host="0.0.0.0", port=8000)Security Risk: This allows external access to the dashboard without authentication. 7. Missing Input Validation
Recommendation: Validate 8. Resource Leak Risk
if self.csv_logger:
self.refresh_state()
self.csv_logger.log_snapshot(...)Recommendation: Wrap in try-except to prevent logging failures from crashing the strategy. 9. Inconsistent Data Types
safe_name = outcome.replace(" ", "_").replace(",", "").lower()[:20]Potential Issue: Long outcome names could create columns that don't match their data. 10. HTML Dashboard Uses CDN Dependencies
<script src="https://cdn.tailwindcss.com"></script>
<script src="https://cdn.jsdelivr.net/npm/chart.js"></script>Risk: Dependency on external services; version changes could break the dashboard. Performance ConsiderationsConcerns
Recommendations
Test CoverageMissing TestsNo tests were added for the new functionality:
Recommendation: Add unit tests covering:
Additional ObservationsPositive
Minor Issues
Recommendations PriorityHigh Priority (Must Fix)
Medium Priority (Should Fix)
Low Priority (Nice to Have)
VerdictOverall Assessment: This is a valuable feature addition with good code structure, but it needs several fixes before merging:
Recommendation: Request changes. The core implementation is solid, but the issues above should be resolved to maintain code quality and security standards. Review conducted following CLAUDE.md guidelines |
PR Review: Enhance strategy execution with CSV logging and dashboard supportSummaryThis PR adds CSV logging capabilities and a web-based dashboard for real-time monitoring of strategy execution. The implementation includes new utilities, FastAPI endpoints, and HTML dashboard with Chart.js visualizations. Code Quality & Best PracticesPositive Aspects
Issues & Recommendations1. Delta Calculation Change (exchange_client.py:940-960)CRITICAL: This appears to be a breaking change unrelated to CSV logging. # Old: delta = max_pos - min_pos (unsigned)
# New: delta = position_values[0] - position_values[1] (signed)Issues:
Recommendation:
2. Missing Test CoverageHIGH PRIORITY: No tests for new functionality. Missing test coverage for:
Recommendation: 3. Security ConcernsPath Traversal Validation (web/api.py:335-337) def _validate_strategy_id(strategy_id: str) -> bool:
return bool(re.match(r"^[a-zA-Z0-9_-]+$", strategy_id))
CORS Missing (web/api.py)
No Rate Limiting
4. Performance IssuesFile I/O on Every Tick (strategy.py:119-126) # Appends to CSV file every tick (default 5 seconds)
with open(self.filepath, "a", newline="") as f:
writer = csv.writer(f)
writer.writerow(row)Issues:
Recommendations:
CSV File Reading (web/api.py:367) with open(csv_file, "r") as f:
reader = csv.DictReader(f)
for row in reader: # Reads entire fileIssues:
Recommendations:
5. Configuration & Environment (CLAUDE.md Violation)CLAUDE.md Rule #4: "Single Source of Truth: DO NOT place many variables in .env file. Place them in the code instead." Violation (examples/spread_strategy.py:751): default=os.getenv("ENABLE_CSV_LOGGING", "").lower() in ("true", "1"),Recommendation:
6. Error HandlingMissing Error Handling:
Recommendations: # csv_logger.py
try:
self.log_dir.mkdir(parents=True, exist_ok=True)
except PermissionError as e:
logger.error(f"Failed to create log directory: {e}")
raise
# api.py
try:
reader = csv.DictReader(f)
# ...
except csv.Error as e:
raise HTTPException(status_code=500, detail="Corrupted CSV file")7. Code Style IssuesHard-coded values (csv_logger.py:202): safe_name = outcome.replace(" ", "_").replace(",", "").lower()[:20]
Hard-coded port (api.py:425): uvicorn.run(app, host="127.0.0.1", port=8000)
Dashboard CDN dependencies (dashboard.html:442-443): <script src="https://cdn.tailwindcss.com"></script>
<script src="https://cdn.jsdelivr.net/npm/chart.js"></script>
8. .gitignore IssueLine 20-21 (.gitignore): Issue:
Fix: Potential Bugs
Missing Features
Performance Considerations
Testing RecommendationsAdd these test files: Test coverage should include:
DocumentationGood:
Missing:
Overall AssessmentStrengths:
Major Concerns:
Recommendation: Request changes before merge. Action ItemsMust Fix (Blocking):
Should Fix (High Priority):
Nice to Have:
Positive NotesThe feature itself is valuable and well-implemented conceptually. With the fixes above, this will be a great addition to the project. The dashboard UI looks clean and the separation of concerns is good. Just needs polish on error handling, testing, and performance optimization. |
PR Review: CSV Logging and Dashboard SupportOverviewThis PR adds CSV logging for strategy execution and a FastAPI-based web dashboard for monitoring. The implementation is well-structured and provides valuable functionality for tracking strategy performance. Code Quality & Best PracticesStrengths:
Issues & Recommendations:
Potential Bugs
Security Concerns
Performance Considerations
Test CoverageCritical Gap: No tests for new functionality
Recommendation: Add test files: Minimum test coverage should include:
Additional Observations
SummaryApproval Status: This is a valuable feature that enhances strategy monitoring capabilities. The code is generally well-written and follows project conventions. However, there are some concerns that should be addressed: Must Fix Before Merge:
Should Fix (can be follow-up PR):
Nice to Have:
Overall, this is solid work that adds meaningful functionality. With the recommended fixes, it will be production-ready. |