Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions packages/evaluators/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## 2026-02-21
### Added
- Add `evaluate` to AbstractEvaluator

## [1.10.1] - 2026-01-25
### Added
- Add `current_time` to social evaluator `get_data_cache` method
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,9 @@ async def ohlcv_callback(self, exchange: str, exchange_id: str,
# To be used to trigger an evaluation when a new candle in closed or a re-evaluation is required
pass

async def evaluate(self, cryptocurrency, symbol, time_frame, candle_data=None, candle=None, inc_in_construction_data=False):
raise NotImplementedError("evaluate is not implemented")

async def evaluator_ohlcv_callback(self, exchange: str, exchange_id: str, cryptocurrency: str, symbol: str,
time_frame: str, candle: dict):
if not self.get_is_symbol_wildcard():
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,12 @@ async def evaluator_manual_callback(self, **kwargs):
"""
raise NotImplementedError("evaluator_manual_callback is not implemented")

async def evaluate(self, *args, **kwargs):
"""
Main method that computes evaluation
"""
raise NotImplementedError("evaluate is not implemented for this evaluator")

@staticmethod
def get_eval_type():
"""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,3 +55,6 @@ def _get_tentacle_registration_topic(self, all_symbols_by_crypto_currencies, tim
# by default time frame registration only for the timeframe of this real-time evaluator
return currencies, symbols, to_handle_time_frames


async def evaluate(self, cryptocurrency, symbol, time_frame, time=None):
raise NotImplementedError("evaluate is not implemented")
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,9 @@ def get_data_cache(self, current_time: float, key: typing.Optional[str] = None):
self.logger.exception(e, True, "Can't get data cache: requires OctoBot-Services package installed")
return None

async def evaluate(self, cryptocurrency, symbol, time_frame, current_time=None):
raise NotImplementedError("evaluate is not implemented")

def get_current_exchange_time(self):
try:
import octobot_trading.api as exchange_api
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,8 @@ async def ohlcv_callback(self, exchange: str, exchange_id: str,
try:
self.last_volume = volume_data[-1]
self.last_price = close_data[-1]
await self._trigger_evaluation(cryptocurrency, symbol,
evaluators_util.get_eval_time(full_candle=candle, time_frame=time_frame))
await self.evaluate(cryptocurrency, symbol, time_frame,
time=evaluators_util.get_eval_time(full_candle=candle, time_frame=time_frame))
except IndexError:
# candles data history is probably not yet available
self.logger.debug(f"Impossible to evaluate, no historical data for {symbol} on {time_frame}")
Expand All @@ -98,14 +98,14 @@ async def kline_callback(self, exchange: str, exchange_id: str,
cryptocurrency: str, symbol: str, time_frame, kline):
self.last_volume = kline[commons_enums.PriceIndexes.IND_PRICE_VOL.value]
self.last_price = kline[commons_enums.PriceIndexes.IND_PRICE_CLOSE.value]
await self._trigger_evaluation(cryptocurrency, symbol, evaluators_util.get_eval_time(kline=kline))
await self.evaluate(cryptocurrency, symbol, time_frame, time=evaluators_util.get_eval_time(kline=kline))

async def _trigger_evaluation(self, cryptocurrency, symbol, time):
async def evaluate(self, cryptocurrency, symbol, time_frame, time=None):
self.evaluate_volume_fluctuations()
if self.something_is_happening and self.eval_note != commons_constants.START_PENDING_EVAL_NOTE:
if abs(self.last_notification_eval - self.eval_note) >= self.MIN_TRIGGERING_DELTA:
self.last_notification_eval = self.eval_note
await self.evaluation_completed(cryptocurrency, symbol, self.available_time_frame,
await self.evaluation_completed(cryptocurrency, symbol, time_frame,
eval_time=time)
self.something_is_happening = False
else:
Expand Down Expand Up @@ -221,20 +221,20 @@ async def ohlcv_callback(self, exchange: str, exchange_id: str,
if len(self.last_candle_data[symbol]) > self.period:
self.last_moving_average_values[symbol] = tulipy.sma(self.last_candle_data[symbol],
self.period)
await self._evaluate_current_price(self.last_candle_data[symbol][-1], cryptocurrency, symbol,
evaluators_util.get_eval_time(full_candle=candle,
time_frame=time_frame))
self._current_price = self.last_candle_data[symbol][-1]
await self.evaluate(cryptocurrency, symbol, time_frame, time=evaluators_util.get_eval_time(full_candle=candle, time_frame=time_frame))

async def kline_callback(self, exchange: str, exchange_id: str,
cryptocurrency: str, symbol: str, time_frame, kline):
if symbol in self.last_moving_average_values and len(self.last_moving_average_values[symbol]) > 0:
self.eval_note = 0
last_price = kline[commons_enums.PriceIndexes.IND_PRICE_CLOSE.value]
if last_price != self.last_candle_data[symbol][-1]:
await self._evaluate_current_price(last_price, cryptocurrency, symbol,
evaluators_util.get_eval_time(kline=kline))
self._current_price = last_price
await self.evaluate(cryptocurrency, symbol, time_frame, time=evaluators_util.get_eval_time(kline=kline))

async def _evaluate_current_price(self, last_price, cryptocurrency, symbol, time):
async def evaluate(self, cryptocurrency, symbol, time_frame, time=None):
last_price = self._current_price or 0
last_ma_value = self.last_moving_average_values[symbol][-1]
if last_ma_value == 0:
self.eval_note = 0
Expand Down
45 changes: 25 additions & 20 deletions packages/tentacles/Evaluator/Social/news_evaluator/news.py
Original file line number Diff line number Diff line change
Expand Up @@ -217,26 +217,31 @@ def get_is_cryptocurrency_name_wildcard(cls) -> bool:

async def _feed_callback(self, data):
if self._is_interested_by_this_notification(data[services_constants.FEED_METADATA]):
latest_news = self.get_data_cache(self.get_current_exchange_time(), key=services_constants.COINDESK_TOPIC_NEWS)
if latest_news is not None and len(latest_news) > 0:
sentiment_sum = 0
news_count = 0
news_titles = []
for news in latest_news:
sentiment = news.sentiment
sentiment_sum += 0 if sentiment is None else -1 if sentiment == "NEGATIVE" else 1 if sentiment == "POSITIVE" else 0
news_count += 1
news_titles.append(news.title)

if news_count > 0:
self.eval_note = sentiment_sum / news_count
await self.evaluation_completed(
cryptocurrency=None,
eval_time=self.get_current_exchange_time(),
eval_note_description=f"Overall news sentiment: {'POSITIVE' if self.eval_note > 0 else 'NEGATIVE' if self.eval_note < 0 else 'NEUTRAL'}. News titles: " + "; ".join(news_titles)
)
else:
self.debug(f"No news found")
await self.evaluate(None, None, None, current_time=self.get_current_exchange_time())

async def evaluate(self, cryptocurrency, symbol, time_frame, current_time=None):
if current_time is None:
current_time = self.get_current_exchange_time()
latest_news = self.get_data_cache(current_time, key=services_constants.COINDESK_TOPIC_NEWS)
if latest_news is not None and len(latest_news) > 0:
sentiment_sum = 0
news_count = 0
news_titles = []
for news in latest_news:
sentiment = news.sentiment
sentiment_sum += 0 if sentiment is None else -1 if sentiment == "NEGATIVE" else 1 if sentiment == "POSITIVE" else 0
news_count += 1
news_titles.append(news.title)

if news_count > 0:
self.eval_note = sentiment_sum / news_count
await self.evaluation_completed(
cryptocurrency=None,
eval_time=self.get_current_exchange_time(),
eval_note_description=f"Overall news sentiment: {'POSITIVE' if self.eval_note > 0 else 'NEGATIVE' if self.eval_note < 0 else 'NEUTRAL'}. News titles: " + "; ".join(news_titles)
)
else:
self.debug(f"No news found")

def _is_interested_by_this_notification(self, notification_description):
return notification_description == services_constants.COINDESK_TOPIC_NEWS
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,13 +56,20 @@ def get_is_cryptocurrency_name_wildcard(cls) -> bool:

async def _feed_callback(self, data):
if self._is_interested_by_this_notification(data[services_constants.FEED_METADATA]):
fear_and_greed_history = self.get_data_cache(self.get_current_exchange_time(), key=services_constants.ALTERNATIVE_ME_TOPIC_FEAR_AND_GREED)
if fear_and_greed_history is not None and len(fear_and_greed_history) > 0:
fear_and_greed_history_values = [item.value for item in fear_and_greed_history]
self.eval_note = self.stats_analyser.get_trend(fear_and_greed_history_values, self.trend_averages)
await self.evaluation_completed(cryptocurrency=None,
eval_time=self.get_current_exchange_time(),
eval_note_description="Latest values: " + ", ".join([str(v) for v in fear_and_greed_history_values[-5:]]))
await self.evaluate(None, None, None, current_time=self.get_current_exchange_time())

async def evaluate(self, cryptocurrency, symbol, time_frame, current_time=None):
if current_time is None:
current_time = self.get_current_exchange_time()
fear_and_greed_history = self.get_data_cache(current_time, key=services_constants.ALTERNATIVE_ME_TOPIC_FEAR_AND_GREED)
if fear_and_greed_history is not None and len(fear_and_greed_history) > 0:
fear_and_greed_history_values = [item.value for item in fear_and_greed_history]
if self.stats_analyser is None:
await self.prepare()
self.eval_note = self.stats_analyser.get_trend(fear_and_greed_history_values, self.trend_averages)
await self.evaluation_completed(cryptocurrency=None,
eval_time=self.get_current_exchange_time(),
eval_note_description="Latest values: " + ", ".join([str(v) for v in fear_and_greed_history_values[-5:]]))

def _is_interested_by_this_notification(self, notification_description):
return notification_description == services_constants.ALTERNATIVE_ME_TOPIC_FEAR_AND_GREED
Expand Down Expand Up @@ -98,11 +105,15 @@ def get_is_cryptocurrency_name_wildcard(cls) -> bool:

async def _feed_callback(self, data):
if self._is_interested_by_this_notification(data[services_constants.FEED_METADATA]):
coin, _ = data[services_constants.FEED_METADATA].split(";")
coin_data = self.get_data_cache(self.get_current_exchange_time(), key=f"{coin};{services_constants.LUNARCRUSH_COIN_METRICS}")
if coin_data is not None and len(coin_data) > 0:
self.eval_note = coin_data[-1].sentiment
await self.evaluation_completed(cryptocurrency=self.cryptocurrency, eval_time=self.get_current_exchange_time())
await self.evaluate(self.cryptocurrency, None, None, current_time=self.get_current_exchange_time())

async def evaluate(self, cryptocurrency, symbol, time_frame, current_time=None):
if current_time is None:
current_time = self.get_current_exchange_time()
coin_data = self.get_data_cache(current_time, key=f"{self.cryptocurrency};{services_constants.LUNARCRUSH_COIN_METRICS}")
if coin_data is not None and len(coin_data) > 0:
self.eval_note = coin_data[-1].sentiment
await self.evaluation_completed(cryptocurrency=self.cryptocurrency, eval_time=self.get_current_exchange_time())

def _is_interested_by_this_notification(self, notification_description):
try:
Expand Down
21 changes: 14 additions & 7 deletions packages/tentacles/Evaluator/Social/trends_evaluator/trends.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,13 +116,20 @@ def get_is_cryptocurrency_name_wildcard(cls) -> bool:

async def _feed_callback(self, data):
if self._is_interested_by_this_notification(data[services_constants.FEED_METADATA]):
marketcap_data = self.get_data_cache(self.get_current_exchange_time(), key=services_constants.COINDESK_TOPIC_MARKETCAP)
if marketcap_data is not None and len(marketcap_data) > 0:
marketcap_history = [item.close for item in marketcap_data]
self.eval_note = self.stats_analyser.get_trend(marketcap_history, self.trend_averages)
await self.evaluation_completed(cryptocurrency=None,
eval_time=self.get_current_exchange_time(),
eval_note_description="Latest market cap values: " + ", ".join([str(v) for v in marketcap_history[-5:]]))
await self.evaluate(None, None, None, current_time=self.get_current_exchange_time())

async def evaluate(self, cryptocurrency, symbol, time_frame, current_time=None):
if current_time is None:
current_time = self.get_current_exchange_time()
marketcap_data = self.get_data_cache(current_time, key=services_constants.COINDESK_TOPIC_MARKETCAP)
if marketcap_data is not None and len(marketcap_data) > 0:
marketcap_history = [item.close for item in marketcap_data]
if self.stats_analyser is None:
await self.prepare()
self.eval_note = self.stats_analyser.get_trend(marketcap_history, self.trend_averages)
await self.evaluation_completed(cryptocurrency=None,
eval_time=self.get_current_exchange_time(),
eval_note_description="Latest market cap values: " + ", ".join([str(v) for v in marketcap_history[-5:]]))

def _is_interested_by_this_notification(self, notification_description):
return notification_description == services_constants.COINDESK_TOPIC_MARKETCAP
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -153,12 +153,6 @@ async def _run_agents_analysis(
missing_data_types: list,
ai_service,
) -> tuple[float | str, str]:
"""
Run strategy agents on aggregated data using the SimpleAIEvaluatorAgentsTeam.

Returns:
Tuple of (eval_note, eval_note_description).
"""
# Determine which agents to include based on available data
include_ta = evaluators_enums.EvaluatorMatrixTypes.TA.value in aggregated_data
include_sentiment = evaluators_enums.EvaluatorMatrixTypes.SOCIAL.value in aggregated_data
Expand Down Expand Up @@ -389,6 +383,9 @@ async def _evaluate_for_cryptocurrency(
else:
missing_data_types.append(eval_type)

await self.evaluate(aggregated_data, missing_data_types, cryptocurrency)

async def evaluate(self, aggregated_data, missing_data_types, cryptocurrency):
if not aggregated_data:
return

Expand Down Expand Up @@ -432,12 +429,10 @@ async def _evaluate_for_cryptocurrency(


class GlobalLLMAIStrategyEvaluator(BaseLLMAIStrategyEvaluator):

def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self._is_evaluating = False


@classmethod
def get_is_cryptocurrencies_wildcard(cls) -> bool:
"""
Expand Down Expand Up @@ -502,6 +497,9 @@ async def _evaluate_global(
else:
missing_data_types.append(eval_type)

await self.evaluate(aggregated_data, missing_data_types)

async def evaluate(self, aggregated_data, missing_data_types):
if not aggregated_data:
return

Expand Down
8 changes: 5 additions & 3 deletions packages/tentacles/Evaluator/TA/ai_evaluator/ai.py
Original file line number Diff line number Diff line change
Expand Up @@ -176,10 +176,12 @@ async def _init_registered_topics(self, all_symbols_by_crypto_currencies, curren

async def ohlcv_callback(self, exchange: str, exchange_id: str,
cryptocurrency: str, symbol: str, time_frame, candle, inc_in_construction_data):
candle_data = self.get_candles_data(exchange, exchange_id, symbol, time_frame, inc_in_construction_data)
await self.evaluate(cryptocurrency, symbol, time_frame, candle_data, candle)
await self.evaluate(cryptocurrency, symbol, time_frame, candle=candle, inc_in_construction_data=inc_in_construction_data)

async def evaluate(self, cryptocurrency, symbol, time_frame, candle_data, candle):
async def evaluate(self, cryptocurrency, symbol, time_frame, candle_data=None, candle=None, inc_in_construction_data=False):
if candle_data is None:
exchange_id = trading_api.get_exchange_id_from_matrix_id(self.exchange_name, self.matrix_id)
candle_data = self.get_candles_data(self.exchange_name, exchange_id, symbol, time_frame, inc_in_construction_data)
async with self.async_evaluation():
self.eval_note = commons_constants.START_PENDING_EVAL_NOTE
if self._check_timeframe(time_frame):
Expand Down
Loading
Loading