feat: Add per-symbol trading controls for SOL and ETH
- Add SymbolSettings interface with enabled/positionSize/leverage fields - Implement per-symbol ENV variables (SOLANA_*, ETHEREUM_*) - Add SOL and ETH sections to settings UI with enable/disable toggles - Add symbol-specific test buttons (SOL LONG/SHORT, ETH LONG/SHORT) - Update execute and test endpoints to check symbol enabled status - Add real-time risk/reward calculator per symbol - Rename 'Position Sizing' to 'Global Fallback' for clarity - Fix position manager P&L calculation for externally closed positions - Fix zero P&L bug affecting 12 historical trades - Add SQL scripts for recalculating historical P&L data - Move archive TypeScript files to .archive to fix build Defaults: - SOL: 10 base × 10x leverage = 100 notional (profit trading) - ETH: base × 1x leverage = notional (data collection) - Global: 10 × 10x for BTC and other symbols Configuration priority: Per-symbol ENV > Market config > Global ENV > Defaults
This commit is contained in:
248
docs/guides/PER_SYMBOL_QUICK_REF.md
Normal file
248
docs/guides/PER_SYMBOL_QUICK_REF.md
Normal file
@@ -0,0 +1,248 @@
|
||||
# Per-Symbol Settings Quick Reference
|
||||
|
||||
## Access Settings UI
|
||||
```
|
||||
http://localhost:3001/settings
|
||||
```
|
||||
|
||||
## Symbol Sections
|
||||
|
||||
### 💎 Solana (SOL-PERP)
|
||||
- **Toggle**: Enable/disable SOL trading
|
||||
- **Position Size**: Base USD amount (default: 210)
|
||||
- **Leverage**: Multiplier 1-20x (default: 10x)
|
||||
- **Notional**: $210 × 10x = $2100 position
|
||||
- **Use Case**: Primary profit generation
|
||||
|
||||
### ⚡ Ethereum (ETH-PERP)
|
||||
- **Toggle**: Enable/disable ETH trading
|
||||
- **Position Size**: Base USD amount (default: 4)
|
||||
- **Leverage**: Multiplier 1-20x (default: 1x)
|
||||
- **Notional**: $4 × 1x = $4 position
|
||||
- **Use Case**: Data collection with minimal risk
|
||||
- **Note**: Drift minimum is ~$38-40 (0.01 ETH)
|
||||
|
||||
### 💰 Global Fallback
|
||||
- **Applies To**: BTC-PERP and any future symbols
|
||||
- **Position Size**: Default: 54
|
||||
- **Leverage**: Default: 10x
|
||||
|
||||
## Environment Variables
|
||||
|
||||
```bash
|
||||
# SOL Settings
|
||||
SOLANA_ENABLED=true
|
||||
SOLANA_POSITION_SIZE=210
|
||||
SOLANA_LEVERAGE=10
|
||||
|
||||
# ETH Settings
|
||||
ETHEREUM_ENABLED=true
|
||||
ETHEREUM_POSITION_SIZE=4
|
||||
ETHEREUM_LEVERAGE=1
|
||||
|
||||
# Global Fallback (BTC, etc.)
|
||||
MAX_POSITION_SIZE_USD=54
|
||||
LEVERAGE=10
|
||||
```
|
||||
|
||||
## Common Scenarios
|
||||
|
||||
### Scenario 1: Disable ETH Trading
|
||||
1. Go to Settings UI
|
||||
2. Toggle off "Enable Ethereum Trading"
|
||||
3. Click "Save Settings"
|
||||
4. Click "Restart Bot"
|
||||
5. All ETH signals will now be rejected
|
||||
|
||||
### Scenario 2: Increase SOL Position Size
|
||||
1. Go to Settings UI
|
||||
2. Adjust "SOL Position Size" slider or input
|
||||
3. Adjust "SOL Leverage" if needed
|
||||
4. Review Risk/Reward calculator
|
||||
5. Click "Save Settings"
|
||||
6. Click "Restart Bot"
|
||||
|
||||
### Scenario 3: Test Single Symbol
|
||||
1. Go to Settings UI
|
||||
2. Click "💎 Test SOL LONG" or "⚡ Test ETH LONG"
|
||||
3. Confirm warning dialog
|
||||
4. Watch for success/error message
|
||||
5. Check Position Manager logs
|
||||
|
||||
### Scenario 4: Minimal Risk on Both
|
||||
```bash
|
||||
SOLANA_ENABLED=true
|
||||
SOLANA_POSITION_SIZE=4
|
||||
SOLANA_LEVERAGE=1
|
||||
ETHEREUM_ENABLED=true
|
||||
ETHEREUM_POSITION_SIZE=4
|
||||
ETHEREUM_LEVERAGE=1
|
||||
```
|
||||
|
||||
## Test Buttons
|
||||
|
||||
### 💎 SOL Test Buttons
|
||||
- **Test SOL LONG**: Opens long position with SOL settings
|
||||
- **Test SOL SHORT**: Opens short position with SOL settings
|
||||
- Disabled when `SOLANA_ENABLED=false`
|
||||
|
||||
### ⚡ ETH Test Buttons
|
||||
- **Test ETH LONG**: Opens long position with ETH settings
|
||||
- **Test ETH SHORT**: Opens short position with ETH settings
|
||||
- Disabled when `ETHEREUM_ENABLED=false`
|
||||
|
||||
## Checking Current Settings
|
||||
|
||||
### Via UI
|
||||
```
|
||||
http://localhost:3001/settings
|
||||
```
|
||||
|
||||
### Via API
|
||||
```bash
|
||||
curl http://localhost:3001/api/settings | jq
|
||||
```
|
||||
|
||||
### Via Container Logs
|
||||
```bash
|
||||
docker logs trading-bot-v4 | grep "Symbol-specific sizing"
|
||||
```
|
||||
|
||||
### Via Environment
|
||||
```bash
|
||||
docker exec trading-bot-v4 printenv | grep -E "SOLANA|ETHEREUM|POSITION_SIZE|LEVERAGE"
|
||||
```
|
||||
|
||||
## Priority Order
|
||||
When bot receives signal, it checks in this order:
|
||||
1. ✅ **Per-symbol ENV** (`SOLANA_POSITION_SIZE`) - highest priority
|
||||
2. Market-specific config (code level)
|
||||
3. Global ENV (`MAX_POSITION_SIZE_USD`) - fallback
|
||||
4. Default config (code level) - last resort
|
||||
|
||||
## Risk Calculator
|
||||
Each symbol section shows:
|
||||
- **Max Loss**: Base × Leverage × |SL%|
|
||||
- **Full Win**: TP1 gain + TP2 gain
|
||||
- **R:R Ratio**: How much you win vs how much you risk
|
||||
|
||||
### Example: SOL with $210 × 10x
|
||||
- SL: -1.5% → Max Loss: $31.50
|
||||
- TP1: +0.7% (50% position) → $7.35
|
||||
- TP2: +1.5% (50% position) → $15.75
|
||||
- Full Win: $23.10
|
||||
- R:R: 1:0.73
|
||||
|
||||
## Monitoring Per-Symbol Trading
|
||||
|
||||
### Check if Symbol Enabled
|
||||
```bash
|
||||
# Look for "Symbol trading disabled" errors
|
||||
docker logs trading-bot-v4 | grep "trading disabled"
|
||||
```
|
||||
|
||||
### Check Position Sizes
|
||||
```bash
|
||||
# Look for symbol-specific sizing logs
|
||||
docker logs trading-bot-v4 | grep "Symbol-specific sizing"
|
||||
```
|
||||
|
||||
### Recent ETH Trades
|
||||
```bash
|
||||
docker exec trading-bot-postgres psql -U postgres -d trading_bot_v4 -c "
|
||||
SELECT
|
||||
entry_time::timestamp,
|
||||
symbol,
|
||||
direction,
|
||||
base_position_size,
|
||||
leverage,
|
||||
ROUND(position_size, 2) as notional,
|
||||
ROUND(realized_pnl, 2) as pnl
|
||||
FROM trades
|
||||
WHERE symbol = 'ETH-PERP'
|
||||
AND test_trade = false
|
||||
ORDER BY entry_time DESC
|
||||
LIMIT 10;
|
||||
"
|
||||
```
|
||||
|
||||
### Recent SOL Trades
|
||||
```bash
|
||||
docker exec trading-bot-postgres psql -U postgres -d trading_bot_v4 -c "
|
||||
SELECT
|
||||
entry_time::timestamp,
|
||||
symbol,
|
||||
direction,
|
||||
base_position_size,
|
||||
leverage,
|
||||
ROUND(position_size, 2) as notional,
|
||||
ROUND(realized_pnl, 2) as pnl
|
||||
FROM trades
|
||||
WHERE symbol = 'SOL-PERP'
|
||||
AND test_trade = false
|
||||
ORDER BY entry_time DESC
|
||||
LIMIT 10;
|
||||
"
|
||||
```
|
||||
|
||||
## Troubleshooting
|
||||
|
||||
### "Symbol trading disabled" Error
|
||||
**Cause**: Symbol is toggled off in settings
|
||||
**Solution**:
|
||||
1. Check settings UI - is toggle on?
|
||||
2. Check ENV: `docker exec trading-bot-v4 printenv | grep ENABLED`
|
||||
3. If needed, set `SOLANA_ENABLED=true` or `ETHEREUM_ENABLED=true`
|
||||
4. Restart bot
|
||||
|
||||
### ETH Trades Using $540 Instead of $4
|
||||
**Cause**: Global ENV override
|
||||
**Solution**:
|
||||
1. Check: `docker exec trading-bot-v4 printenv | grep ETHEREUM`
|
||||
2. Should see: `ETHEREUM_POSITION_SIZE=4`
|
||||
3. If not, update settings UI and restart
|
||||
4. Verify logs show: `ETH Position size: $4`
|
||||
|
||||
### SOL Trades Using Wrong Size
|
||||
**Cause**: Global ENV override
|
||||
**Solution**:
|
||||
1. Check: `docker exec trading-bot-v4 printenv | grep SOLANA`
|
||||
2. Should see: `SOLANA_POSITION_SIZE=210`
|
||||
3. If not, update settings UI and restart
|
||||
|
||||
### Changes Not Applied After Save
|
||||
**Cause**: Bot not restarted
|
||||
**Solution**:
|
||||
1. Settings page shows: "Click Restart Bot to apply changes"
|
||||
2. Must click "🔄 Restart Bot" button
|
||||
3. Wait ~10 seconds for restart
|
||||
4. Verify with `docker logs trading-bot-v4`
|
||||
|
||||
## Best Practices
|
||||
|
||||
1. **Test First**: Use test buttons before enabling live trading
|
||||
2. **Check Risk**: Review Risk/Reward calculator before changing sizes
|
||||
3. **Save + Restart**: Always restart after saving settings
|
||||
4. **Monitor Logs**: Watch logs for first few trades after changes
|
||||
5. **Verify Sizes**: Check database to confirm actual executed sizes
|
||||
6. **One at a Time**: Change one symbol setting at a time for easier debugging
|
||||
|
||||
## Quick Commands
|
||||
|
||||
```bash
|
||||
# Full system restart
|
||||
docker compose restart trading-bot
|
||||
|
||||
# View real-time logs
|
||||
docker logs -f trading-bot-v4
|
||||
|
||||
# Check ENV variables
|
||||
docker exec trading-bot-v4 printenv | grep -E "POSITION|LEVERAGE|ENABLED"
|
||||
|
||||
# Test settings API
|
||||
curl http://localhost:3001/api/settings | jq
|
||||
|
||||
# Check recent trades by symbol
|
||||
docker exec trading-bot-postgres psql -U postgres -d trading_bot_v4 -c \
|
||||
"SELECT symbol, COUNT(*), ROUND(SUM(realized_pnl),2) FROM trades WHERE test_trade=false GROUP BY symbol;"
|
||||
```
|
||||
Reference in New Issue
Block a user