Skip to content

Commit

Permalink
Merge pull request #1244 from mraniki/dev
Browse files Browse the repository at this point in the history
⬆️ 🤖 - Q	Whats a lightyear
  • Loading branch information
mraniki authored Feb 11, 2024
2 parents 94a4d42 + 259505d commit 14ff964
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 7 deletions.
2 changes: 1 addition & 1 deletion tt/plugins/default_plugins/cex_exchange_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion tt/plugins/default_plugins/dex_exchange_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
39 changes: 35 additions & 4 deletions tt/plugins/plugin_manager.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import asyncio
import importlib
import pkgutil
from datetime import datetime

from asyncz.triggers import CronTrigger, IntervalTrigger

Expand Down Expand Up @@ -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
Expand All @@ -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,
Expand All @@ -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
21 changes: 20 additions & 1 deletion tt/talky_settings.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 ###
Expand Down Expand Up @@ -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 ###
########################################
Expand Down Expand Up @@ -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 ###
########################################
Expand Down

0 comments on commit 14ff964

Please sign in to comment.