AiDataTaskRuner/Backend/Tlgm/Tools/Tools.mqh

636 lines
26 KiB
MQL5
Raw Permalink Normal View History

2026-03-18 12:10:52 -05:00
//+------------------------------------------------------------------+
//| Tools.mqh |
//| Copyright 2025, Niquel Mendoza. |
//| https://www.mql5.com/es/users/nique_372 |
//+------------------------------------------------------------------+
#property copyright "Copyright 2025, Niquel Mendoza."
#property link "https://www.mql5.com/es/users/nique_372"
#property strict
#ifndef AIDATATASKRUNNER_BACKEND_TLGM_TOOLS_TOOLS_MQH
#define AIDATATASKRUNNER_BACKEND_TLGM_TOOLS_TOOLS_MQH
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
//--- Reciber
2026-04-25 18:03:47 -05:00
#include <TSN\\AiFullTab\\TlgReciber.mqh>
2026-07-13 10:55:30 -05:00
#include <TSN\\MQLArticles\\Utils\\EnumReg.mqh>
2026-03-18 12:10:52 -05:00
//--- Protocolo de comunicacion con telegram
#include "..\\Protocol\\Def.mqh"
2026-07-13 16:01:06 -05:00
//--- Extra tools
#include <TSN\\LLMBTools\\Main.mqh>
2026-07-13 10:55:30 -05:00
//+------------------------------------------------------------------+
//| Generador de id interno (correlacion con ChartEvent, no con el |
//| id de tool_call del LLM: Run() es sincrono y ya no lo recibe) |
//+------------------------------------------------------------------+
namespace TSN
2026-06-03 22:07:50 -05:00
{
2026-07-13 10:55:30 -05:00
//---
static int g_aitaskrunner_tool_counter = 0;
//---
#define AiTaskRunnerGenId(name) StringFormat("tlg_aitaskruner_%s_%d", name, ++g_aitaskrunner_tool_counter)
2026-03-18 12:10:52 -05:00
//+------------------------------------------------------------------+
2026-07-13 10:55:30 -05:00
//| name: aidatataskrunner_get_task_total |
//| desc: Returns the total number of tasks in the table |
//| params: none |
2026-03-18 12:10:52 -05:00
//+------------------------------------------------------------------+
2026-07-13 10:55:30 -05:00
class CAiTaskRunnerToolGetTaskTotal : public CLLmTool
2026-03-18 12:10:52 -05:00
{
private:
2026-04-01 13:21:12 -05:00
const long m_panel_chart_id;
2026-03-18 12:10:52 -05:00
const long m_bot_chart_id;
public:
2026-04-01 13:21:12 -05:00
CAiTaskRunnerToolGetTaskTotal(const long panel_chart_id, const long bot_chart_id)
2026-07-13 10:55:30 -05:00
: CLLmTool("aidatataskrunner_get_task_total"),
2026-04-01 13:21:12 -05:00
m_panel_chart_id(panel_chart_id), m_bot_chart_id(bot_chart_id)
2026-07-13 10:55:30 -05:00
{}
2026-03-18 12:10:52 -05:00
~CAiTaskRunnerToolGetTaskTotal() {}
//---
2026-07-15 12:35:26 -05:00
void Run(CJsonNode &param, CJsonBuilderStr* &out) override final
2026-03-18 12:10:52 -05:00
{
2026-07-15 12:35:26 -05:00
out = m_shared_builder;
2026-07-13 10:55:30 -05:00
const string id = AiTaskRunnerGenId(m_name);
2026-07-15 12:35:26 -05:00
m_shared_builder.PutChar('"');
m_shared_builder.Obj();
2026-04-01 13:21:12 -05:00
if(!::EventChartCustom(m_panel_chart_id, AIDATATASKRUNER_API_ON_PARAM_CHANGE,
m_bot_chart_id, double(AIDATATASKRUNER_API_TASK_TOTAL),
AiDataTaskRunnerEmpaquetar(id, "")))
2026-07-13 10:55:30 -05:00
{
2026-07-15 12:35:26 -05:00
m_shared_builder.KeyWV("ok").Val(false);
m_shared_builder.KeyWV("error").ValS("Failed to dispatch get_task_total");
2026-07-13 10:55:30 -05:00
}
2026-07-15 12:35:26 -05:00
else
{
m_shared_builder.KeyWV("ok").Val(true);
m_shared_builder.KeyWV("result").ValS("Queued | Result will appear in chat");
}
m_shared_builder.EndObj();
m_shared_builder.PutChar('"');
2026-03-18 12:10:52 -05:00
}
};
//+------------------------------------------------------------------+
2026-07-13 10:55:30 -05:00
//| name: aidatataskrunner_clean_all_tasks |
//| desc: Cleans all tasks from the table that are not running or |
//| queued |
//| params: none |
2026-03-18 12:10:52 -05:00
//+------------------------------------------------------------------+
2026-07-13 10:55:30 -05:00
class CAiTaskRunnerToolCleanAllTasks : public CLLmTool
2026-03-18 12:10:52 -05:00
{
private:
2026-04-01 13:21:12 -05:00
const long m_panel_chart_id;
2026-03-18 12:10:52 -05:00
const long m_bot_chart_id;
public:
2026-04-01 13:21:12 -05:00
CAiTaskRunnerToolCleanAllTasks(const long panel_chart_id, const long bot_chart_id)
2026-07-13 10:55:30 -05:00
: CLLmTool("aidatataskrunner_clean_all_tasks"),
2026-04-01 13:21:12 -05:00
m_panel_chart_id(panel_chart_id), m_bot_chart_id(bot_chart_id)
2026-07-13 10:55:30 -05:00
{}
2026-03-18 12:10:52 -05:00
~CAiTaskRunnerToolCleanAllTasks() {}
//---
2026-07-15 12:35:26 -05:00
void Run(CJsonNode &param, CJsonBuilderStr* &out) override final
2026-03-18 12:10:52 -05:00
{
2026-07-15 12:35:26 -05:00
out = m_shared_builder;
2026-07-13 10:55:30 -05:00
const string id = AiTaskRunnerGenId(m_name);
2026-07-15 12:35:26 -05:00
m_shared_builder.PutChar('"');
m_shared_builder.Obj();
2026-04-01 13:21:12 -05:00
if(!::EventChartCustom(m_panel_chart_id, AIDATATASKRUNER_API_ON_PARAM_CHANGE,
m_bot_chart_id, double(AIDATATASKRUNER_API_CLEAN_ALL_TASK_OF_TABLE),
AiDataTaskRunnerEmpaquetar(id, "")))
2026-07-13 10:55:30 -05:00
{
2026-07-15 12:35:26 -05:00
m_shared_builder.KeyWV("ok").Val(false);
m_shared_builder.KeyWV("error").ValS("Failed to dispatch clean_all_tasks");
}
else
{
m_shared_builder.KeyWV("ok").Val(true);
m_shared_builder.KeyWV("result").ValS("Queued | Cleaning tasks, result will appear in chat");
2026-07-13 10:55:30 -05:00
}
2026-07-15 12:35:26 -05:00
m_shared_builder.EndObj();
m_shared_builder.PutChar('"');
2026-03-18 12:10:52 -05:00
}
};
//+------------------------------------------------------------------+
2026-07-13 10:55:30 -05:00
//| name: aidatataskrunner_execute_all_tasks |
//| desc: Executes all pending tasks in the table |
//| params: none |
2026-03-18 12:10:52 -05:00
//+------------------------------------------------------------------+
2026-07-13 10:55:30 -05:00
class CAiTaskRunnerToolExecuteAllTasks : public CLLmTool
2026-03-18 12:10:52 -05:00
{
private:
2026-04-01 13:21:12 -05:00
const long m_panel_chart_id;
2026-03-18 12:10:52 -05:00
const long m_bot_chart_id;
public:
2026-04-01 13:21:12 -05:00
CAiTaskRunnerToolExecuteAllTasks(const long panel_chart_id, const long bot_chart_id)
2026-07-13 10:55:30 -05:00
: CLLmTool("aidatataskrunner_execute_all_tasks"),
2026-04-01 13:21:12 -05:00
m_panel_chart_id(panel_chart_id), m_bot_chart_id(bot_chart_id)
2026-07-13 10:55:30 -05:00
{}
2026-03-18 12:10:52 -05:00
~CAiTaskRunnerToolExecuteAllTasks() {}
//---
2026-07-15 12:35:26 -05:00
void Run(CJsonNode &param, CJsonBuilderStr* &out) override final
2026-03-18 12:10:52 -05:00
{
2026-07-15 12:35:26 -05:00
out = m_shared_builder;
2026-07-13 10:55:30 -05:00
const string id = AiTaskRunnerGenId(m_name);
2026-07-15 12:35:26 -05:00
m_shared_builder.PutChar('"');
m_shared_builder.Obj();
2026-04-01 13:21:12 -05:00
if(!::EventChartCustom(m_panel_chart_id, AIDATATASKRUNER_API_ON_PARAM_CHANGE,
m_bot_chart_id, double(AIDATATASKRUNER_API_EXECUTE_ALL_TASK_OF_TABLE),
AiDataTaskRunnerEmpaquetar(id, "")))
2026-07-13 10:55:30 -05:00
{
2026-07-15 12:35:26 -05:00
m_shared_builder.KeyWV("ok").Val(false);
m_shared_builder.KeyWV("error").ValS("Failed to dispatch execute_all_tasks");
2026-07-13 10:55:30 -05:00
}
2026-07-15 12:35:26 -05:00
else
{
m_shared_builder.KeyWV("ok").Val(true);
m_shared_builder.KeyWV("result").ValS("Queued | Executing all tasks, result will appear in chat");
}
m_shared_builder.EndObj();
m_shared_builder.PutChar('"');
2026-03-18 12:10:52 -05:00
}
};
//+------------------------------------------------------------------+
2026-07-13 10:55:30 -05:00
//| name: aidatataskrunner_get_main_folder |
//| desc: Returns the main base folder path used by AiDataTaskRunner |
//| params: none |
2026-03-18 12:10:52 -05:00
//+------------------------------------------------------------------+
2026-07-13 10:55:30 -05:00
class CAiTaskRunnerToolGetMainFolder : public CLLmTool
2026-03-18 12:10:52 -05:00
{
private:
2026-04-01 13:21:12 -05:00
const long m_panel_chart_id;
2026-03-18 12:10:52 -05:00
const long m_bot_chart_id;
public:
2026-04-01 13:21:12 -05:00
CAiTaskRunnerToolGetMainFolder(const long panel_chart_id, const long bot_chart_id)
2026-07-13 10:55:30 -05:00
: CLLmTool("aidatataskrunner_get_main_folder"),
2026-04-01 13:21:12 -05:00
m_panel_chart_id(panel_chart_id), m_bot_chart_id(bot_chart_id)
2026-07-13 10:55:30 -05:00
{}
2026-03-18 12:10:52 -05:00
~CAiTaskRunnerToolGetMainFolder() {}
//---
2026-07-15 12:35:26 -05:00
void Run(CJsonNode &param, CJsonBuilderStr* &out) override final
2026-03-18 12:10:52 -05:00
{
2026-07-15 12:35:26 -05:00
out = m_shared_builder;
2026-07-13 10:55:30 -05:00
const string id = AiTaskRunnerGenId(m_name);
2026-07-15 12:35:26 -05:00
m_shared_builder.PutChar('"');
m_shared_builder.Obj();
2026-04-01 13:21:12 -05:00
if(!::EventChartCustom(m_panel_chart_id, AIDATATASKRUNER_API_ON_PARAM_CHANGE,
m_bot_chart_id, double(AIDATATASKRUNER_API_MAIN_FOLDER),
AiDataTaskRunnerEmpaquetar(id, "")))
2026-07-13 10:55:30 -05:00
{
2026-07-15 12:35:26 -05:00
m_shared_builder.KeyWV("ok").Val(false);
m_shared_builder.KeyWV("error").ValS("Failed to dispatch get_main_folder");
}
else
{
m_shared_builder.KeyWV("ok").Val(true);
m_shared_builder.KeyWV("result").ValS("Queued | Result will appear in chat");
2026-07-13 10:55:30 -05:00
}
2026-07-15 12:35:26 -05:00
m_shared_builder.EndObj();
m_shared_builder.PutChar('"');
2026-03-18 12:10:52 -05:00
}
};
//+------------------------------------------------------------------+
2026-07-13 10:55:30 -05:00
//| name: aidatataskrunner_get_task_folder |
//| desc: Returns the tasks folder path used by AiDataTaskRunner |
//| params: none |
2026-03-18 12:10:52 -05:00
//+------------------------------------------------------------------+
2026-07-13 10:55:30 -05:00
class CAiTaskRunnerToolGetTaskFolder : public CLLmTool
2026-03-18 12:10:52 -05:00
{
private:
2026-04-01 13:21:12 -05:00
const long m_panel_chart_id;
2026-03-18 12:10:52 -05:00
const long m_bot_chart_id;
public:
2026-04-01 13:21:12 -05:00
CAiTaskRunnerToolGetTaskFolder(const long panel_chart_id, const long bot_chart_id)
2026-07-13 10:55:30 -05:00
: CLLmTool("aidatataskrunner_get_task_folder"),
2026-04-01 13:21:12 -05:00
m_panel_chart_id(panel_chart_id), m_bot_chart_id(bot_chart_id)
2026-07-13 10:55:30 -05:00
{}
2026-03-18 12:10:52 -05:00
~CAiTaskRunnerToolGetTaskFolder() {}
//---
2026-07-15 12:35:26 -05:00
void Run(CJsonNode &param, CJsonBuilderStr* &out) override final
2026-03-18 12:10:52 -05:00
{
2026-07-15 12:35:26 -05:00
out = m_shared_builder;
2026-07-13 10:55:30 -05:00
const string id = AiTaskRunnerGenId(m_name);
2026-07-15 12:35:26 -05:00
m_shared_builder.PutChar('"');
m_shared_builder.Obj();
2026-04-01 13:21:12 -05:00
if(!::EventChartCustom(m_panel_chart_id, AIDATATASKRUNER_API_ON_PARAM_CHANGE,
m_bot_chart_id, double(AIDATATASKRUNER_API_TASK_FOLDER),
AiDataTaskRunnerEmpaquetar(id, "")))
2026-07-13 10:55:30 -05:00
{
2026-07-15 12:35:26 -05:00
m_shared_builder.KeyWV("ok").Val(false);
m_shared_builder.KeyWV("error").ValS("Failed to dispatch get_task_folder");
2026-07-13 10:55:30 -05:00
}
2026-07-15 12:35:26 -05:00
else
{
m_shared_builder.KeyWV("ok").Val(true);
m_shared_builder.KeyWV("result").ValS("Queued | Result will appear in chat");
}
m_shared_builder.EndObj();
m_shared_builder.PutChar('"');
2026-03-18 12:10:52 -05:00
}
};
//+------------------------------------------------------------------+
2026-07-13 10:55:30 -05:00
//| name: aidatataskrunner_is_in_commonfolder |
//| desc: Returns whether AiDataTaskRunner is using the MT5 common |
//| folder |
//| params: none |
2026-03-18 12:10:52 -05:00
//+------------------------------------------------------------------+
2026-07-13 10:55:30 -05:00
class CAiTaskRunnerToolIsInCommonFolder : public CLLmTool
2026-03-18 12:10:52 -05:00
{
private:
2026-04-01 13:21:12 -05:00
const long m_panel_chart_id;
2026-03-18 12:10:52 -05:00
const long m_bot_chart_id;
public:
2026-04-01 13:21:12 -05:00
CAiTaskRunnerToolIsInCommonFolder(const long panel_chart_id, const long bot_chart_id)
2026-07-13 10:55:30 -05:00
: CLLmTool("aidatataskrunner_is_in_commonfolder"),
2026-04-01 13:21:12 -05:00
m_panel_chart_id(panel_chart_id), m_bot_chart_id(bot_chart_id)
2026-07-13 10:55:30 -05:00
{}
2026-03-18 12:10:52 -05:00
~CAiTaskRunnerToolIsInCommonFolder() {}
//---
2026-07-15 12:35:26 -05:00
void Run(CJsonNode &param, CJsonBuilderStr* &out) override final
2026-03-18 12:10:52 -05:00
{
2026-07-15 12:35:26 -05:00
out = m_shared_builder;
2026-07-13 10:55:30 -05:00
const string id = AiTaskRunnerGenId(m_name);
2026-07-15 12:35:26 -05:00
m_shared_builder.PutChar('"');
m_shared_builder.Obj();
2026-04-01 13:21:12 -05:00
if(!::EventChartCustom(m_panel_chart_id, AIDATATASKRUNER_API_ON_PARAM_CHANGE,
m_bot_chart_id, double(AIDATATASKRUNER_API_IS_IN_COMMON_FOLDER),
AiDataTaskRunnerEmpaquetar(id, "")))
2026-07-13 10:55:30 -05:00
{
2026-07-15 12:35:26 -05:00
m_shared_builder.KeyWV("ok").Val(false);
m_shared_builder.KeyWV("error").ValS("Failed to dispatch is_in_commonfolder");
}
else
{
m_shared_builder.KeyWV("ok").Val(true);
m_shared_builder.KeyWV("result").ValS("Queued | Result will appear in chat");
2026-07-13 10:55:30 -05:00
}
2026-07-15 12:35:26 -05:00
m_shared_builder.EndObj();
m_shared_builder.PutChar('"');
2026-03-18 12:10:52 -05:00
}
};
//+------------------------------------------------------------------+
2026-07-13 10:55:30 -05:00
//| name: aidatataskrunner_add_task |
//| desc: Adds a new backtest task to the AiDataTaskRunner table |
//| params (definir schema en JSON, requeridos: symbol, start_date, |
//| end_date): |
//| symbol string Trading symbol e.g. EURUSD, XAUUSD |
//| start_date string Start date format YYYY.MM.DD HH:MM |
//| end_date string End date format YYYY.MM.DD HH:MM |
//| timeframe string enum: _Period,M1,M2,M3,M4,M5,M6,M10, |
//| M12,M15,M20,M30,H1,H2,H3,H4,H6,H8,H12, |
//| D1,W1,MN1 |
//| set_file string Optional .set file path for EA params |
//| symbol_folder string Optional subfolder name for grouping |
//| label string Optional strategy name (folder prefix) |
//| label_id string Optional variant id, default 0 |
//+------------------------------------------------------------------+
class CAiTaskRunnerToolAddTask : public CLLmTool
2026-03-18 12:10:52 -05:00
{
private:
2026-04-01 13:21:12 -05:00
const long m_panel_chart_id;
2026-03-18 12:10:52 -05:00
const long m_bot_chart_id;
public:
2026-07-13 10:55:30 -05:00
CAiTaskRunnerToolAddTask(const long panel_chart_id, const long bot_chart_id)
: CLLmTool("aidatataskrunner_add_task"),
m_panel_chart_id(panel_chart_id), m_bot_chart_id(bot_chart_id)
{}
2026-03-18 12:10:52 -05:00
~CAiTaskRunnerToolAddTask(void) {}
2026-07-15 12:35:26 -05:00
void Run(CJsonNode &param, CJsonBuilderStr* &out) override final;
2026-03-18 12:10:52 -05:00
};
//+------------------------------------------------------------------+
2026-07-15 12:35:26 -05:00
void CAiTaskRunnerToolAddTask::Run(CJsonNode &param, CJsonBuilderStr* &out)
2026-03-18 12:10:52 -05:00
{
2026-07-15 12:35:26 -05:00
out = m_shared_builder;
2026-07-13 10:55:30 -05:00
const string symbol = param["symbol"].ToString();
const string start_date = param["start_date"].ToString();
const string end_date = param["end_date"].ToString();
const int timeframe = CEnumRegBasis::GetValNoRef<int>(param["timeframe"].ToString("_Period"), _Period);
const string set_file = param["set_file"].ToString("");
const string symbol_folder = param["symbol_folder"].ToString("");
const string label = param["label"].ToString("");
const string label_id = param["label_id"].ToString("0");
2026-03-18 12:10:52 -05:00
//---
/*
//---
__forceinline string ToStringFile()
{
return StringFormat("%d|%s|%s|%s|%s|%s|%s|%d",
int(timeframe), // [0]
symbol, // [1]
set_file, // [2]
TimeToString(start_date), // [3]
TimeToString(end_date), // [4]
symbol_folder, // [5]
label, // [6]
label_id); // [7]
}
*/
//---
const string val = StringFormat("%d|%s|%s|%s|%s|%s|%s|%s",
timeframe, symbol, set_file,
start_date, end_date,
symbol_folder, label, label_id);
//---
2026-07-13 10:55:30 -05:00
const string id = AiTaskRunnerGenId(m_name);
2026-07-15 12:35:26 -05:00
m_shared_builder.PutChar('"');
m_shared_builder.Obj();
2026-04-01 13:21:12 -05:00
if(!::EventChartCustom(m_panel_chart_id, AIDATATASKRUNER_API_ON_PARAM_CHANGE,
m_bot_chart_id, double(AIDATATASKRUNER_API_ADD_TASK_TO_TABLE),
AiDataTaskRunnerEmpaquetar(id, val)))
2026-07-13 10:55:30 -05:00
{
2026-07-15 12:35:26 -05:00
m_shared_builder.KeyWV("ok").Val(false);
m_shared_builder.KeyWV("error").ValS("Failed to dispatch add_task");
2026-07-13 10:55:30 -05:00
}
2026-07-15 12:35:26 -05:00
else
{
m_shared_builder.KeyWV("ok").Val(true);
m_shared_builder.KeyWV("result").ValS("Queued | Task added to table");
}
m_shared_builder.EndObj();
m_shared_builder.PutChar('"');
2026-03-18 12:10:52 -05:00
}
//+------------------------------------------------------------------+
2026-07-13 10:55:30 -05:00
//| name: aidatataskrunner_save_tasks_to_file |
//| desc: Saves all tasks to a CSV file. Can filter to save only |
//| unfinished tasks (pending, queued or in process) |
//| params (requeridos: file_name, only_unfinished): |
//| file_name string Absolute path inside MT5 Files\\ or |
//| Common\\Files\\, extension .csv |
//| only_unfinished boolean If true saves only pending/queued/in- |
//| process tasks, else saves all |
2026-03-18 12:10:52 -05:00
//+------------------------------------------------------------------+
2026-07-13 10:55:30 -05:00
class CAiTaskRunnerToolSaveTasksToFile : public CLLmTool
2026-03-18 12:10:52 -05:00
{
private:
2026-04-01 13:21:12 -05:00
const long m_panel_chart_id;
2026-03-18 12:10:52 -05:00
const long m_bot_chart_id;
public:
2026-07-13 10:55:30 -05:00
CAiTaskRunnerToolSaveTasksToFile(const long panel_chart_id, const long bot_chart_id)
: CLLmTool("aidatataskrunner_save_tasks_to_file"),
m_panel_chart_id(panel_chart_id), m_bot_chart_id(bot_chart_id)
{}
2026-03-18 12:10:52 -05:00
~CAiTaskRunnerToolSaveTasksToFile(void) {}
2026-07-15 12:35:26 -05:00
void Run(CJsonNode &param, CJsonBuilderStr* &out) override final;
2026-03-18 12:10:52 -05:00
};
//+------------------------------------------------------------------+
2026-07-15 12:35:26 -05:00
void CAiTaskRunnerToolSaveTasksToFile::Run(CJsonNode &param, CJsonBuilderStr* &out)
2026-03-18 12:10:52 -05:00
{
2026-07-15 12:35:26 -05:00
out = m_shared_builder;
2026-07-13 10:55:30 -05:00
const string file_name = param["file_name"].ToString();
const bool only_unfinished = param["only_unfinished"].ToBool(false);
2026-03-18 12:10:52 -05:00
//---
const string val = StringFormat("%d|%s", int(only_unfinished), file_name);
//---
2026-07-13 10:55:30 -05:00
const string id = AiTaskRunnerGenId(m_name);
2026-07-15 12:35:26 -05:00
m_shared_builder.PutChar('"');
m_shared_builder.Obj();
2026-04-01 13:21:12 -05:00
if(!::EventChartCustom(m_panel_chart_id, AIDATATASKRUNER_API_ON_PARAM_CHANGE,
m_bot_chart_id, double(AIDATATASKRUNER_API_SAVE_TASK_IN_FILE),
AiDataTaskRunnerEmpaquetar(id, val)))
2026-07-13 10:55:30 -05:00
{
2026-07-15 12:35:26 -05:00
m_shared_builder.KeyWV("ok").Val(false);
m_shared_builder.KeyWV("error").ValS("Failed to dispatch save_tasks_to_file");
2026-07-13 10:55:30 -05:00
}
2026-07-15 12:35:26 -05:00
else
{
m_shared_builder.KeyWV("ok").Val(true);
m_shared_builder.KeyWV("result").ValS("Queued | Saving tasks to file");
}
m_shared_builder.EndObj();
m_shared_builder.PutChar('"');
2026-03-18 12:10:52 -05:00
}
//+------------------------------------------------------------------+
2026-07-13 10:55:30 -05:00
//| name: aidatataskrunner_load_tasks_from_file |
//| desc: Loads tasks from a CSV file into the table |
//| params (requerido: file_name): |
//| file_name string Absolute path inside MT5 Files\\ or |
//| Common\\Files\\, extension .csv |
2026-03-18 12:10:52 -05:00
//+------------------------------------------------------------------+
2026-07-13 10:55:30 -05:00
class CAiTaskRunnerToolLoadTasksFromFile : public CLLmTool
2026-03-18 12:10:52 -05:00
{
private:
2026-04-01 13:21:12 -05:00
const long m_panel_chart_id;
2026-03-18 12:10:52 -05:00
const long m_bot_chart_id;
public:
2026-07-13 10:55:30 -05:00
CAiTaskRunnerToolLoadTasksFromFile(const long panel_chart_id, const long bot_chart_id)
: CLLmTool("aidatataskrunner_load_tasks_from_file"),
m_panel_chart_id(panel_chart_id), m_bot_chart_id(bot_chart_id)
{}
2026-03-18 12:10:52 -05:00
~CAiTaskRunnerToolLoadTasksFromFile(void) {}
2026-07-15 12:35:26 -05:00
void Run(CJsonNode &param, CJsonBuilderStr* &out) override final;
2026-03-18 12:10:52 -05:00
};
//+------------------------------------------------------------------+
2026-07-15 12:35:26 -05:00
void CAiTaskRunnerToolLoadTasksFromFile::Run(CJsonNode &param, CJsonBuilderStr* &out)
2026-03-18 12:10:52 -05:00
{
2026-07-15 12:35:26 -05:00
out = m_shared_builder;
2026-07-13 10:55:30 -05:00
const string file_name = param["file_name"].ToString();
2026-03-18 12:10:52 -05:00
//---
2026-07-13 10:55:30 -05:00
const string id = AiTaskRunnerGenId(m_name);
2026-07-15 12:35:26 -05:00
m_shared_builder.PutChar('"');
m_shared_builder.Obj();
2026-04-01 13:21:12 -05:00
if(!::EventChartCustom(m_panel_chart_id, AIDATATASKRUNER_API_ON_PARAM_CHANGE,
m_bot_chart_id, double(AIDATATASKRUNER_API_LOAD_TASK_IN_FILE),
AiDataTaskRunnerEmpaquetar(id, file_name)))
2026-07-13 10:55:30 -05:00
{
2026-07-15 12:35:26 -05:00
m_shared_builder.KeyWV("ok").Val(false);
m_shared_builder.KeyWV("error").ValS("Failed to dispatch load_tasks_from_file");
2026-07-13 10:55:30 -05:00
}
2026-07-15 12:35:26 -05:00
else
{
m_shared_builder.KeyWV("ok").Val(true);
m_shared_builder.KeyWV("result").ValS("Queued | Loading tasks from file");
}
m_shared_builder.EndObj();
m_shared_builder.PutChar('"');
2026-03-18 12:10:52 -05:00
}
//+------------------------------------------------------------------+
2026-07-13 10:55:30 -05:00
//| name: aidatataskrunner_load_config |
//| desc: Loads the panel configuration from a file |
//| params (requerido: file_name): |
//| file_name string Absolute path inside MT5 Files\\ or |
//| Common\\Files\\, extension .txt |
2026-03-18 12:10:52 -05:00
//+------------------------------------------------------------------+
2026-07-13 10:55:30 -05:00
class CAiTaskRunnerToolLoadConfig : public CLLmTool
2026-03-18 12:10:52 -05:00
{
private:
2026-04-01 13:21:12 -05:00
const long m_panel_chart_id;
2026-03-18 12:10:52 -05:00
const long m_bot_chart_id;
public:
2026-07-13 10:55:30 -05:00
CAiTaskRunnerToolLoadConfig(const long panel_chart_id, const long bot_chart_id)
: CLLmTool("aidatataskrunner_load_config"),
m_panel_chart_id(panel_chart_id), m_bot_chart_id(bot_chart_id)
{}
2026-03-18 12:10:52 -05:00
~CAiTaskRunnerToolLoadConfig(void) {}
2026-07-15 12:35:26 -05:00
void Run(CJsonNode &param, CJsonBuilderStr* &out) override final;
2026-03-18 12:10:52 -05:00
};
//+------------------------------------------------------------------+
2026-07-15 12:35:26 -05:00
void CAiTaskRunnerToolLoadConfig::Run(CJsonNode &param, CJsonBuilderStr* &out)
2026-03-18 12:10:52 -05:00
{
2026-07-15 12:35:26 -05:00
out = m_shared_builder;
2026-07-13 10:55:30 -05:00
const string file_name = param["file_name"].ToString();
2026-03-18 12:10:52 -05:00
//---
2026-07-13 10:55:30 -05:00
const string id = AiTaskRunnerGenId(m_name);
2026-07-15 12:35:26 -05:00
m_shared_builder.PutChar('"');
m_shared_builder.Obj();
2026-04-01 13:21:12 -05:00
if(!::EventChartCustom(m_panel_chart_id, AIDATATASKRUNER_API_ON_PARAM_CHANGE,
m_bot_chart_id, double(AIDATATASKRUNER_API_LOAD_CONFIG_IN_FILE),
AiDataTaskRunnerEmpaquetar(id, file_name)))
2026-07-13 10:55:30 -05:00
{
2026-07-15 12:35:26 -05:00
m_shared_builder.KeyWV("ok").Val(false);
m_shared_builder.KeyWV("error").ValS("Failed to dispatch load_config");
2026-07-13 10:55:30 -05:00
}
2026-07-15 12:35:26 -05:00
else
{
m_shared_builder.KeyWV("ok").Val(true);
m_shared_builder.KeyWV("result").ValS("Queued | Loading config from file");
}
m_shared_builder.EndObj();
m_shared_builder.PutChar('"');
2026-03-18 12:10:52 -05:00
}
//+------------------------------------------------------------------+
2026-07-13 10:55:30 -05:00
//| name: aidatataskrunner_save_config |
//| desc: Saves the current panel configuration to a file |
//| params (requerido: file_name): |
//| file_name string Absolute path inside MT5 Files\\ or |
//| Common\\Files\\, extension .txt |
2026-03-18 12:10:52 -05:00
//+------------------------------------------------------------------+
2026-07-13 10:55:30 -05:00
class CAiTaskRunnerToolSaveConfig : public CLLmTool
2026-03-18 12:10:52 -05:00
{
private:
2026-04-01 13:21:12 -05:00
const long m_panel_chart_id;
2026-03-18 12:10:52 -05:00
const long m_bot_chart_id;
public:
2026-07-13 10:55:30 -05:00
CAiTaskRunnerToolSaveConfig(const long panel_chart_id, const long bot_chart_id)
: CLLmTool("aidatataskrunner_save_config"),
m_panel_chart_id(panel_chart_id), m_bot_chart_id(bot_chart_id)
{}
2026-03-18 12:10:52 -05:00
~CAiTaskRunnerToolSaveConfig(void) {}
2026-07-15 12:35:26 -05:00
void Run(CJsonNode &param, CJsonBuilderStr* &out) override final;
2026-03-18 12:10:52 -05:00
};
//+------------------------------------------------------------------+
2026-07-15 12:35:26 -05:00
void CAiTaskRunnerToolSaveConfig::Run(CJsonNode &param, CJsonBuilderStr* &out)
2026-03-18 12:10:52 -05:00
{
2026-07-15 12:35:26 -05:00
out = m_shared_builder;
2026-07-13 10:55:30 -05:00
const string file_name = param["file_name"].ToString();
2026-03-18 12:10:52 -05:00
//---
2026-07-13 10:55:30 -05:00
const string id = AiTaskRunnerGenId(m_name);
2026-07-15 12:35:26 -05:00
m_shared_builder.PutChar('"');
m_shared_builder.Obj();
2026-04-01 13:21:12 -05:00
if(!::EventChartCustom(m_panel_chart_id, AIDATATASKRUNER_API_ON_PARAM_CHANGE,
m_bot_chart_id, double(AIDATATASKRUNER_API_SAVE_CONFIG_IN_FILE),
AiDataTaskRunnerEmpaquetar(id, file_name)))
2026-07-13 10:55:30 -05:00
{
2026-07-15 12:35:26 -05:00
m_shared_builder.KeyWV("ok").Val(false);
m_shared_builder.KeyWV("error").ValS("Failed to dispatch save_config");
2026-07-13 10:55:30 -05:00
}
2026-07-15 12:35:26 -05:00
else
{
m_shared_builder.KeyWV("ok").Val(true);
m_shared_builder.KeyWV("result").ValS("Queued | Saving config to file");
}
m_shared_builder.EndObj();
m_shared_builder.PutChar('"');
2026-03-18 12:10:52 -05:00
}
//+------------------------------------------------------------------+
2026-07-13 10:55:30 -05:00
//| name: aidatataskrunner_get_task_by_index |
//| desc: Returns the details of a task by its index in the table |
//| params (requerido: index): |
//| index integer Zero-based index of the task in the table. Use |
//| aidatataskrunner_get_task_total to know total |
2026-03-18 12:10:52 -05:00
//+------------------------------------------------------------------+
2026-07-13 10:55:30 -05:00
class CAiTaskRunnerToolGetTaskByIndex : public CLLmTool
2026-03-18 12:10:52 -05:00
{
private:
2026-04-01 13:21:12 -05:00
const long m_panel_chart_id;
2026-03-18 12:10:52 -05:00
const long m_bot_chart_id;
public:
2026-07-13 10:55:30 -05:00
CAiTaskRunnerToolGetTaskByIndex(const long panel_chart_id, const long bot_chart_id)
: CLLmTool("aidatataskrunner_get_task_by_index"),
m_panel_chart_id(panel_chart_id), m_bot_chart_id(bot_chart_id)
{}
2026-03-18 12:10:52 -05:00
~CAiTaskRunnerToolGetTaskByIndex(void) {}
2026-07-15 12:35:26 -05:00
void Run(CJsonNode &param, CJsonBuilderStr* &out) override final;
2026-03-18 12:10:52 -05:00
};
//+------------------------------------------------------------------+
2026-07-15 12:35:26 -05:00
void CAiTaskRunnerToolGetTaskByIndex::Run(CJsonNode &param, CJsonBuilderStr* &out)
2026-03-18 12:10:52 -05:00
{
2026-07-15 12:35:26 -05:00
out = m_shared_builder;
2026-07-13 10:55:30 -05:00
const string index = param["index"].ToString();
2026-03-18 12:10:52 -05:00
//---
2026-07-13 10:55:30 -05:00
const string id = AiTaskRunnerGenId(m_name);
2026-07-15 12:35:26 -05:00
m_shared_builder.PutChar('"');
m_shared_builder.Obj();
2026-04-01 13:21:12 -05:00
if(!::EventChartCustom(m_panel_chart_id, AIDATATASKRUNER_API_ON_PARAM_CHANGE,
m_bot_chart_id, double(AIDATATASKRUNER_API_GET_TASK_BY_INDEX),
AiDataTaskRunnerEmpaquetar(id, index)))
2026-07-13 10:55:30 -05:00
{
2026-07-15 12:35:26 -05:00
m_shared_builder.KeyWV("ok").Val(false);
m_shared_builder.KeyWV("error").ValS("Failed to dispatch get_task_by_index");
2026-07-13 10:55:30 -05:00
}
2026-07-15 12:35:26 -05:00
else
{
m_shared_builder.KeyWV("ok").Val(true);
m_shared_builder.KeyWV("result").ValS("Queued | Result will appear in chat");
}
m_shared_builder.EndObj();
m_shared_builder.PutChar('"');
2026-03-18 12:10:52 -05:00
}
2026-07-13 10:55:30 -05:00
}
2026-03-18 12:10:52 -05:00
//+------------------------------------------------------------------+
2026-07-13 10:55:30 -05:00
#endif // AIDATATASKRUNNER_BACKEND_TLGM_TOOLS_TOOLS_MQH