2026-04-27 22:49:28 -05:00
|
|
|
//+------------------------------------------------------------------+
|
|
|
|
|
//| Deals.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_TRADE_DEALS_MQH
|
|
|
|
|
#define FULLMT5MCPBYLEO_SRC_TRADE_DEALS_MQH
|
|
|
|
|
|
|
|
|
|
//+------------------------------------------------------------------+
|
|
|
|
|
//| Include |
|
|
|
|
|
//+------------------------------------------------------------------+
|
|
|
|
|
#include "..\\Def\\Def.mqh"
|
|
|
|
|
|
|
|
|
|
//+------------------------------------------------------------------+
|
|
|
|
|
//| history_deal_get_total |
|
|
|
|
|
//+------------------------------------------------------------------+
|
2026-04-28 08:52:21 -05:00
|
|
|
class CMcpFuncHistoryDealList : public CMcpFunction
|
2026-04-27 22:49:28 -05:00
|
|
|
{
|
|
|
|
|
public:
|
2026-04-28 08:52:21 -05:00
|
|
|
CMcpFuncHistoryDealList() : CMcpFunction(0, false, "history_deal_list") {}
|
|
|
|
|
~CMcpFuncHistoryDealList(void) {}
|
2026-04-27 22:49:28 -05:00
|
|
|
|
|
|
|
|
void Run(CJsonNode& param, string& res) override final;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
//+------------------------------------------------------------------+
|
|
|
|
|
//| |
|
|
|
|
|
//+------------------------------------------------------------------+
|
2026-04-28 08:52:21 -05:00
|
|
|
void CMcpFuncHistoryDealList::Run(CJsonNode& param, string& res)
|
2026-04-27 22:49:28 -05:00
|
|
|
{
|
2026-04-28 08:52:21 -05:00
|
|
|
//---
|
|
|
|
|
if(!HistorySelect(
|
|
|
|
|
StringToTime(param["start_date_select"].ToString("0")),
|
|
|
|
|
StringToTime(param["end_date_select"].ToString(TimeToString(TimeCurrent(), TIME_DATE | TIME_MINUTES | TIME_SECONDS)))
|
|
|
|
|
))
|
2026-04-27 22:49:28 -05:00
|
|
|
{
|
2026-04-28 10:48:57 -05:00
|
|
|
res = StringFormat("{\"ok\":true,\"error\":\"Erorr selected positions, last err = %d\"}", ::GetLastError());
|
2026-04-27 22:49:28 -05:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2026-04-28 08:52:21 -05:00
|
|
|
//---
|
|
|
|
|
res = "{\"ok\":true,\"result\":[";
|
|
|
|
|
const int t = HistoryDealsTotal();
|
|
|
|
|
for(int i = 0; i < t; i++)
|
|
|
|
|
{
|
|
|
|
|
if(i == t - 1)
|
|
|
|
|
res += string(HistoryDealGetTicket(i));
|
|
|
|
|
else
|
|
|
|
|
res += string(HistoryDealGetTicket(i)) + ",";
|
|
|
|
|
}
|
|
|
|
|
res += "]}";
|
2026-04-27 22:49:28 -05:00
|
|
|
}
|
|
|
|
|
|
2026-04-28 08:52:21 -05:00
|
|
|
|
2026-04-27 22:49:28 -05:00
|
|
|
//+------------------------------------------------------------------+
|
|
|
|
|
//| history_deal_get_double |
|
|
|
|
|
//+------------------------------------------------------------------+
|
|
|
|
|
class CMcpFuncHistoryDealGetDouble : public CMcpFunction
|
|
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
CMcpFuncHistoryDealGetDouble() : CMcpFunction(0, false, "history_deal_get_double") {}
|
|
|
|
|
~CMcpFuncHistoryDealGetDouble(void) {}
|
|
|
|
|
|
|
|
|
|
void Run(CJsonNode& param, string& res) override final;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
//+------------------------------------------------------------------+
|
|
|
|
|
//| |
|
|
|
|
|
//+------------------------------------------------------------------+
|
|
|
|
|
void CMcpFuncHistoryDealGetDouble::Run(CJsonNode& param, string& res)
|
|
|
|
|
{
|
|
|
|
|
::ResetLastError();
|
|
|
|
|
const ulong ticket = (ulong)param["ticket"].ToInt(0);
|
|
|
|
|
|
|
|
|
|
//---
|
|
|
|
|
if(!::HistoryDealSelect(ticket))
|
|
|
|
|
{
|
|
|
|
|
res = StringFormat("{\"ok\":false,\"error\":\"deal not found in history, last mt5 error = %d\"}", ::GetLastError());
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//---
|
2026-04-28 08:52:21 -05:00
|
|
|
const ENUM_DEAL_PROPERTY_DOUBLE property = CEnumReg::GetValueNoRef<ENUM_DEAL_PROPERTY_DOUBLE>(param["property"].ToString(""), DEAL_VOLUME);
|
2026-04-27 22:49:28 -05:00
|
|
|
const double value = HistoryDealGetDouble(ticket, property);
|
|
|
|
|
res = StringFormat("{\"ok\":true,\"result\":%.8f}", value);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//+------------------------------------------------------------------+
|
|
|
|
|
//| history_deal_get_integer |
|
|
|
|
|
//+------------------------------------------------------------------+
|
|
|
|
|
class CMcpFuncHistoryDealGetInteger : public CMcpFunction
|
|
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
CMcpFuncHistoryDealGetInteger() : CMcpFunction(0, false, "history_deal_get_integer") {}
|
|
|
|
|
~CMcpFuncHistoryDealGetInteger(void) {}
|
|
|
|
|
|
|
|
|
|
void Run(CJsonNode& param, string& res) override final;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
//+------------------------------------------------------------------+
|
|
|
|
|
//| |
|
|
|
|
|
//+------------------------------------------------------------------+
|
|
|
|
|
void CMcpFuncHistoryDealGetInteger::Run(CJsonNode& param, string& res)
|
|
|
|
|
{
|
|
|
|
|
::ResetLastError();
|
|
|
|
|
const ulong ticket = (ulong)param["ticket"].ToInt(0);
|
|
|
|
|
|
|
|
|
|
//---
|
|
|
|
|
if(!::HistoryDealSelect(ticket))
|
|
|
|
|
{
|
|
|
|
|
res = StringFormat("{\"ok\":false,\"error\":\"deal not found in history, last mt5 error = %d\"}", ::GetLastError());
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//---
|
2026-04-28 08:52:21 -05:00
|
|
|
const ENUM_DEAL_PROPERTY_INTEGER property = CEnumReg::GetValueNoRef<ENUM_DEAL_PROPERTY_INTEGER>(param["property"].ToString(""), DEAL_TICKET);
|
2026-04-27 22:49:28 -05:00
|
|
|
const long value = HistoryDealGetInteger(ticket, property);
|
|
|
|
|
res = StringFormat("{\"ok\":true,\"result\":%ld}", value);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//+------------------------------------------------------------------+
|
|
|
|
|
//| history_deal_get_string |
|
|
|
|
|
//+------------------------------------------------------------------+
|
|
|
|
|
class CMcpFuncHistoryDealGetString : public CMcpFunction
|
|
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
CMcpFuncHistoryDealGetString() : CMcpFunction(0, false, "history_deal_get_string") {}
|
|
|
|
|
~CMcpFuncHistoryDealGetString(void) {}
|
|
|
|
|
|
|
|
|
|
void Run(CJsonNode& param, string& res) override final;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
//+------------------------------------------------------------------+
|
|
|
|
|
//| |
|
|
|
|
|
//+------------------------------------------------------------------+
|
|
|
|
|
void CMcpFuncHistoryDealGetString::Run(CJsonNode& param, string& res)
|
|
|
|
|
{
|
|
|
|
|
::ResetLastError();
|
|
|
|
|
const ulong ticket = (ulong)param["ticket"].ToInt(0);
|
|
|
|
|
|
|
|
|
|
//---
|
|
|
|
|
if(!::HistoryDealSelect(ticket))
|
|
|
|
|
{
|
|
|
|
|
res = StringFormat("{\"ok\":false,\"error\":\"deal not found in history, last mt5 error = %d\"}", ::GetLastError());
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//---
|
2026-04-28 08:52:21 -05:00
|
|
|
const ENUM_DEAL_PROPERTY_STRING property = CEnumReg::GetValueNoRef<ENUM_DEAL_PROPERTY_STRING>(param["property"].ToString(""), DEAL_SYMBOL);
|
2026-04-27 22:49:28 -05:00
|
|
|
const string value = HistoryDealGetString(ticket, property);
|
|
|
|
|
res = StringFormat("{\"ok\":true,\"result\":\"%s\"}", value);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//+------------------------------------------------------------------+
|
|
|
|
|
#endif // FULLMT5MCPBYLEO_SRC_TRADE_DEALS_MQH
|