Stock Oracle

AI-powered financial analysis

Fetch real-time stock data from Polygon.io and generate intelligent market analysis.
Complete pipeline from data retrieval to AI-driven insights.

← Back to Home

Interactive Demo

Enter comma-separated stock symbols (e.g., AAPL,MSFT,GOOGL)
Number of days of historical data to fetch

Code Example

// Stock Data Analysis Pipeline
class StockAnalyzer(private val openAI: OpenAI, private val polygon: Polygon) {
    
    suspend fun analyzeStocks(tickers: Array<String>, daysBack: Int): StockAnalysis {
        // Step 1: Fetch stock data from Polygon.io
        val aggregates = polygon.getAggregates(
            tickers = tickers,
            timespan = "day",
            from = LocalDate.now().minusDays(daysBack.toLong()),
            to = LocalDate.now()
        )
        
        // Step 2: Convert to JSON for AI processing
        val jsonData = polygon.aggregatesToJson(aggregates)
        
        // Step 3: Generate AI analysis
        val systemMessage = """
            You handle financial information. The input will be JSON data 
            from polygon.io API containing OHLCV data for multiple companies.
            Create a short report focusing on main differences between companies.
            Use fewer than 100 words.
        """.trimIndent()
        
        val response = openAI.createChatCompletion(jsonData, systemMessage)
        
        return StockAnalysis(
            tickers = tickers.toList(),
            rawData = aggregates,
            analysis = response.text()
        )
    }
}