89 lines
3.3 KiB
MQL5
89 lines
3.3 KiB
MQL5
//+------------------------------------------------------------------+
|
|
//| Time.mqh |
|
|
//| Copyright 2026, Niquel Mendoza. |
|
|
//| https://www.mql5.com/ |
|
|
//+------------------------------------------------------------------+
|
|
#property copyright "Copyright 2026, Niquel Mendoza."
|
|
#property link "https://www.mql5.com/"
|
|
#property strict
|
|
|
|
#ifndef LLMAGENTSBASICTOOLS_SRC_UTILS_TIME_MQH
|
|
#define LLMAGENTSBASICTOOLS_SRC_UTILS_TIME_MQH
|
|
|
|
//+------------------------------------------------------------------+
|
|
//| |
|
|
//+------------------------------------------------------------------+
|
|
#include "..\\Def.mqh"
|
|
|
|
//+------------------------------------------------------------------+
|
|
//| |
|
|
//+------------------------------------------------------------------+
|
|
namespace TSN
|
|
{
|
|
//+------------------------------------------------------------------+
|
|
//| name: get_time |
|
|
//| desc: Returns the requested time (gmt, server, local or symbol) |
|
|
//| params: |
|
|
//| type string enum ENUM_LLMAGENT_BTOOLS_TIME: gmt, server, |
|
|
//| local, symbol |
|
|
//| symbol string Optional, solo aplica para type=symbol. |
|
|
//| Default: _Symbol |
|
|
//+------------------------------------------------------------------+
|
|
class CLlmBToolGetTime : public CLLmTool
|
|
{
|
|
public:
|
|
CLlmBToolGetTime(void) : CLLmTool("get_time") {}
|
|
~CLlmBToolGetTime(void) {}
|
|
|
|
void Run(CJsonNode& param, CJsonBuilderStr* &out) override final
|
|
{
|
|
out = m_shared_builder;
|
|
const ENUM_LLMAGENT_BTOOLS_TIME type_time = CEnumRegLlmBTools::GetValNoRef<ENUM_LLMAGENT_BTOOLS_TIME>(param["type"].ToString(), WRONG_VALUE);
|
|
|
|
//---
|
|
datetime time = 0;
|
|
switch(type_time)
|
|
{
|
|
case LLMAGENT_BTOOLS_TIME_GMT:
|
|
time = TimeGMT();
|
|
break;
|
|
|
|
case LLMAGENT_BTOOLS_TIME_SERVER:
|
|
time = TimeTradeServer();
|
|
break;
|
|
|
|
case LLMAGENT_BTOOLS_TIME_LOCAL:
|
|
time = TimeLocal();
|
|
break;
|
|
|
|
case LLMAGENT_BTOOLS_TIME_SYMBOL:
|
|
{
|
|
const string symbol = param["symbol"].ToString(_Symbol);
|
|
time = datetime(SymbolInfoInteger(symbol, SYMBOL_TIME));
|
|
break;
|
|
}
|
|
|
|
default:
|
|
{
|
|
m_shared_builder.PutChar('"');
|
|
m_shared_builder.Obj();
|
|
m_shared_builder.KeyWV("ok").Val(false);
|
|
m_shared_builder.KeyWV("error").ValS(StringFormat("Invalid time type = %d", EnumToString(type_time)));
|
|
m_shared_builder.EndObj();
|
|
m_shared_builder.PutChar('"');
|
|
return;
|
|
}
|
|
}
|
|
|
|
//---
|
|
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('"');
|
|
}
|
|
};
|
|
}
|
|
//+------------------------------------------------------------------+
|
|
#endif // LLMAGENTSBASICTOOLS_SRC_UTILS_TIME_MQH
|