import random from datetime import datetime class SentimentAnalyzer: def __init__(self): self.gold_sources = [ "Federal Reserve hints at rate pause - positive for gold", "Inflation data higher than expected - gold demand rising", "Dollar strength weighs on precious metals", "Central banks continue gold accumulation", "Geopolitical tensions support safe-haven demand", "Gold ETFs see outflows amid risk-on sentiment", "Technical breakout above resistance level", "Profit-taking observed after recent rally" ] self.crypto_sources = [ "Fed rate hike fear drives BTC sell-off", "Institutional adoption pushes Bitcoin price up", "Whale wallets show large accumulation activity", "Regulatory uncertainty weighs on crypto market", "New protocol launch fuels altcoin rally", "ETF approval anticipation creates bullish momentum", "High funding rates suggest market overheating", "Tether minting correlates with short-term pumps" ] def analyze_market_sentiment(self, ticker): """Analyze sentiment for a given market (Simulated)""" try: # PENTING: Untuk sentimen riil, Anda harus mengintegrasikan API Berita Finansial (misalnya Finnhub, MarketAux) # dan model NLP (misalnya BERT/Transformer) untuk menganalisis berita secara aktual. # Memilih sumber data dan warna berdasarkan Ticker if ticker == "BTC-USD": base_sentiment = random.uniform(-0.3, 0.7) sources = self.crypto_sources title_color = "#FFA500" else: # GC=F base_sentiment = random.uniform(-0.5, 0.5) sources = self.gold_sources title_color = "#FFD700" # Simulasi analisis sentimen sentiment = base_sentiment + random.uniform(-0.2, 0.2) sentiment = max(-1, min(1, sentiment)) # Generate news summary num_news = random.randint(3, 5) selected_news = random.sample(sources, num_news) # Tampilan News (menggunakan background terang #E0E0E0 agar terlihat di tema putih) news_html = "
{sentiment_label} {news}
" news_html += "Error analyzing sentiment: {str(e)}
"