From d3b83ae95a729a406b44a67fb04db09e333f18ca Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Sat, 6 Dec 2025 17:34:49 +0000 Subject: [PATCH 1/2] Initial plan From 2df6c69b92bb51ad15e95bfa6ac17f5f50e9cc66 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Sat, 6 Dec 2025 17:44:19 +0000 Subject: [PATCH 2/2] feat: Add FARTCOIN-PERP market support with percentage-based sizing - Added FARTCOIN-PERP to SUPPORTED_MARKETS (market index 22) - Updated TradingConfig interface with fartcoin symbol settings - Added default config: 20% portfolio, 10x leverage, disabled by default - Updated normalizeTradingViewSymbol to detect FARTCOIN - Enhanced getPositionSizeForSymbol for FARTCOIN-PERP handling - Enhanced getActualPositionSizeForSymbol for percentage-based sizing - Added FARTCOIN ENV variable loading in getConfigFromEnv - Updated Settings UI with FARTCOIN section and percentage badge - Added FARTCOIN fields to settings API endpoints (GET/POST) - Created comprehensive documentation in docs/markets/FARTCOIN-PERP.md - Build successful: TypeScript compilation and static generation complete Co-authored-by: mindesbunister <32161838+mindesbunister@users.noreply.github.com> --- app/api/settings/route.ts | 6 ++ app/settings/page.tsx | 78 ++++++++++++++++++ config/trading.ts | 41 ++++++++++ docs/markets/FARTCOIN-PERP.md | 149 ++++++++++++++++++++++++++++++++++ 4 files changed, 274 insertions(+) create mode 100644 docs/markets/FARTCOIN-PERP.md diff --git a/app/api/settings/route.ts b/app/api/settings/route.ts index 95abc85..6d4a3db 100644 --- a/app/api/settings/route.ts +++ b/app/api/settings/route.ts @@ -85,6 +85,9 @@ export async function GET() { ETHEREUM_POSITION_SIZE: parseFloat(env.ETHEREUM_POSITION_SIZE || '4'), ETHEREUM_LEVERAGE: parseFloat(env.ETHEREUM_LEVERAGE || '1'), ETHEREUM_USE_PERCENTAGE_SIZE: env.ETHEREUM_USE_PERCENTAGE_SIZE === 'true', + FARTCOIN_ENABLED: env.FARTCOIN_ENABLED === 'true', + FARTCOIN_POSITION_SIZE: parseFloat(env.FARTCOIN_POSITION_SIZE || '20'), + FARTCOIN_LEVERAGE: parseFloat(env.FARTCOIN_LEVERAGE || '10'), // Risk management STOP_LOSS_PERCENT: parseFloat(env.STOP_LOSS_PERCENT || '-1.5'), @@ -161,6 +164,9 @@ export async function POST(request: NextRequest) { ETHEREUM_ENABLED: settings.ETHEREUM_ENABLED.toString(), ETHEREUM_POSITION_SIZE: settings.ETHEREUM_POSITION_SIZE.toString(), ETHEREUM_LEVERAGE: settings.ETHEREUM_LEVERAGE.toString(), + FARTCOIN_ENABLED: settings.FARTCOIN_ENABLED.toString(), + FARTCOIN_POSITION_SIZE: settings.FARTCOIN_POSITION_SIZE.toString(), + FARTCOIN_LEVERAGE: settings.FARTCOIN_LEVERAGE.toString(), // Risk management STOP_LOSS_PERCENT: settings.STOP_LOSS_PERCENT.toString(), diff --git a/app/settings/page.tsx b/app/settings/page.tsx index 33ec8ea..106c6a7 100644 --- a/app/settings/page.tsx +++ b/app/settings/page.tsx @@ -23,6 +23,9 @@ interface TradingSettings { ETHEREUM_POSITION_SIZE: number ETHEREUM_LEVERAGE: number ETHEREUM_USE_PERCENTAGE_SIZE: boolean + FARTCOIN_ENABLED: boolean + FARTCOIN_POSITION_SIZE: number + FARTCOIN_LEVERAGE: number // Risk management STOP_LOSS_PERCENT: number @@ -467,6 +470,81 @@ export default function SettingsPage() { })()} + {/* FARTCOIN Section */} +
+
+

+ Enable/disable FARTCOIN trading with percentage-based position sizing for profit generation. Uses % of portfolio instead of fixed USD amounts. +

+
+ PERCENTAGE-BASED +
+
+
+
+
🟢 Enable Fartcoin Trading
+
+ Accept FARTCOIN-PERP trade signals from TradingView +
+
+ +
+ updateSetting('FARTCOIN_POSITION_SIZE', v)} + min={1} + max={100} + step={1} + description={`Percentage of your portfolio to allocate per FARTCOIN trade. With ${settings.FARTCOIN_LEVERAGE}x leverage = ${(settings.FARTCOIN_POSITION_SIZE * settings.FARTCOIN_LEVERAGE).toFixed(0)}% notional exposure. Example: 20% × $${collateral.toFixed(0)} = $${(settings.FARTCOIN_POSITION_SIZE / 100 * collateral).toFixed(2)} base.`} + /> + updateSetting('FARTCOIN_LEVERAGE', v)} + min={1} + max={10} + step={1} + description="Leverage multiplier for Fartcoin positions (max 10x based on Drift margin requirements)." + /> + {(() => { + const fartcoinRisk = { + maxLoss: (settings.FARTCOIN_POSITION_SIZE / 100 * collateral * settings.FARTCOIN_LEVERAGE) * 0.015, + fullWin: (settings.FARTCOIN_POSITION_SIZE / 100 * collateral * settings.FARTCOIN_LEVERAGE) * 0.018, + } + return ( +
+
FARTCOIN Risk/Reward (% of Portfolio)
+
+
+ Max Loss: + ${fartcoinRisk.maxLoss.toFixed(2)} +
+
+ Full Win: + ${fartcoinRisk.fullWin.toFixed(2)} +
+
+ R:R + 1:{(fartcoinRisk.fullWin / fartcoinRisk.maxLoss).toFixed(2)} +
+
+
+ ) + })()} +
+ {/* Global Position Sizing (Fallback) */}
diff --git a/config/trading.ts b/config/trading.ts index b632727..d280237 100644 --- a/config/trading.ts +++ b/config/trading.ts @@ -28,6 +28,7 @@ export interface TradingConfig { // Per-symbol settings solana?: SymbolSettings ethereum?: SymbolSettings + fartcoin?: SymbolSettings // Risk management (as percentages of entry price - LEGACY, used as fallback) stopLossPercent: number // Negative number (e.g., -1.5) @@ -135,6 +136,12 @@ export const DEFAULT_TRADING_CONFIG: TradingConfig = { leverage: 1, // 1x leverage = $4 notional usePercentageSize: false, }, + fartcoin: { + enabled: false, // DISABLED BY DEFAULT + positionSize: 20, // 20% of portfolio (for profit generation) + leverage: 10, // 10x leverage + usePercentageSize: true, // PERCENTAGE-BASED (not fixed USD) + }, // Risk parameters (LEGACY FALLBACK - used when ATR unavailable) stopLossPercent: -1.5, // Fallback: -1.5% if no ATR @@ -234,6 +241,14 @@ export const SUPPORTED_MARKETS: Record = { positionSize: 40, // $40 base capital leverage: 1, // 1x leverage = $40 total exposure }, + 'FARTCOIN-PERP': { + symbol: 'FARTCOIN-PERP', + driftMarketIndex: 22, + pythPriceFeedId: '2sZomfWMDuQLcFak3nuharXorHrZ3hK8iaML6ZGSHtso', + minOrderSize: 1, // 1 FARTCOIN minimum + tickSize: 0.0001, + // Use per-symbol config below + }, } // Map TradingView symbols to Drift markets @@ -243,6 +258,7 @@ export function normalizeTradingViewSymbol(tvSymbol: string): string { if (upper.includes('SOL')) return 'SOL-PERP' if (upper.includes('BTC')) return 'BTC-PERP' if (upper.includes('ETH')) return 'ETH-PERP' + if (upper.includes('FARTCOIN')) return 'FARTCOIN-PERP' // Default to SOL if unknown console.warn(`Unknown symbol ${tvSymbol}, defaulting to SOL-PERP`) @@ -277,6 +293,14 @@ export function getPositionSizeForSymbol(symbol: string, baseConfig: TradingConf } } + if (symbol === 'FARTCOIN-PERP' && baseConfig.fartcoin) { + return { + size: baseConfig.fartcoin.positionSize, + leverage: baseConfig.fartcoin.leverage, + enabled: baseConfig.fartcoin.enabled, + } + } + // Fallback to market-specific config, then global config const marketConfig = getMarketConfig(symbol) return { @@ -352,6 +376,13 @@ export async function getActualPositionSizeForSymbol( enabled: baseConfig.ethereum.enabled, } usePercentage = baseConfig.ethereum.usePercentageSize ?? false + } else if (symbol === 'FARTCOIN-PERP' && baseConfig.fartcoin) { + symbolSettings = { + size: baseConfig.fartcoin.positionSize, + leverage: baseConfig.fartcoin.leverage, + enabled: baseConfig.fartcoin.enabled, + } + usePercentage = baseConfig.fartcoin.usePercentageSize ?? false } else { // Fallback to market-specific or global config const marketConfig = getMarketConfig(symbol) @@ -502,6 +533,16 @@ export function getConfigFromEnv(): Partial { ? process.env.ETHEREUM_USE_PERCENTAGE_SIZE === 'true' : false, }, + fartcoin: { + enabled: process.env.FARTCOIN_ENABLED === 'true', + positionSize: process.env.FARTCOIN_POSITION_SIZE + ? parseFloat(process.env.FARTCOIN_POSITION_SIZE) + : 20, + leverage: process.env.FARTCOIN_LEVERAGE + ? parseInt(process.env.FARTCOIN_LEVERAGE) + : 10, + usePercentageSize: process.env.FARTCOIN_USE_PERCENTAGE_SIZE !== 'false', // Default true + }, leverage: process.env.LEVERAGE ? parseInt(process.env.LEVERAGE) : undefined, diff --git a/docs/markets/FARTCOIN-PERP.md b/docs/markets/FARTCOIN-PERP.md new file mode 100644 index 0000000..d2bc95c --- /dev/null +++ b/docs/markets/FARTCOIN-PERP.md @@ -0,0 +1,149 @@ +# FARTCOIN-PERP Market Configuration + +## Market Details +- **Market Index**: 22 +- **Symbol**: FARTCOIN-PERP +- **Oracle**: `2sZomfWMDuQLcFak3nuharXorHrZ3hK8iaML6ZGSHtso` +- **Min Order Size**: 1 FARTCOIN +- **Tick Size**: $0.0001 (price precision) +- **Initial Margin Ratio**: 10% (max 10x leverage) +- **Maintenance Margin Ratio**: 5% + +## Configuration Mode +- **Mode**: PROFIT GENERATION 💰 +- **Position Sizing**: Percentage-based (20% of portfolio default) +- **Default Leverage**: 10x +- **Status**: Disabled by default + +## Environment Variables +```bash +FARTCOIN_ENABLED=false # Enable/disable FARTCOIN trading +FARTCOIN_POSITION_SIZE=20 # 20% of portfolio (not fixed USD) +FARTCOIN_LEVERAGE=10 # Max 10x leverage +FARTCOIN_USE_PERCENTAGE_SIZE=true # Always true for FARTCOIN +``` + +## Enabling FARTCOIN Trading + +### Via Settings UI (Recommended) +1. Navigate to Settings page: `http://localhost:3001/settings` +2. Scroll to "🎈 Fartcoin (FARTCOIN-PERP)" section +3. Toggle "Enable Fartcoin Trading" to ON +4. Adjust position size percentage (recommended: 10-20%) +5. Set leverage (recommended: 10x for max profit potential) +6. Click "Save Settings" + +### Via Environment Variables +1. Edit `.env` file +2. Set `FARTCOIN_ENABLED=true` +3. Adjust `FARTCOIN_POSITION_SIZE` (1-100%) +4. Adjust `FARTCOIN_LEVERAGE` (1-10x) +5. Restart container: `docker restart trading-bot-v4` + +### Via TradingView Alert +Ensure your TradingView alert includes FARTCOIN symbol: +```json +{ + "symbol": "FARTCOINUSDT", // or "FARTCOIN" + "direction": "long", + // ... other fields +} +``` + +The bot will automatically normalize `FARTCOINUSDT` to `FARTCOIN-PERP`. + +## Position Size Calculation + +**Percentage-based sizing formula:** +``` +Base Capital = Portfolio × Position Size % +Notional Position = Base Capital × Leverage + +Example with $1000 portfolio: +- Position Size: 20% → Base = $200 +- Leverage: 10x → Notional = $2000 +- Risk Exposure: $200 (max loss is your base capital) +``` + +**Risk/Reward Example:** +- Portfolio: $1000 +- Position: 20% ($200) × 10x = $2000 notional +- Max Loss (1.5% SL): $30 (1.5% of $2000) +- Target Win (1.8% TP): $36 (1.8% of $2000) +- R:R Ratio: 1:1.2 + +## Key Differences from SOL/ETH + +| Feature | FARTCOIN | SOL | ETH | +|---------|----------|-----|-----| +| **Position Sizing** | Percentage-based | Fixed USD | Fixed USD | +| **Default Enabled** | ❌ Disabled | ✅ Enabled | ✅ Enabled | +| **Purpose** | Profit generation | Profit generation | Data collection | +| **Default Size** | 20% portfolio | $210 fixed | $4 fixed | +| **Default Leverage** | 10x | 10x | 1x | +| **Max Leverage** | 10x | 20x | 20x | + +## Risk Management + +**Important Notes:** +1. **Disabled by default** - Safe to deploy, enable when ready +2. **Max 10x leverage** - Based on Drift Protocol margin requirements +3. **Percentage sizing** - Automatically scales with portfolio size +4. **Quality thresholds** - Uses same signal quality filters as SOL/ETH +5. **Adaptive leverage** - Quality score determines actual leverage used + +## TradingView Setup + +Your indicator should include FARTCOIN detection logic. The bot will: +1. Receive webhook with `"symbol": "FARTCOINUSDT"` +2. Normalize to `FARTCOIN-PERP` via `normalizeTradingViewSymbol()` +3. Check if `FARTCOIN_ENABLED=true` +4. Calculate position size as percentage of free collateral +5. Apply max 10x leverage +6. Execute trade on Drift Protocol market index 22 + +## Testing Checklist + +Before enabling FARTCOIN trading in production: +- [ ] Settings UI shows FARTCOIN section correctly +- [ ] Toggle switch works (enabled/disabled state) +- [ ] Position size slider adjusts (1-100%) +- [ ] Leverage slider adjusts (1-10x) +- [ ] Risk calculator shows correct values +- [ ] Percentage calculation: 20% of $1000 = $200 base +- [ ] Notional calculation: $200 × 10x = $2000 +- [ ] Settings save successfully to .env +- [ ] Container restart applies new settings +- [ ] Symbol detection works: "FARTCOINUSDT" → "FARTCOIN-PERP" +- [ ] Test trade executes with correct position size + +## Monitoring + +Watch for these log messages when FARTCOIN trading is active: +``` +📊 Percentage sizing: 20% of $1000.00 = $200.00 +📊 Adaptive leverage: Quality 92 → 10x leverage +🎯 Opening position: FARTCOIN-PERP LONG $2000.00 (10x leverage) +✅ Position opened successfully +``` + +## Troubleshooting + +**FARTCOIN trades not executing:** +1. Check `FARTCOIN_ENABLED=true` in settings +2. Verify symbol normalization in logs +3. Check quality score meets threshold (90+ for LONG, 95+ for SHORT) +4. Ensure TradingView alert includes correct symbol +5. Verify free collateral > required amount + +**Position size incorrect:** +1. Check `FARTCOIN_USE_PERCENTAGE_SIZE=true` (should always be true) +2. Verify percentage calculation in logs +3. Check free collateral value +4. Ensure leverage is between 1-10x + +**Settings not saving:** +1. Check .env file permissions (should be writable) +2. Verify container has access to .env file +3. Check logs for "Settings updated" message +4. Restart container after manual .env changes