2026-04-28 21:48:13 -05:00 | | | //+------------------------------------------------------------------+
|
| | | //| Utils.mqh |
|
| | | //| Copyright 2026, Niquel Mendoza. |
|
| | | //| https://www.mql5.com/es/users/nique_372 |
|
| | | //+------------------------------------------------------------------+
|
| | | #property copyright "Copyright 2026, Niquel Mendoza."
|
| | | #property link "https://www.mql5.com/es/users/nique_372"
|
| | | #property strict
|
| | |
|
| | | #ifndef FULLMT5MCPBYLEO_SRC_UTILS_UTILS_MQH
|
| | | #define FULLMT5MCPBYLEO_SRC_UTILS_UTILS_MQH
|
| | |
|
| | |
|
| | | //+------------------------------------------------------------------+
|
| | | //| Include |
|
| | | //+------------------------------------------------------------------+
|
| | | #include "..\\Def\\Def.mqh"
|
| | |
|
2026-06-03 20:39:25 -05:00 | | | //+------------------------------------------------------------------+
|
| | | //| |
|
| | | //+------------------------------------------------------------------+
|
| | | namespace TSN
|
| | | {
|
2026-04-28 21:48:13 -05:00 | | | //+------------------------------------------------------------------+
|
| | | //| CMcpFuncGetTime - Obtiene diferentes tipos de tiempo |
|
| | | //+------------------------------------------------------------------+
|
| | | class CMcpFuncGetTime : public CMcpFunction
|
| | | {
|
| | | public:
|
| | | CMcpFuncGetTime(void);
|
| | | ~CMcpFuncGetTime(void) {}
|
| | |
|
2026-07-13 21:11:54 -05:00 | | | void Run(CJsonNode& param, CJsonBuilderStr* &out) override final;
|
2026-04-28 21:48:13 -05:00 | | | };
|
| | |
|
| | |
|
| | | //+------------------------------------------------------------------+
|
| | | //| Constructor |
|
| | | //+------------------------------------------------------------------+
|
| | | CMcpFuncGetTime::CMcpFuncGetTime(void) : CMcpFunction(0, false, "get_time")
|
| | | {
|
| | | }
|
| | |
|
| | | //+------------------------------------------------------------------+
|
| | | //| Run - Retorna el tiempo solicitado en múltiples formatos |
|
| | | //+------------------------------------------------------------------+
|
2026-07-13 21:11:54 -05:00 | | | void CMcpFuncGetTime::Run(CJsonNode& param, CJsonBuilderStr* &out)
|
2026-04-28 21:48:13 -05:00 | | | {
|
| | | //---
|
2026-07-13 21:11:54 -05:00 | | | out = m_shared_builder; // confimamos que usamos el mismo.. este es el que usamos
|
2026-06-28 22:09:10 -05:00 | | | const int8_t type = int8_t(CEnumRegFullMt5Mcp::GetValNoRef<ENUM_MCPFUNC_TYPE_TIME>(param["type"].ToString(), WRONG_VALUE));
|
2026-04-28 21:48:13 -05:00 | | |
|
| | | //---
|
| | | datetime time = 0;
|
| | | switch(type)
|
| | | {
|
| | | case MCPFUNC_TIME_GMT:
|
| | | time = TimeGMT();
|
| | | break;
|
| | | case MCPFUNC_TIME_CURRENT:
|
| | | time = TimeCurrent();
|
| | | break;
|
| | | case MCPFUNC_TIME_LOCAL:
|
| | | time = TimeLocal();
|
| | | break;
|
| | | case MCPFUNC_TIME_SERVER:
|
| | | time = TimeTradeServer();
|
| | | break;
|
| | | default:
|
2026-07-13 21:11:54 -05:00 | | | {
|
| | | m_shared_builder.PutChar('"');
|
| | | m_shared_builder.Obj();
|
| | | m_shared_builder.KeyWV("ok").Val(false);
|
| | | m_shared_builder.KeyWV("error").ValSWV(StringFormat("Invalid type = %s", EnumToString(ENUM_MCPFUNC_TYPE_TIME(type))));
|
| | | m_shared_builder.EndObj();
|
| | | m_shared_builder.PutChar('"');
|
2026-04-28 21:48:13 -05:00 | | | return;
|
2026-07-13 21:11:54 -05:00 | | | }
|
2026-04-28 21:48:13 -05:00 | | | }
|
| | |
|
| | | //---
|
2026-07-13 21:11:54 -05:00 | | | m_shared_builder.PutChar('"');
|
| | | m_shared_builder.Obj();
|
| | | m_shared_builder.KeyWV("ok").Val(true);
|
| | | m_shared_builder.KeyWV("result").ValSWV(TimeToString(time, TIME_DATE | TIME_MINUTES | TIME_SECONDS));
|
| | | m_shared_builder.EndObj();
|
| | | m_shared_builder.PutChar('"');
|
2026-04-28 21:48:13 -05:00 | | | }
|
| | |
|
| | |
|
| | | //+------------------------------------------------------------------+
|
| | | //| CMcpFuncGetErrDescription - Obtiene descripción de errores |
|
| | | //+------------------------------------------------------------------+
|
| | | class CMcpFuncGetErrDescription : public CMcpFunction
|
| | | {
|
| | | public:
|
| | | CMcpFuncGetErrDescription(void);
|
| | | ~CMcpFuncGetErrDescription(void);
|
| | |
|
2026-07-13 21:11:54 -05:00 | | | void Run(CJsonNode& param, CJsonBuilderStr* &out) override final;
|
2026-04-28 21:48:13 -05:00 | | | };
|
| | |
|
| | |
|
| | | //+------------------------------------------------------------------+
|
| | | //| Constructor |
|
| | | //+------------------------------------------------------------------+
|
| | | CMcpFuncGetErrDescription::CMcpFuncGetErrDescription(void) : CMcpFunction(0, false, "get_err_description")
|
| | | {
|
| | | }
|
| | |
|
| | | //+------------------------------------------------------------------+
|
| | | //| Destructor |
|
| | | //+------------------------------------------------------------------+
|
| | | CMcpFuncGetErrDescription::~CMcpFuncGetErrDescription(void)
|
| | | {
|
| | | }
|
| | |
|
| | |
|
| | | //+------------------------------------------------------------------+
|
| | | //| Run - Retorna descripción de error MT5 |
|
| | | //+------------------------------------------------------------------+
|
2026-07-13 21:11:54 -05:00 | | | void CMcpFuncGetErrDescription::Run(CJsonNode& param, CJsonBuilderStr* &out)
|
2026-04-28 21:48:13 -05:00 | | | {
|
| | | //---
|
2026-07-13 21:11:54 -05:00 | | | out = m_shared_builder;
|
2026-04-28 21:48:13 -05:00 | | | const int error_code = (int)param["error_code"].ToInt(-1);
|
| | | const bool include_code = param["include_code"].ToBool(true);
|
| | |
|
| | | //---
|
| | | string err = "";
|
| | |
|
| | | //---
|
| | | CMt5ErrorDesc::GetError(err, error_code, include_code);
|
| | |
|
| | | //---
|
2026-07-13 21:11:54 -05:00 | | | m_shared_builder.PutChar('"');
|
| | | m_shared_builder.Obj();
|
| | | m_shared_builder.KeyWV("ok").Val(true);
|
| | | m_shared_builder.KeyWV("result").ValS(err);
|
| | | m_shared_builder.EndObj();
|
| | | m_shared_builder.PutChar('"');
|
2026-04-28 21:48:13 -05:00 | | | }
|
2026-04-29 07:59:28 -05:00 | | |
|
| | | //+------------------------------------------------------------------+
|
| | | //| account_info |
|
| | | //+------------------------------------------------------------------+
|
| | | class CMcpFuncAccountInfo : public CMcpFunction
|
| | | {
|
| | | public:
|
| | | CMcpFuncAccountInfo() : CMcpFunction(0, false, "account_info") {}
|
| | | ~CMcpFuncAccountInfo(void) {}
|
| | |
|
2026-07-13 21:11:54 -05:00 | | | void Run(CJsonNode& param, CJsonBuilderStr* &out) override final;
|
2026-04-29 07:59:28 -05:00 | | | };
|
| | |
|
| | | //+------------------------------------------------------------------+
|
2026-07-13 21:11:54 -05:00 | | | void CMcpFuncAccountInfo::Run(CJsonNode& param, CJsonBuilderStr* &out)
|
2026-04-29 07:59:28 -05:00 | | | {
|
2026-07-13 21:11:54 -05:00 | | | //---
|
| | | out = m_shared_builder;
|
2026-06-03 20:39:25 -05:00 | | | const int8_t mode = (int8_t)param["mode"].ToInt(0);
|
2026-07-13 21:11:54 -05:00 | | |
|
| | | //---
|
2026-04-29 07:59:28 -05:00 | | | switch(mode)
|
| | | {
|
| | | //--- DOUBLE
|
| | | case 0:
|
| | | {
|
2026-07-13 21:11:54 -05:00 | | | m_shared_builder.PutChar('"');
|
| | | m_shared_builder.Obj();
|
| | | m_shared_builder.KeyWV("ok").Val(true);
|
| | | m_shared_builder.KeyWV("result").Val(AccountInfoDouble(CEnumRegBasis::GetValNoRef<ENUM_ACCOUNT_INFO_DOUBLE>(param["property"].ToString(""), WRONG_VALUE)));
|
| | | m_shared_builder.EndObj();
|
| | | m_shared_builder.PutChar('"');
|
2026-04-29 07:59:28 -05:00 | | | return;
|
| | | }
|
| | |
|
| | | //--- INTEGER
|
| | | case 1:
|
| | | {
|
2026-07-13 21:11:54 -05:00 | | | m_shared_builder.PutChar('"');
|
| | | m_shared_builder.Obj();
|
| | | m_shared_builder.KeyWV("ok").Val(true);
|
| | | m_shared_builder.KeyWV("result").Val((long)AccountInfoInteger(CEnumRegBasis::GetValNoRef<ENUM_ACCOUNT_INFO_INTEGER>(param["property"].ToString(""), WRONG_VALUE)));
|
| | | m_shared_builder.EndObj();
|
| | | m_shared_builder.PutChar('"');
|
2026-04-29 07:59:28 -05:00 | | | return;
|
| | | }
|
| | |
|
| | | //--- STRING
|
| | | case 2:
|
| | | {
|
2026-07-13 21:11:54 -05:00 | | | m_shared_builder.PutChar('"');
|
| | | m_shared_builder.Obj();
|
| | | m_shared_builder.KeyWV("ok").Val(true);
|
| | | m_shared_builder.KeyWV("result").ValS(AccountInfoString(CEnumRegBasis::GetValNoRef<ENUM_ACCOUNT_INFO_STRING>(param["property"].ToString(""), WRONG_VALUE)));
|
| | | m_shared_builder.EndObj();
|
| | | m_shared_builder.PutChar('"');
|
2026-04-29 07:59:28 -05:00 | | | return;
|
| | | }
|
| | |
|
| | | default:
|
2026-07-13 21:11:54 -05:00 | | | {
|
| | | m_shared_builder.PutChar('"');
|
| | | m_shared_builder.Obj();
|
| | | m_shared_builder.KeyWV("ok").Val(false);
|
| | | m_shared_builder.KeyWV("error").ValSWV(StringFormat("Invalid mode = %d", mode));
|
| | | m_shared_builder.EndObj();
|
| | | m_shared_builder.PutChar('"');
|
2026-04-29 07:59:28 -05:00 | | | return;
|
2026-07-13 21:11:54 -05:00 | | | }
|
2026-04-29 07:59:28 -05:00 | | | }
|
| | | }
|
| | |
|
| | | //+------------------------------------------------------------------+
|
| | | //| terminal_info |
|
| | | //+------------------------------------------------------------------+
|
| | | class CMcpFuncTerminalInfo : public CMcpFunction
|
| | | {
|
| | | public:
|
| | | CMcpFuncTerminalInfo() : CMcpFunction(0, false, "terminal_info") {}
|
| | | ~CMcpFuncTerminalInfo(void) {}
|
| | |
|
2026-07-13 21:11:54 -05:00 | | | void Run(CJsonNode& param, CJsonBuilderStr* &out) override final;
|
2026-04-29 07:59:28 -05:00 | | | };
|
| | |
|
| | | //+------------------------------------------------------------------+
|
2026-07-13 21:11:54 -05:00 | | | void CMcpFuncTerminalInfo::Run(CJsonNode& param, CJsonBuilderStr* &out)
|
2026-04-29 07:59:28 -05:00 | | | {
|
2026-07-13 21:11:54 -05:00 | | | //---
|
| | | out = m_shared_builder;
|
2026-06-03 20:39:25 -05:00 | | | const int8_t mode = (int8_t)param["mode"].ToInt(0);
|
2026-04-29 07:59:28 -05:00 | | |
|
2026-07-13 21:11:54 -05:00 | | | //---
|
2026-04-29 07:59:28 -05:00 | | | switch(mode)
|
| | | {
|
| | | //--- DOUBLE
|
| | | case 0:
|
| | | {
|
2026-07-13 21:11:54 -05:00 | | | m_shared_builder.PutChar('"');
|
| | | m_shared_builder.Obj();
|
| | | m_shared_builder.KeyWV("ok").Val(true);
|
| | | m_shared_builder.KeyWV("result").Val(TerminalInfoDouble(CEnumRegBasis::GetValNoRef<ENUM_TERMINAL_INFO_DOUBLE>(param["property"].ToString(""), WRONG_VALUE)));
|
| | | m_shared_builder.EndObj();
|
| | | m_shared_builder.PutChar('"');
|
2026-04-29 07:59:28 -05:00 | | | return;
|
| | | }
|
| | |
|
| | | //--- INTEGER
|
| | | case 1:
|
| | | {
|
2026-07-13 21:11:54 -05:00 | | | m_shared_builder.PutChar('"');
|
| | | m_shared_builder.Obj();
|
| | | m_shared_builder.KeyWV("ok").Val(true);
|
| | | m_shared_builder.KeyWV("result").Val((long)TerminalInfoInteger(CEnumRegBasis::GetValNoRef<ENUM_TERMINAL_INFO_INTEGER>(param["property"].ToString(""), WRONG_VALUE)));
|
| | | m_shared_builder.EndObj();
|
| | | m_shared_builder.PutChar('"');
|
2026-04-29 07:59:28 -05:00 | | | return;
|
| | | }
|
| | |
|
| | | //--- STRING
|
| | | case 2:
|
| | | {
|
2026-07-13 21:11:54 -05:00 | | | m_shared_builder.PutChar('"');
|
| | | m_shared_builder.Obj();
|
| | | m_shared_builder.KeyWV("ok").Val(true);
|
| | | m_shared_builder.KeyWV("result").ValS(TerminalInfoString(CEnumRegBasis::GetValNoRef<ENUM_TERMINAL_INFO_STRING>(param["property"].ToString(""), WRONG_VALUE)));
|
| | | m_shared_builder.EndObj();
|
| | | m_shared_builder.PutChar('"');
|
2026-04-29 07:59:28 -05:00 | | | return;
|
| | | }
|
| | |
|
| | | default:
|
2026-07-13 21:11:54 -05:00 | | | {
|
| | | m_shared_builder.PutChar('"');
|
| | | m_shared_builder.Obj();
|
| | | m_shared_builder.KeyWV("ok").Val(false);
|
| | | m_shared_builder.KeyWV("error").ValSWV(StringFormat("Invalid mode = %d", mode));
|
| | | m_shared_builder.EndObj();
|
| | | m_shared_builder.PutChar('"');
|
2026-04-29 07:59:28 -05:00 | | | return;
|
2026-07-13 21:11:54 -05:00 | | | }
|
2026-04-29 07:59:28 -05:00 | | | }
|
| | | }
|
| | |
|
2026-04-28 21:48:13 -05:00 | | | //+------------------------------------------------------------------+
|
2026-06-03 20:39:25 -05:00 | | | } // namespace TSN
|
2026-04-28 22:54:27 -05:00 | | | #endif // FULLMT5MCPBYLEO_SRC_UTILS_UTILS_MQH
|