AlphaV15-Quant-Engine / sentiment_engine.py
Nexo-S's picture
Upload 3 files
d93dba0 verified
raw
history blame
1.09 kB
# sentiment_engine.py
from vaderSentiment.vaderSentiment import SentimentIntensityAnalyzer
import aiohttp
analyzer = SentimentIntensityAnalyzer()
async def get_crypto_sentiment(symbol):
API_KEY = "6388e0c06c9ea848afee62ffe6a3dc9f1022e7ad"
base_coin = symbol.split('/')[0]
url = f"https://cryptopanic.com/api/v1/posts/?auth_token={API_KEY}&currencies={base_coin}&filter=hot"
try:
async with aiohttp.ClientSession() as session:
async with session.get(url, timeout=5) as resp:
if resp.status == 200:
data = await resp.json()
all_text = ""
for post in data.get('results', [])[:10]:
all_text += post['title'] + " "
if not all_text: return 0.5
vs = analyzer.polarity_scores(all_text)
# Transformation (-1 à 1) -> (0 à 1)
return (vs['compound'] + 1) / 2
return 0.5
except:
return 0.5