#!/usr/bin/env node // Test script to verify cost control implementation const { PaperTradingUsageTracker } = require('./lib/paper-trading-config'); async function testCostControl() { console.log('๐Ÿงช Testing Paper Trading Cost Control System...\n'); const tracker = new PaperTradingUsageTracker(); // Test 1: Check timeframe configurations console.log('๐Ÿ“Š Timeframe Configurations:'); const timeframes = [ { value: '5', label: '5 Minutes' }, { value: '30', label: '30 Minutes' }, { value: '60', label: '1 Hour' }, { value: '240', label: '4 Hours' } ]; timeframes.forEach(tf => { const config = tracker.getTimeframeConfig(tf.value); console.log(` ${tf.label}: ${config.maxDaily} analyses/day, Risk: ${config.riskLevel}, Cost: ${config.cost}`); }); // Test 2: Usage tracking console.log('\n๐Ÿ’ฐ Usage Tracking:'); const stats = tracker.getTodaysUsage('60'); console.log(` Today's usage for 1H: ${stats.dailyCount} analyses`); console.log(` Estimated cost: $${stats.estimatedDailyCost.toFixed(4)}`); console.log(` Hit daily limit: ${stats.hitDailyLimit ? 'Yes' : 'No'}`); // Test 3: Cooldown system console.log('\nโฑ๏ธ Cooldown System:'); const canAnalyze = tracker.canAnalyze('60'); console.log(` Can analyze 1H timeframe: ${canAnalyze ? 'Yes' : 'No'}`); if (canAnalyze) { console.log(' Recording simulated analysis...'); tracker.recordAnalysis('60'); const canAnalyzeAgain = tracker.canAnalyze('60'); console.log(` Can analyze again immediately: ${canAnalyzeAgain ? 'Yes' : 'No'}`); const cooldownTime = tracker.getCooldownRemaining('60'); console.log(` Cooldown remaining: ${Math.ceil(cooldownTime / 1000)} seconds`); } // Test 4: Cost estimation console.log('\n๐Ÿ“ˆ Cost Estimation:'); const dailyAnalyses = [5, 10, 20, 50]; dailyAnalyses.forEach(count => { const cost = count * 0.006; const monthlyEst = cost * 30; console.log(` ${count} analyses/day = $${cost.toFixed(3)}/day (~$${monthlyEst.toFixed(2)}/month)`); }); console.log('\nโœ… Cost Control System Test Complete!'); console.log('๐Ÿ’ก Your selected timeframes (5m, 30m, 1h, 4h) are configured with appropriate limits.'); console.log('๐Ÿ›ก๏ธ 5-minute cooldowns and daily limits will prevent excessive OpenAI costs.'); } testCostControl().catch(console.error);