omniverse1 commited on
Commit
7df1b11
·
verified ·
1 Parent(s): 70d7d18

Update sentiment_analyzer.py

Browse files
Files changed (1) hide show
  1. sentiment_analyzer.py +38 -37
sentiment_analyzer.py CHANGED
@@ -13,51 +13,52 @@ class SentimentAnalyzer:
13
  "Technical breakout above resistance level",
14
  "Profit-taking observed after recent rally"
15
  ]
16
- self.crypto_sources = [
17
- "Fed rate hike fear drives BTC sell-off",
18
- "Institutional adoption pushes Bitcoin price up",
19
- "Whale wallets show large accumulation activity",
20
- "Regulatory uncertainty weighs on crypto market",
21
- "New protocol launch fuels altcoin rally",
22
- "ETF approval anticipation creates bullish momentum",
23
- "High funding rates suggest market overheating",
24
- "Tether minting correlates with short-term pumps"
25
  ]
26
 
27
- def analyze_market_sentiment(self, ticker):
28
- """Analyze sentiment for a given market (Simulated)"""
29
  try:
30
- # PENTING: Untuk sentimen riil, Anda harus mengintegrasikan API Berita Finansial (misalnya Finnhub, MarketAux)
31
- # dan model NLP (misalnya BERT/Transformer) untuk menganalisis berita secara aktual.
32
-
33
- # Memilih sumber data dan warna berdasarkan Ticker
34
- if ticker == "BTC-USD":
35
- base_sentiment = random.uniform(-0.3, 0.7)
36
- sources = self.crypto_sources
37
- title_color = "#FFA500"
38
- else: # GC=F
39
- base_sentiment = random.uniform(-0.5, 0.5)
40
  sources = self.gold_sources
41
- title_color = "#FFD700"
42
-
43
- # Simulasi analisis sentimen
44
- sentiment = base_sentiment + random.uniform(-0.2, 0.2)
 
 
 
 
 
 
 
 
45
  sentiment = max(-1, min(1, sentiment))
46
-
47
  # Generate news summary
48
- num_news = random.randint(3, 5)
49
  selected_news = random.sample(sources, num_news)
50
-
51
- # Tampilan News (menggunakan background terang #E0E0E0 agar terlihat di tema putih)
52
- news_html = "<div style='max-height: 200px; overflow-y: auto; color: black;'>"
53
- news_html += f"<h4 style='color: {title_color};'>Latest {ticker} News (Simulated)</h4>"
54
-
55
- for news in selected_news:
56
- sentiment_label = "🟢" if "positive" in news or "rising" in news or "support" in news or "bullish" in news or "accumulation" in news else \
57
- "🔴" if "sell-off" in news or "weighs" in news or "outflows" in news or "Profit-taking" in news or "fear" in news else \
58
  "🟡"
59
- news_html += f"<p style='margin: 10px 0; padding: 10px; background: #E0E0E0; border-radius: 5px; color: black;'>{sentiment_label} {news}</p>"
60
-
61
  news_html += "</div>"
62
 
63
  return sentiment, news_html
 
13
  "Technical breakout above resistance level",
14
  "Profit-taking observed after recent rally"
15
  ]
16
+ self.bitcoin_sources = [
17
+ "Institutional adoption of Bitcoin accelerates",
18
+ "Regulatory clarity improves - positive for crypto",
19
+ "Bitcoin halving event supports price",
20
+ "Macro uncertainty drives Bitcoin demand",
21
+ "Spot ETF inflows reach record highs",
22
+ "Network hash rate reaches new ATH",
23
+ "Whale accumulation detected on-chain",
24
+ "DeFi TVL growth supports crypto market"
25
  ]
26
 
27
+ def analyze_sentiment(self, asset_name):
28
+ """Analyze sentiment for selected asset"""
29
  try:
30
+ # Select appropriate news sources
31
+ if "Bitcoin" in asset_name:
32
+ sources = self.bitcoin_sources
33
+ else:
 
 
 
 
 
 
34
  sources = self.gold_sources
35
+
36
+ # Generate random sentiment around current market conditions
37
+ base_sentiment = random.uniform(-0.5, 0.5)
38
+
39
+ # Add some realistic variation
40
+ if random.random() > 0.7:
41
+ # Strong sentiment event
42
+ sentiment = base_sentiment + random.uniform(-0.5, 0.5)
43
+ else:
44
+ sentiment = base_sentiment
45
+
46
+ # Clamp between -1 and 1
47
  sentiment = max(-1, min(1, sentiment))
48
+
49
  # Generate news summary
50
+ num_news = random.randint(3, 6)
51
  selected_news = random.sample(sources, num_news)
52
+
53
+ news_html = f"<div style='max-height: 300px; overflow-y: auto;'>"
54
+ news_html += f"<h4 style='color: #4169E1;'>{asset_name} Market News</h4>"
55
+
56
+ for i, news in enumerate(selected_news, 1):
57
+ sentiment_label = "🟢" if "positive" in news or "rising" in news or "support" in news or "accelerates" in news or " ATH" in news else \
58
+ "🔴" if "weighs" in news or "outflows" in news or "Profit-taking" in news else \
 
59
  "🟡"
60
+ news_html += f"<p style='margin: 10px 0; padding: 10px; background: rgba(65,105,225,0.05); border-radius: 5px;'>{sentiment_label} {news}</p>"
61
+
62
  news_html += "</div>"
63
 
64
  return sentiment, news_html