Fix database persistence and add analytics

- Fixed Prisma client not being available in Docker container
- Added isTestTrade flag to exclude test trades from analytics
- Created analytics views for net positions (matches Drift UI netting)
- Added API endpoints: /api/analytics/positions and /api/analytics/stats
- Added test trade endpoint: /api/trading/test-db
- Updated Dockerfile to properly copy Prisma client from builder stage
- Database now successfully stores all trades with full details
- Supports position netting calculations to match Drift perpetuals behavior
This commit is contained in:
mindesbunister
2025-10-27 09:35:01 +01:00
parent 1da5db5e75
commit 8e5c592cac
9 changed files with 589 additions and 8 deletions

8
.env
View File

@@ -93,15 +93,15 @@ HARD_STOP_PERCENT=-2.5
# Take Profit 1: Close 50% of position at this profit level
# Example: +0.7% on 10x = +7% account gain
TAKE_PROFIT_1_PERCENT=0.4
TAKE_PROFIT_1_PERCENT=0.7
# Take Profit 1 Size: What % of position to close at TP1
# Example: 50 = close 50% of position
TAKE_PROFIT_1_SIZE_PERCENT=75
TAKE_PROFIT_1_SIZE_PERCENT=50
# Take Profit 2: Close remaining 50% at this profit level
# Example: +1.5% on 10x = +15% account gain
TAKE_PROFIT_2_PERCENT=0.8
TAKE_PROFIT_2_PERCENT=1.5
# Take Profit 2 Size: What % of remaining position to close at TP2
# Example: 100 = close all remaining position
@@ -113,7 +113,7 @@ EMERGENCY_STOP_PERCENT=-2
# Dynamic stop-loss adjustments
# Move SL to breakeven when profit reaches this level
BREAKEVEN_TRIGGER_PERCENT=0.5
BREAKEVEN_TRIGGER_PERCENT=0.7
# Lock in profit when price reaches this level
PROFIT_LOCK_TRIGGER_PERCENT=1.2