diff --git a/tt/plugins/default_plugins/cex_exchange_plugin.py b/tt/plugins/default_plugins/cex_exchange_plugin.py index c546e75b3..ffbdd633f 100644 --- a/tt/plugins/default_plugins/cex_exchange_plugin.py +++ b/tt/plugins/default_plugins/cex_exchange_plugin.py @@ -62,7 +62,7 @@ async def handle_message(self, msg): return logger.debug("settings.bot_ignore: {}", settings.bot_ignore) if settings.bot_ignore not in msg or settings.bot_prefix not in msg: - if await self.fmo.search(msg): + if await self.fmo.search(msg) and self.should_handle_timeframe(): order = await self.fmo.get_order(msg) if order and settings.trading_enabled: trade = await self.exchange.submit_order(order) diff --git a/tt/plugins/default_plugins/dex_exchange_plugin.py b/tt/plugins/default_plugins/dex_exchange_plugin.py index 5ee2f0ae8..ce6849d18 100644 --- a/tt/plugins/default_plugins/dex_exchange_plugin.py +++ b/tt/plugins/default_plugins/dex_exchange_plugin.py @@ -53,7 +53,7 @@ async def handle_message(self, msg): return if settings.bot_ignore not in msg or settings.bot_prefix not in msg: - if await self.fmo.search(msg): + if await self.fmo.search(msg) and self.should_handle_timeframe(): order = await self.fmo.get_order(msg) if order and settings.trading_enabled: trade = await self.exchange.submit_order(order) diff --git a/tt/plugins/plugin_manager.py b/tt/plugins/plugin_manager.py index 27fccb4b8..e26759c83 100644 --- a/tt/plugins/plugin_manager.py +++ b/tt/plugins/plugin_manager.py @@ -1,6 +1,7 @@ import asyncio import importlib import pkgutil +from datetime import datetime from asyncz.triggers import CronTrigger, IntervalTrigger @@ -216,17 +217,18 @@ async def plugin_notify_schedule_task( async def plugin_notify_cron_task( self, user_name=None, - user_day_of_week="mon-fri", - user_hours="4,10,16", - user_timezone="UTC", + user_day_of_week=None, + user_hours=None, + user_timezone=None, function=None, ): """ Handles task cron scheduling for notification default set to - Monday to Friday + Tuesday to Thursday at 6AM, 12PM and 6PM UTC + via settings Args: user_name (str): User name @@ -239,6 +241,13 @@ async def plugin_notify_cron_task( None """ + if not user_day_of_week: + user_day_of_week = settings.user_day_of_week + if not user_hours: + user_hours = settings.user_hours + if not user_timezone: + user_timezone = settings.user_timezone + if function: self.scheduler.add_task( name=user_name, @@ -265,3 +274,25 @@ async def handle_message(self, msg): # if command in command_mapping: # function = command_mapping[command] # await self.send_notification(f"{await function()}") + + def should_handle_timeframe(): + """ + Returns True if the current day and time + are within the configured trading window. + + Returns: + bool + """ + if settings.trading_control: + current_time = datetime.now().time() + current_day = datetime.now().strftime("%a").lower() + + start_time = datetime.strptime(settings.trading_hours_start, "%H:%M").time() + end_time = datetime.strptime(settings.trading_hours_end, "%H:%M").time() + + return ( + current_day in settings.trading_days_allowed + and start_time <= current_time <= end_time + ) + + return True diff --git a/tt/talky_settings.toml b/tt/talky_settings.toml index bb236478a..4c9964e8d 100644 --- a/tt/talky_settings.toml +++ b/tt/talky_settings.toml @@ -164,6 +164,10 @@ helper_commands = """ # Enable/Disable Trading trading_enabled = true +trading_control = false +trading_days_allowed = ["tue", "wed", "thu"] +trading_hours_start = "08:00" +trading_hours_end = "16:00" ######################################## ### FINDMYORDER SETTINGS ### @@ -239,7 +243,12 @@ example_plugin_enabled = false # Not yet implemented # user_plugins_allowed = true user_plugins_allowed = false - + +# plugin cron scheduler +user_day_of_week="tue-thu" +user_hours="6,12,18" +user_timezone="UTC" + ######################################## ### HELPER SETTINGS ### ######################################## @@ -303,6 +312,16 @@ enable_feed = true # Feeds RSS url news_feed = "https://www.dailyfx.com/feeds/market-news" +# Finnhub news fetcher +enable_finnhub = false +finnhub_api_key = "" +finnhub_news_category = "forex" + +# web scraper +enable_scraper = false +market_page_url = "" +market_page_id = "" + ######################################## ### CEFI SETTINGS ### ########################################