34 lines
1.2 KiB
TypeScript
34 lines
1.2 KiB
TypeScript
|
|
import { GoogleGenAI } from "@google/genai";
|
|
|
|
export async function analyzeMarketSentiment(news: string[]) {
|
|
const ai = new GoogleGenAI({ apiKey: process.env.API_KEY });
|
|
const prompt = `Based on the following news headlines, provide a concise market sentiment summary (Bullish/Bearish/Neutral) and 3 key takeaways for a stock trader. News: ${news.join('. ')}`;
|
|
|
|
try {
|
|
const response = await ai.models.generateContent({
|
|
model: 'gemini-3-flash-preview',
|
|
contents: prompt,
|
|
});
|
|
return response.text;
|
|
} catch (error) {
|
|
console.error("Gemini Error:", error);
|
|
return "AI insight currently unavailable.";
|
|
}
|
|
}
|
|
|
|
export async function getStockInsight(stockName: string, recentTrend: string) {
|
|
const ai = new GoogleGenAI({ apiKey: process.env.API_KEY });
|
|
const prompt = `Analyze the stock ${stockName} which has been ${recentTrend}. Suggest a potential strategy for an automated trading bot (e.g., Trailing Stop percentage, Accumulation frequency).`;
|
|
|
|
try {
|
|
const response = await ai.models.generateContent({
|
|
model: 'gemini-3-pro-preview',
|
|
contents: prompt,
|
|
});
|
|
return response.text;
|
|
} catch (error) {
|
|
return "Detailed analysis unavailable at this moment.";
|
|
}
|
|
}
|