/** * Test script for Phase 1 API endpoint * Run with: node test_phase1_api.js */ const PYTHON_SERVICE_URL = process.env.PYTHON_SERVICE_URL || 'http://localhost:8010'; async function testPhase1API() { console.log('๐Ÿงช Testing Phase 1 API Endpoint...\n'); try { // Test 1: Health check console.log('1๏ธโƒฃ Testing health endpoint...'); const healthResponse = await fetch(`${PYTHON_SERVICE_URL}/health`); const healthData = await healthResponse.json(); console.log('โœ… Health:', healthData); console.log(''); // Test 2: Options flow with Phase 1 fields console.log('2๏ธโƒฃ Testing options flow endpoint...'); const today = new Date().toISOString().split('T')[0]; const yesterday = new Date(Date.now() - 24 * 60 * 60 * 1000).toISOString().split('T')[0]; const flowUrl = `${PYTHON_SERVICE_URL}/api/options-flow?start_date=${yesterday}&end_date=${today}&min_premium=80000`; console.log(` URL: ${flowUrl}`); const flowResponse = await fetch(flowUrl); const flowData = await flowResponse.json(); if (!flowData.success) { console.error('โŒ API returned error:', flowData); return; } console.log(`โœ… Response: ${flowData.count} records`); console.log(''); // Test 3: Check for Phase 1 fields console.log('3๏ธโƒฃ Checking for Phase 1 fields...'); if (flowData.data && flowData.data.length > 0) { const firstRow = flowData.data[0]; const phase1Fields = { 'signal_tier': firstRow.signal_tier, 'is_tradeable': firstRow.is_tradeable, 'checklist_score': firstRow.checklist_score, 'checklist_passed': firstRow.checklist_passed, 'checklist_details': firstRow.checklist_details, 'price_reaction_5m_pct': firstRow.price_reaction_5m_pct, 'flow_led_to_move': firstRow.flow_led_to_move, 'vwap_at_signal': firstRow.vwap_at_signal, 'price_vs_vwap_pct': firstRow.price_vs_vwap_pct, }; console.log('Phase 1 Fields in first row:'); Object.entries(phase1Fields).forEach(([key, value]) => { const status = value !== undefined && value !== null ? 'โœ…' : 'โŒ'; console.log(` ${status} ${key}: ${JSON.stringify(value)}`); }); // Count Tier-1 signals const tier1Count = flowData.data.filter(r => r.signal_tier === 'TIER_1').length; const checklistPassedCount = flowData.data.filter(r => r.checklist_passed === true).length; const flowLedToMoveCount = flowData.data.filter(r => r.flow_led_to_move === true).length; console.log(''); console.log('๐Ÿ“Š Phase 1 Statistics:'); console.log(` Tier-1 signals: ${tier1Count}/${flowData.count}`); console.log(` Checklist passed: ${checklistPassedCount}/${flowData.count}`); console.log(` Flow led to move: ${flowLedToMoveCount}/${flowData.count}`); } else { console.log('โš ๏ธ No data returned - cannot verify Phase 1 fields'); } console.log(''); console.log('โœ… Phase 1 API test complete!'); } catch (error) { console.error('โŒ Error testing API:', error.message); console.error(' Make sure the Python service is running on', PYTHON_SERVICE_URL); } } // Run the test testPhase1API();