212 lines
6.2 KiB
Python
212 lines
6.2 KiB
Python
"""
|
|
Insider Data Service for aggregating and analyzing insider trading data.
|
|
"""
|
|
|
|
import logging
|
|
from dataclasses import dataclass
|
|
from enum import Enum
|
|
from typing import Any
|
|
|
|
from tradingagents.config import TradingAgentsConfig
|
|
|
|
from .clients.finnhub_client import FinnhubClient
|
|
|
|
logger = logging.getLogger(__name__)
|
|
|
|
|
|
class InsiderDataRepository:
|
|
"""Simple repository for insider data - placeholder implementation."""
|
|
|
|
def __init__(self, data_dir: str):
|
|
self.data_dir = data_dir
|
|
|
|
def get_data(self, symbol: str, start_date: str, end_date: str) -> dict:
|
|
return {}
|
|
|
|
def store_data(self, symbol: str, data: dict) -> bool:
|
|
return True
|
|
|
|
|
|
class DataQuality(Enum):
|
|
"""Data quality levels for insider data."""
|
|
|
|
HIGH = "high"
|
|
MEDIUM = "medium"
|
|
LOW = "low"
|
|
|
|
|
|
@dataclass
|
|
class InsiderTransaction:
|
|
"""Insider transaction data."""
|
|
|
|
date: str # YYYY-MM-DD format
|
|
insider_name: str
|
|
title: str
|
|
transaction_type: str # "Purchase", "Sale", "Exercise", etc.
|
|
shares: int
|
|
price_per_share: float
|
|
total_value: float
|
|
shares_owned_after: int
|
|
filing_date: str
|
|
|
|
|
|
@dataclass
|
|
class InsiderSentimentContext:
|
|
"""Insider sentiment context for trading analysis."""
|
|
|
|
symbol: str
|
|
period: dict[str, str] # {"start": "YYYY-MM-DD", "end": "YYYY-MM-DD"}
|
|
transactions: list[InsiderTransaction]
|
|
sentiment_score: float # -1.0 to 1.0 (-1: very bearish, 1: very bullish)
|
|
net_buying_value: float # Net buying (positive) or selling (negative) in USD
|
|
insider_count: int # Number of unique insiders in period
|
|
transaction_count: int
|
|
analysis_summary: str
|
|
metadata: dict[str, Any]
|
|
|
|
|
|
@dataclass
|
|
class InsiderTransactionContext:
|
|
"""Insider transaction context for detailed transaction analysis."""
|
|
|
|
symbol: str
|
|
period: dict[str, str] # {"start": "YYYY-MM-DD", "end": "YYYY-MM-DD"}
|
|
transactions: list[InsiderTransaction]
|
|
total_transaction_value: float
|
|
net_insider_activity: float # Net buying/selling activity
|
|
top_insiders: list[dict[str, Any]] # Top insiders by transaction value
|
|
transaction_summary: dict[str, Any] # Summary stats by transaction type
|
|
analysis_summary: str
|
|
metadata: dict[str, Any]
|
|
|
|
|
|
class InsiderDataService:
|
|
"""Service for insider trading data aggregation and analysis."""
|
|
|
|
def __init__(
|
|
self,
|
|
client: FinnhubClient,
|
|
repository: InsiderDataRepository,
|
|
):
|
|
"""
|
|
Initialize insider data service.
|
|
|
|
Args:
|
|
client: Client for insider data (e.g., FinnhubClient)
|
|
repository: Repository for cached insider data
|
|
online_mode: Whether to use live data
|
|
**kwargs: Additional configuration
|
|
"""
|
|
self.client = client
|
|
self.repository = repository
|
|
|
|
@staticmethod
|
|
def build(_config: TradingAgentsConfig):
|
|
client = FinnhubClient("")
|
|
repo = InsiderDataRepository("")
|
|
return InsiderDataService(client, repo)
|
|
|
|
def get_insider_sentiment_context(
|
|
self,
|
|
symbol: str,
|
|
start_date: str,
|
|
end_date: str,
|
|
) -> InsiderSentimentContext:
|
|
"""
|
|
Get insider sentiment context for a company.
|
|
|
|
Args:
|
|
symbol: Stock ticker symbol
|
|
start_date: Start date in YYYY-MM-DD format
|
|
end_date: End date in YYYY-MM-DD format
|
|
**kwargs: Additional parameters
|
|
|
|
Returns:
|
|
InsiderSentimentContext: Insider sentiment analysis
|
|
"""
|
|
# TODO: Implement insider sentiment analysis
|
|
transactions = []
|
|
sentiment_score = 0.0
|
|
net_buying_value = 0.0
|
|
analysis_summary = f"Insider sentiment analysis for {symbol}"
|
|
|
|
metadata = {
|
|
"data_quality": DataQuality.HIGH if transactions else DataQuality.LOW,
|
|
"service": "insider_data",
|
|
"data_source": "placeholder",
|
|
"analysis_method": "insider_sentiment",
|
|
}
|
|
|
|
return InsiderSentimentContext(
|
|
symbol=symbol,
|
|
period={"start": start_date, "end": end_date},
|
|
transactions=transactions,
|
|
sentiment_score=sentiment_score,
|
|
net_buying_value=net_buying_value,
|
|
insider_count=0,
|
|
transaction_count=len(transactions),
|
|
analysis_summary=analysis_summary,
|
|
metadata=metadata,
|
|
)
|
|
|
|
def get_insider_transaction_context(
|
|
self,
|
|
symbol: str,
|
|
start_date: str,
|
|
end_date: str,
|
|
) -> InsiderTransactionContext:
|
|
"""
|
|
Get insider transaction context for detailed analysis.
|
|
|
|
Args:
|
|
symbol: Stock ticker symbol
|
|
start_date: Start date in YYYY-MM-DD format
|
|
end_date: End date in YYYY-MM-DD format
|
|
**kwargs: Additional parameters
|
|
|
|
Returns:
|
|
InsiderTransactionContext: Detailed insider transaction analysis
|
|
"""
|
|
# TODO: Implement insider transaction analysis
|
|
transactions = []
|
|
total_transaction_value = 0.0
|
|
net_insider_activity = 0.0
|
|
top_insiders = []
|
|
transaction_summary = {}
|
|
analysis_summary = f"Insider transaction analysis for {symbol}"
|
|
|
|
metadata = {
|
|
"data_quality": DataQuality.HIGH if transactions else DataQuality.LOW,
|
|
"service": "insider_data",
|
|
"data_source": "placeholder",
|
|
"analysis_method": "insider_transactions",
|
|
}
|
|
|
|
return InsiderTransactionContext(
|
|
symbol=symbol,
|
|
period={"start": start_date, "end": end_date},
|
|
transactions=transactions,
|
|
total_transaction_value=total_transaction_value,
|
|
net_insider_activity=net_insider_activity,
|
|
top_insiders=top_insiders,
|
|
transaction_summary=transaction_summary,
|
|
analysis_summary=analysis_summary,
|
|
metadata=metadata,
|
|
)
|
|
|
|
def update_insider_sentiment(
|
|
self,
|
|
symbol: str,
|
|
start_date: str,
|
|
end_date: str,
|
|
):
|
|
pass # TODO: fetch insider sentiment with finnhub client, save with repo
|
|
|
|
def update_insider_transactions(
|
|
self,
|
|
symbol: str,
|
|
start_date: str,
|
|
end_date: str,
|
|
):
|
|
pass # TODO: fetch insider transactions with finnhub client, save with repo
|