Fix P&L calculation and signal flip detection

- Fix external closure P&L using tp1Hit flag instead of currentSize
- Add direction change detection to prevent false TP1 on signal flips
- Signal flips now recorded with accurate P&L as 'manual' exits
- Add retry logic with exponential backoff for Solana RPC rate limits
- Create /api/trading/cancel-orders endpoint for manual cleanup
- Improves data integrity for win/loss statistics
This commit is contained in:
mindesbunister
2025-11-09 17:59:50 +01:00
parent 4d533ccb53
commit 22195ed34c
15 changed files with 2166 additions and 17 deletions

124
QUICK_SETUP_CARD.md Normal file
View File

@@ -0,0 +1,124 @@
# Quick Reference - Your Setup Info
## ✅ Your Trading Bot Status
- **Container:** Running and healthy ✅
- **Endpoint:** Working correctly ✅
- **Server IP:** 10.0.0.48
---
## 📋 YOUR WEBHOOK URL
Use this URL in TradingView alerts:
```
http://10.0.0.48:3001/api/trading/market-data
```
**OR if you have n8n setup as proxy:**
```
https://flow.egonetix.de/webhook/market-data
```
---
## 📝 COPY-PASTE CHECKLIST
When creating EACH alert in TradingView:
### 1⃣ CONDITION
```
time("1") changes
```
### 2⃣ WEBHOOK URL
```
http://10.0.0.48:3001/api/trading/market-data
```
### 3⃣ ALERT MESSAGE (full JSON)
```json
{
"action": "market_data",
"symbol": "{{ticker}}",
"timeframe": "{{interval}}",
"atr": {{ta.atr(14)}},
"adx": {{ta.dmi(14, 14)}},
"rsi": {{ta.rsi(14)}},
"volumeRatio": {{volume / ta.sma(volume, 20)}},
"pricePosition": {{(close - ta.lowest(low, 100)) / (ta.highest(high, 100) - ta.lowest(low, 100)) * 100}},
"currentPrice": {{close}}
}
```
### 4⃣ SETTINGS
- **Frequency:** Once Per Bar Close
- **Expiration:** Never
- **Notifications:** ONLY ✅ Webhook URL (uncheck all others)
---
## 🎯 THE 3 ALERTS YOU NEED
| # | Symbol | Alert Name |
|---|---------|-------------------------|
| 1 | SOLUSDT | Market Data - SOL 5min |
| 2 | ETHUSDT | Market Data - ETH 5min |
| 3 | BTCUSDT | Market Data - BTC 5min |
All on 5-minute charts, all using same config above.
---
## ✅ VERIFICATION COMMAND
After creating alerts, wait 5 minutes, then run:
```bash
curl http://localhost:3001/api/trading/market-data
```
**You should see symbols appear:**
```json
{
"success": true,
"availableSymbols": ["SOL-PERP", "ETH-PERP", "BTC-PERP"],
"count": 3
}
```
---
## 🆘 IF SOMETHING GOES WRONG
**Check bot logs:**
```bash
docker logs -f trading-bot-v4
```
Watch for incoming POST requests when bar closes.
**Test from external machine:**
```bash
curl http://10.0.0.48:3001/api/trading/market-data
```
If this fails → port 3001 blocked by firewall.
---
## 📖 DETAILED GUIDE
See: `TRADINGVIEW_STEP_BY_STEP.md` for detailed walkthrough with screenshots.
---
## ⏭️ NEXT STEP
After alerts are working and cache is populated:
```bash
./scripts/run_exit_analysis.sh
```
This will analyze your trades and recommend optimal TP/SL levels.