initial commit
This commit is contained in:
33
services/geminiService.ts
Normal file
33
services/geminiService.ts
Normal file
@@ -0,0 +1,33 @@
|
||||
|
||||
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.";
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user