2026-05-07 16:15:15 -05:00 | | | //+------------------------------------------------------------------+
|
| | | //| Main.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 TBPWRRAPER_SRC_MQL5_BASE_MQH
|
| | | #define TBPWRRAPER_SRC_MQL5_BASE_MQH
|
| | |
|
| | | //+------------------------------------------------------------------+
|
| | | //| |
|
| | | //+------------------------------------------------------------------+
|
| | | #include "Defines.mqh"
|
| | |
|
| | | //+------------------------------------------------------------------+
|
| | | //| |
|
| | | //+------------------------------------------------------------------+
|
2026-06-03 12:24:19 -05:00 | | | namespace TSN
|
| | | {
|
2026-10-13 07:37:43 -05:00 | | | //+------------------------------------------------------------------+
|
| | | //| |
|
| | | //+------------------------------------------------------------------+
|
| | | class CTbpBase
|
2026-05-07 16:15:15 -05:00 | | | {
|
| | | protected:
|
| | | //--- Variables miembro
|
| | | string m_api_key;
|
2026-06-03 12:24:19 -05:00 | | | CJsonParser m_json;
|
2026-05-07 16:15:15 -05:00 | | | int m_timeout;
|
2026-10-13 07:37:43 -05:00 | | | int m_last_http;
|
| | | ENUM_TSN_TBP_ERR m_last_err;
|
| | |
|
| | | //---
|
| | | // Solo request, resultado crudo en m_json.m_raw
|
| | | bool Send(const string& url);
|
| | | // Request + CalcLen + CorrectPadding + Parse
|
| | | bool SendAndParse(const string& url);
|
2026-05-07 16:15:15 -05:00 | | |
|
| | | public:
|
2026-10-13 07:37:43 -05:00 | | | CTbpBase(void) : m_api_key(NULL), m_timeout(5000), m_last_http(0), m_last_err(TSN_TBP_ERR_NONE) {}
|
2026-05-07 16:15:15 -05:00 | | | ~CTbpBase(void) {}
|
| | |
|
| | | //--- Getters \ Setters
|
| | | //- Apy key
|
| | | __forceinline string ApyKey() const { return m_api_key; }
|
| | | void ApyKey(const string& apykey) { m_api_key = apykey; }
|
| | |
|
| | | //- json
|
2026-06-03 12:24:19 -05:00 | | | CJsonParser* GetLastJson() { return &m_json; }
|
2026-05-07 16:15:15 -05:00 | | |
|
2026-10-13 07:37:43 -05:00 | | | //- Ultimo error
|
| | | ENUM_TSN_TBP_ERR LastErr() const { return m_last_err; }
|
| | |
|
| | | //- Ultimo codigo http
|
| | | int LastHttp() const { return m_last_http; }
|
| | |
|
2026-05-07 16:15:15 -05:00 | | | //- Timeout
|
| | | __forceinline int Timeout() const { return m_timeout; }
|
| | | void Timeout(const int timeout) { m_timeout = timeout; }
|
| | |
|
| | | //---
|
| | | bool GetAllClients();
|
| | | };
|
| | | //+------------------------------------------------------------------+
|
| | | //| |
|
| | | //+------------------------------------------------------------------+
|
2026-10-13 07:37:43 -05:00 | | | bool CTbpBase::Send(const string& url)
|
2026-05-07 16:15:15 -05:00 | | | {
|
| | | //---
|
2026-10-13 07:37:43 -05:00 | | | m_last_err = TSN_TBP_ERR_NONE;
|
| | | const string req_headers = "api-key: " + m_api_key + "\r\n";
|
2026-06-03 12:24:19 -05:00 | | |
|
2026-10-13 07:37:43 -05:00 | | | //---
|
| | | static string res_headers;
|
| | | static uchar data[];
|
2026-05-07 16:15:15 -05:00 | | |
|
| | | //---
|
2026-10-13 07:37:43 -05:00 | | | m_last_http = WebRequest(
|
| | | "GET",
|
| | | url,
|
| | | req_headers,
|
| | | m_timeout,
|
| | | data,
|
| | | m_json.m_raw,
|
| | | res_headers
|
| | | );
|
2026-05-07 16:15:15 -05:00 | | |
|
2026-10-13 07:37:43 -05:00 | | | //---
|
| | | if(m_last_http != 200)
|
| | | {
|
| | | m_last_err = TSN_TBP_ERR_SEND_HTTP;
|
| | | return false;
|
| | | }
|
2026-05-07 16:15:15 -05:00 | | |
|
| | | //---
|
2026-10-13 07:37:43 -05:00 | | | return true;
|
| | | }
|
| | |
|
| | | //+------------------------------------------------------------------+
|
| | | //| |
|
| | | //+------------------------------------------------------------------+
|
| | | bool CTbpBase::SendAndParse(const string& url)
|
| | | {
|
| | | //---
|
| | | m_last_err = TSN_TBP_ERR_NONE;
|
| | | const string req_headers = "api-key: " + m_api_key + "\r\n";
|
| | |
|
| | | //---
|
| | | static string res_headers;
|
| | | static uchar data[];
|
| | |
|
| | | //---
|
| | | m_last_http = WebRequest(
|
| | | "GET",
|
| | | url,
|
| | | req_headers,
|
| | | m_timeout,
|
| | | data,
|
| | | m_json.m_raw,
|
| | | res_headers
|
| | | );
|
| | |
|
| | | //---
|
| | | if(m_last_http != 200)
|
2026-05-07 16:15:15 -05:00 | | | {
|
2026-10-13 07:37:43 -05:00 | | | m_last_err = TSN_TBP_ERR_SEND_HTTP;
|
2026-05-07 16:15:15 -05:00 | | | return false;
|
| | | }
|
| | |
|
| | | //---
|
2026-06-03 12:24:19 -05:00 | | | m_json.CalcLen();
|
2026-07-19 21:44:20 -05:00 | | | m_json.CorrectPadding();
|
2026-06-03 12:24:19 -05:00 | | |
|
| | | //---
|
2026-10-13 07:37:43 -05:00 | | | if(!m_json.Parse())
|
| | | {
|
| | | m_last_err = TSN_TBP_ERR_JSON_PARSING;
|
| | | return false;
|
| | | }
|
| | | return true;
|
| | | }
|
| | |
|
| | | //+------------------------------------------------------------------+
|
| | | //| |
|
| | | //+------------------------------------------------------------------+
|
| | | bool CTbpBase::GetAllClients()
|
| | | {
|
| | | return SendAndParse(THE_BOT_PLACE_API_CUSTOMERS);
|
2026-05-07 16:15:15 -05:00 | | | }
|
2026-06-03 12:24:19 -05:00 | | | }
|
2026-05-07 16:15:15 -05:00 | | | //+------------------------------------------------------------------+
|
2026-06-03 12:24:19 -05:00 | | | #endif // TBPWRRAPER_SRC_MQL5_BASE_MQH
|