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"
|
| | |
|
2026-06-03 20:39:25 -05:00 | | | //+------------------------------------------------------------------+
|
| | | //| |
|
| | | //+------------------------------------------------------------------+
|
| | | namespace TSN
|
| | | {
|
2026-04-27 22:49:28 -05:00 | | | //+------------------------------------------------------------------+
|
| | | //| 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 | | |
|
2026-07-13 21:11:54 -05:00 | | | void Run(CJsonNode& param, CJsonBuilderStr* &out) override final;
|
2026-04-27 22:49:28 -05:00 | | | };
|
| | |
|
| | | //+------------------------------------------------------------------+
|
| | | //| |
|
| | | //+------------------------------------------------------------------+
|
2026-07-13 21:11:54 -05:00 | | | void CMcpFuncHistoryDealList::Run(CJsonNode& param, CJsonBuilderStr* &out)
|
2026-04-27 22:49:28 -05:00 | | | {
|
2026-04-28 08:52:21 -05:00 | | | //---
|
2026-07-13 21:11:54 -05:00 | | | out = m_shared_builder;
|
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-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("error").ValSWV(StringFormat("Erorr selected positions, last err = %d", ::GetLastError()));
|
| | | m_shared_builder.EndObj();
|
| | | m_shared_builder.PutChar('"');
|
2026-04-27 22:49:28 -05:00 | | | return;
|
| | | }
|
| | |
|
2026-04-28 08:52:21 -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").Arr();
|
2026-04-28 08:52:21 -05:00 | | | const int t = HistoryDealsTotal();
|
| | | for(int i = 0; i < t; i++)
|
| | | {
|
2026-07-13 21:11:54 -05:00 | | | m_shared_builder.Val((long)HistoryDealGetTicket(i));
|
2026-04-28 08:52:21 -05:00 | | | }
|
2026-07-13 21:11:54 -05:00 | | | m_shared_builder.EndArr();
|
| | | m_shared_builder.EndObj();
|
| | | m_shared_builder.PutChar('"');
|
2026-04-27 22:49:28 -05:00 | | | }
|
| | |
|
2026-04-28 08:52:21 -05:00 | | |
|
2026-04-27 22:49:28 -05:00 | | | //+------------------------------------------------------------------+
|
2026-04-29 07:59:28 -05:00 | | | //| history_deal_get |
|
2026-04-27 22:49:28 -05:00 | | | //+------------------------------------------------------------------+
|
2026-04-29 07:59:28 -05:00 | | | class CMcpFuncHistoryDealGet : public CMcpFunction
|
2026-04-27 22:49:28 -05:00 | | | {
|
| | | public:
|
2026-04-29 07:59:28 -05:00 | | | CMcpFuncHistoryDealGet() : CMcpFunction(0, false, "history_deal_get") {}
|
| | | ~CMcpFuncHistoryDealGet(void) {}
|
2026-04-27 22:49:28 -05:00 | | |
|
2026-07-13 21:11:54 -05:00 | | | void Run(CJsonNode& param, CJsonBuilderStr* &out) override final;
|
2026-04-27 22:49:28 -05:00 | | | };
|
| | |
|
| | | //+------------------------------------------------------------------+
|
| | | //| |
|
| | | //+------------------------------------------------------------------+
|
2026-07-13 21:11:54 -05:00 | | | void CMcpFuncHistoryDealGet::Run(CJsonNode& param, CJsonBuilderStr* &out)
|
2026-04-27 22:49:28 -05:00 | | | {
|
2026-07-13 21:11:54 -05:00 | | | //---
|
| | | out = m_shared_builder;
|
2026-04-27 22:49:28 -05:00 | | | ::ResetLastError();
|
| | | const ulong ticket = (ulong)param["ticket"].ToInt(0);
|
| | |
|
| | | //---
|
| | | if(!::HistoryDealSelect(ticket))
|
| | | {
|
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("deal_not_found, last mt5 error = %d", ::GetLastError()));
|
| | | m_shared_builder.EndObj();
|
| | | m_shared_builder.PutChar('"');
|
2026-04-27 22:49:28 -05:00 | | | return;
|
| | | }
|
| | |
|
| | | //---
|
2026-06-03 20:39:25 -05:00 | | | const int8_t mode = (int8_t)param["mode"].ToInt(0);
|
2026-04-27 22:49:28 -05:00 | | |
|
2026-04-29 07:59:28 -05:00 | | | switch(mode)
|
2026-04-27 22:49:28 -05:00 | | | {
|
2026-04-29 07:59:28 -05:00 | | | //--- DOUBLE
|
| | | case 0:
|
| | | {
|
| | | double v;
|
| | | if(HistoryDealGetDouble(
|
| | | ticket,
|
2026-06-28 22:09:10 -05:00 | | | CEnumRegBasis::GetValNoRef<ENUM_DEAL_PROPERTY_DOUBLE>(param["property"].ToString(""), WRONG_VALUE),
|
2026-04-29 07:59:28 -05:00 | | | v))
|
| | | {
|
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(v);
|
| | | m_shared_builder.EndObj();
|
| | | m_shared_builder.PutChar('"');
|
2026-04-29 07:59:28 -05:00 | | | return;
|
| | | }
|
| | | break;
|
| | | }
|
| | |
|
| | | //--- INTEGER
|
| | | case 1:
|
| | | {
|
| | | long v;
|
| | | if(HistoryDealGetInteger(
|
| | | ticket,
|
2026-06-28 22:09:10 -05:00 | | | CEnumRegBasis::GetValNoRef<ENUM_DEAL_PROPERTY_INTEGER>(param["property"].ToString(""), WRONG_VALUE),
|
2026-04-29 07:59:28 -05:00 | | | v))
|
| | | {
|
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(v);
|
| | | m_shared_builder.EndObj();
|
| | | m_shared_builder.PutChar('"');
|
2026-04-29 07:59:28 -05:00 | | | return;
|
| | | }
|
| | | break;
|
| | | }
|
| | |
|
| | | //--- STRING
|
| | | case 2:
|
| | | {
|
| | | string v;
|
| | | if(HistoryDealGetString(
|
| | | ticket,
|
2026-06-28 22:09:10 -05:00 | | | CEnumRegBasis::GetValNoRef<ENUM_DEAL_PROPERTY_STRING>(param["property"].ToString(""), WRONG_VALUE),
|
2026-04-29 07:59:28 -05:00 | | | v))
|
| | | {
|
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(v);
|
| | | m_shared_builder.EndObj();
|
| | | m_shared_builder.PutChar('"');
|
2026-04-29 07:59:28 -05:00 | | | return;
|
| | | }
|
| | | 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 mode = %d", mode));
|
| | | m_shared_builder.EndObj();
|
| | | m_shared_builder.PutChar('"');
|
2026-04-29 07:59:28 -05:00 | | | return;
|
2026-04-27 22:49:28 -05:00 | | | }
|
| | |
|
| | | //---
|
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("Failed to call HistoryDealGet*, last mt5 err = %d", ::GetLastError()));
|
| | | m_shared_builder.EndObj();
|
| | | m_shared_builder.PutChar('"');
|
2026-04-27 22:49:28 -05:00 | | | }
|
| | |
|
| | |
|
| | |
|
| | | //+------------------------------------------------------------------+
|
2026-06-03 20:39:25 -05:00 | | | } // namespace TSN
|
2026-04-27 22:49:28 -05:00 | | | #endif // FULLMT5MCPBYLEO_SRC_TRADE_DEALS_MQH
|