1
This commit is contained in:
parent
4490072d66
commit
f8f1b3eaae
@ -31,7 +31,7 @@ class MarketAnalysisEngine:
|
|||||||
"""
|
"""
|
||||||
self.symbol = symbol or config.SYMBOL
|
self.symbol = symbol or config.SYMBOL
|
||||||
self.data_reader = MarketDataReader(symbol=self.symbol)
|
self.data_reader = MarketDataReader(symbol=self.symbol)
|
||||||
self.llm_builder = LLMContextBuilder()
|
self.llm_builder = LLMContextBuilder(symbol=self.symbol)
|
||||||
|
|
||||||
def analyze_current_market(
|
def analyze_current_market(
|
||||||
self, timeframe: str = '5m', symbol: str = None
|
self, timeframe: str = '5m', symbol: str = None
|
||||||
@ -135,20 +135,22 @@ class MarketAnalysisEngine:
|
|||||||
logger.error(f"Error in market analysis: {e}", exc_info=True)
|
logger.error(f"Error in market analysis: {e}", exc_info=True)
|
||||||
return {'error': str(e)}
|
return {'error': str(e)}
|
||||||
|
|
||||||
def get_llm_context(self, format: str = 'full') -> Dict[str, Any]:
|
def get_llm_context(self, format: str = 'full', symbol: str = None) -> Dict[str, Any]:
|
||||||
"""
|
"""
|
||||||
Get market context formatted for LLM consumption
|
Get market context formatted for LLM consumption
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
format: 'full' or 'simplified'
|
format: 'full' or 'simplified'
|
||||||
|
symbol: Trading symbol (uses engine's symbol if None)
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
LLM-ready context dictionary
|
LLM-ready context dictionary
|
||||||
"""
|
"""
|
||||||
|
symbol = symbol or self.symbol
|
||||||
if format == 'simplified':
|
if format == 'simplified':
|
||||||
return self.llm_builder.get_simplified_context()
|
return self.llm_builder.get_simplified_context()
|
||||||
else:
|
else:
|
||||||
return self.llm_builder.build_full_context()
|
return self.llm_builder.build_full_context(symbol=symbol)
|
||||||
|
|
||||||
def get_multi_timeframe_analysis(self) -> Dict[str, Any]:
|
def get_multi_timeframe_analysis(self) -> Dict[str, Any]:
|
||||||
"""
|
"""
|
||||||
|
|||||||
@ -35,22 +35,26 @@ KLINE_LIMITS = {
|
|||||||
class LLMContextBuilder:
|
class LLMContextBuilder:
|
||||||
"""Build structured context for LLM trading decisions"""
|
"""Build structured context for LLM trading decisions"""
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self, symbol: str = "BTCUSDT"):
|
||||||
self.data_reader = MarketDataReader()
|
self.symbol = symbol
|
||||||
|
self.data_reader = MarketDataReader(symbol=symbol)
|
||||||
|
|
||||||
def build_full_context(self, symbol: str = "BTCUSDT") -> Dict[str, Any]:
|
def build_full_context(self, symbol: str = None) -> Dict[str, Any]:
|
||||||
"""
|
"""
|
||||||
Build complete market context for LLM analysis
|
Build complete market context for LLM analysis
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
symbol: Trading symbol (default: BTCUSDT)
|
symbol: Trading symbol (uses instance symbol if None)
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
Dict with structured market analysis
|
Dict with structured market analysis
|
||||||
"""
|
"""
|
||||||
|
# Use passed symbol or fall back to instance symbol
|
||||||
|
symbol = symbol or self.symbol
|
||||||
|
|
||||||
try:
|
try:
|
||||||
# Fetch multi-timeframe data with custom limits
|
# Fetch multi-timeframe data with custom limits
|
||||||
mtf_data = self._get_multi_timeframe_data_for_llm()
|
mtf_data = self._get_multi_timeframe_data_for_llm(symbol)
|
||||||
|
|
||||||
if '5m' not in mtf_data or mtf_data['5m'].empty:
|
if '5m' not in mtf_data or mtf_data['5m'].empty:
|
||||||
logger.error("No 5m data available for analysis")
|
logger.error("No 5m data available for analysis")
|
||||||
@ -90,16 +94,22 @@ class LLMContextBuilder:
|
|||||||
logger.error(f"Error building LLM context: {e}", exc_info=True)
|
logger.error(f"Error building LLM context: {e}", exc_info=True)
|
||||||
return self._empty_context()
|
return self._empty_context()
|
||||||
|
|
||||||
def _get_multi_timeframe_data_for_llm(self) -> Dict[str, pd.DataFrame]:
|
def _get_multi_timeframe_data_for_llm(self, symbol: str = None) -> Dict[str, pd.DataFrame]:
|
||||||
"""
|
"""
|
||||||
Fetch data from multiple timeframes with custom limits for LLM
|
Fetch data from multiple timeframes with custom limits for LLM
|
||||||
|
|
||||||
|
Args:
|
||||||
|
symbol: Trading symbol (uses instance symbol if None)
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
Dict mapping timeframe to DataFrame
|
Dict mapping timeframe to DataFrame
|
||||||
"""
|
"""
|
||||||
|
symbol = symbol or self.symbol
|
||||||
data = {}
|
data = {}
|
||||||
for tf, count in KLINE_LIMITS.items():
|
for tf, count in KLINE_LIMITS.items():
|
||||||
df = self.data_reader.fetch_klines(interval=tf, limit=count)
|
df = self.data_reader.fetch_historical_klines_from_api(
|
||||||
|
symbol=symbol, interval=tf, limit=count
|
||||||
|
)
|
||||||
if not df.empty:
|
if not df.empty:
|
||||||
data[tf] = df
|
data[tf] = df
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user