complete xea class ...
This commit is contained in:
@@ -35,10 +35,10 @@ public:
|
||||
//
|
||||
// Represent Basic Unique Tag ...
|
||||
virtual string GetTag();
|
||||
protected:
|
||||
|
||||
//
|
||||
// Retrieve Class Token ...
|
||||
string GetToken()
|
||||
virtual string GetToken()
|
||||
{
|
||||
//
|
||||
string result = NULL;
|
||||
@@ -81,6 +81,7 @@ protected:
|
||||
return result;
|
||||
}
|
||||
|
||||
protected:
|
||||
//
|
||||
// Private ...
|
||||
private:
|
||||
|
||||
@@ -2035,7 +2035,7 @@ public:
|
||||
// For Data Collector ...
|
||||
string GetToken()
|
||||
{
|
||||
return GetToken(this);
|
||||
return GetSpecificToken(this);
|
||||
}
|
||||
bool IsModelValid()
|
||||
{
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,373 @@
|
||||
///////////////////////////////////////////////////////
|
||||
//
|
||||
// SaherElm IT Center MQL5 Class Library
|
||||
// ----------------------------------------------
|
||||
// Name: XSCHttp
|
||||
// Description: provides all HTTP requirements ...
|
||||
//
|
||||
//
|
||||
// Maintainer:
|
||||
// ------------
|
||||
// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com)
|
||||
//
|
||||
//////////////////////////////////////////////////////
|
||||
//
|
||||
// Global Properties ...
|
||||
#property library
|
||||
#property copyright "Copyright 2023, SaherElm IT Center"
|
||||
#property link "https://www.saherelm.ir"
|
||||
#property version "1.00"
|
||||
#property strict
|
||||
|
||||
//
|
||||
// Definitions ...
|
||||
|
||||
//
|
||||
enum X_HTTP_METHOD
|
||||
{
|
||||
X_HTTP_GET,
|
||||
X_HTTP_POST
|
||||
};
|
||||
|
||||
//
|
||||
// Imports ...
|
||||
|
||||
//
|
||||
// Includes ...
|
||||
#include "../Classes/x-saherelm.base.class.mq5"
|
||||
#include "../Libraries/x-saherelm.common.lib.mq5"
|
||||
|
||||
//
|
||||
// a Class for Manage Account ...
|
||||
class XSCHttp : public XSCBase
|
||||
{
|
||||
//
|
||||
// Public ...
|
||||
public:
|
||||
//
|
||||
// Constructor ...
|
||||
void XSCHttp()
|
||||
{
|
||||
XSCHttp("", 10000);
|
||||
}
|
||||
void XSCHttp(
|
||||
string path, // Base Folder to Store Data
|
||||
int timeout // base timeout for Requests
|
||||
)
|
||||
{
|
||||
//
|
||||
Path(path);
|
||||
Timeout(timeout);
|
||||
}
|
||||
|
||||
//
|
||||
// Deconstructor ...
|
||||
void ~XSCHttp()
|
||||
{
|
||||
}
|
||||
|
||||
//
|
||||
// Properties Getter(s) / Setter(s) ...
|
||||
|
||||
//
|
||||
// Path ...
|
||||
void Path(string value)
|
||||
{
|
||||
//
|
||||
mPath = value;
|
||||
|
||||
//
|
||||
if (!IsValid(mPath))
|
||||
{
|
||||
mPath = GetTag();
|
||||
}
|
||||
}
|
||||
|
||||
string Path()
|
||||
{
|
||||
return mPath;
|
||||
}
|
||||
|
||||
//
|
||||
// Timeout ...
|
||||
void Timeout(int value)
|
||||
{
|
||||
mTimeout = value;
|
||||
}
|
||||
|
||||
//
|
||||
int Timeout()
|
||||
{
|
||||
return mTimeout;
|
||||
}
|
||||
|
||||
//
|
||||
// Error ...
|
||||
int Error()
|
||||
{
|
||||
return mError;
|
||||
}
|
||||
|
||||
//
|
||||
// Response ...
|
||||
string Response()
|
||||
{
|
||||
return mResponse;
|
||||
}
|
||||
|
||||
//
|
||||
// Overrides ...
|
||||
string GetTag() override
|
||||
{
|
||||
return GetSpecificToken(this);
|
||||
}
|
||||
|
||||
//
|
||||
// Tools ...
|
||||
|
||||
//
|
||||
// Send Global Request ...
|
||||
int SendRequest(
|
||||
X_HTTP_METHOD method, // Httm Request Method
|
||||
const string url, // Server Address
|
||||
const string headers, // Headers providing
|
||||
const char &payload[], // the Data which needs to Send
|
||||
char &response[], // Response of request
|
||||
string responseHeaders, // Response Headers
|
||||
int timeout = 500 // Timeout for response default is 500
|
||||
)
|
||||
{
|
||||
//
|
||||
int result = -1;
|
||||
|
||||
//
|
||||
string strMethod = ToString(method);
|
||||
if (StringLen(strMethod) == 0)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Reset State ...
|
||||
ResetState();
|
||||
|
||||
//
|
||||
result = WebRequest(
|
||||
strMethod,
|
||||
url,
|
||||
headers,
|
||||
timeout,
|
||||
payload,
|
||||
response,
|
||||
responseHeaders);
|
||||
|
||||
//
|
||||
if (result < 0)
|
||||
{
|
||||
mError = GetLastError();
|
||||
}
|
||||
else
|
||||
{
|
||||
mResponse = CharArrayToString(response);
|
||||
}
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Get Request ...
|
||||
int GetRequest(
|
||||
const string url, // Server Address
|
||||
const string headers, // Headers providing
|
||||
const char &payload[], // the Data which needs to Send
|
||||
char &response[], // Response of request
|
||||
string responseHeaders, // Response Headers
|
||||
int timeout = 500 // Timeout for response default is 500
|
||||
)
|
||||
{
|
||||
//
|
||||
int result = SendRequest(
|
||||
X_HTTP_GET,
|
||||
url,
|
||||
headers,
|
||||
payload,
|
||||
response,
|
||||
responseHeaders,
|
||||
timeout);
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Post Request ...
|
||||
int PostRequest(
|
||||
const string url, // Server Address
|
||||
const string headers, // Headers providing
|
||||
const char &payload[], // the Data which needs to Send
|
||||
char &response[], // Response of request
|
||||
string responseHeaders, // Response Headers
|
||||
int timeout = 500 // Timeout for response default is 500
|
||||
)
|
||||
{
|
||||
//
|
||||
int result = SendRequest(
|
||||
X_HTTP_POST,
|
||||
url,
|
||||
headers,
|
||||
payload,
|
||||
response,
|
||||
responseHeaders,
|
||||
timeout);
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Handle Download Specific URL Content to Specific Path and File Name ...
|
||||
bool Download(
|
||||
string url, // the URL address which going to download
|
||||
string fileName // Specify Destination file name to Store Response
|
||||
)
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
string filePath = GetFilePath(fileName);
|
||||
string cookie = NULL;
|
||||
string referer = NULL;
|
||||
int timeout = Timeout();
|
||||
|
||||
//
|
||||
char payload[];
|
||||
string headers;
|
||||
char response[];
|
||||
string responseHeaders;
|
||||
|
||||
//
|
||||
// Send Request ...
|
||||
int requestResult = GetRequest(
|
||||
url,
|
||||
headers,
|
||||
payload,
|
||||
response,
|
||||
responseHeaders,
|
||||
timeout);
|
||||
|
||||
//
|
||||
// Define File Handler ...
|
||||
int mFileHandler = FileOpen(
|
||||
filePath,
|
||||
FILE_WRITE | FILE_BIN);
|
||||
if (mFileHandler == INVALID_HANDLE)
|
||||
{
|
||||
//
|
||||
mError = GetLastError();
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Write Response to File ...
|
||||
uint writed = FileWriteArray(
|
||||
mFileHandler,
|
||||
response,
|
||||
0,
|
||||
ArraySize(response));
|
||||
FileFlush(mFileHandler);
|
||||
FileClose(mFileHandler);
|
||||
|
||||
//
|
||||
result = writed > 0;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// END Provided Functions ...
|
||||
//
|
||||
|
||||
//
|
||||
// Protected ...
|
||||
protected:
|
||||
//
|
||||
// Destintion Folder Path ...
|
||||
string mPath;
|
||||
|
||||
//
|
||||
// WEB Request Timeout Value ...
|
||||
int mTimeout;
|
||||
|
||||
//
|
||||
// WEB Request's Response ...
|
||||
string mResponse;
|
||||
|
||||
//
|
||||
// Error Value ...
|
||||
int mError;
|
||||
|
||||
//
|
||||
// Private ...
|
||||
private:
|
||||
//
|
||||
// Reset Errors State ...
|
||||
void ResetState()
|
||||
{
|
||||
//
|
||||
// Reset Errors ...
|
||||
mError = -1;
|
||||
mResponse = "";
|
||||
ResetLastError();
|
||||
}
|
||||
|
||||
//
|
||||
// Generate Full File Path ...
|
||||
string GetFilePath(string fileName)
|
||||
{
|
||||
//
|
||||
string result = "";
|
||||
|
||||
//
|
||||
result =
|
||||
//
|
||||
Path() + "\\" + fileName
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
};
|
||||
|
||||
//
|
||||
// Tools ...
|
||||
|
||||
//
|
||||
// Convert enum to String ...
|
||||
string ToString(X_HTTP_METHOD method)
|
||||
{
|
||||
//
|
||||
string result = "";
|
||||
|
||||
//
|
||||
switch (method)
|
||||
{
|
||||
//
|
||||
case X_HTTP_GET:
|
||||
result = "GET";
|
||||
break;
|
||||
|
||||
//
|
||||
case X_HTTP_POST:
|
||||
result = "POST";
|
||||
break;
|
||||
}
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
@@ -23,7 +23,6 @@
|
||||
#define ShortName "X5EA"
|
||||
|
||||
//
|
||||
#include "../Libraries/x-saherelm.log.lib.mq5"
|
||||
#include "../Libraries/x-saherelm.draw.lib.mq5"
|
||||
#include "../Libraries/x-saherelm.common.lib.mq5"
|
||||
#include "../Classes/x-saherelm.xtrade.class.mq5"
|
||||
@@ -70,7 +69,6 @@ int OnInit()
|
||||
}
|
||||
|
||||
//
|
||||
logTag = ShortName;
|
||||
drawPrefix = ShortName;
|
||||
|
||||
//
|
||||
|
||||
@@ -23,7 +23,6 @@
|
||||
#define ShortName "X5EA"
|
||||
|
||||
//
|
||||
#include "../Libraries/x-saherelm.log.lib.mq5"
|
||||
#include "../Classes/x-saherelm.x5.provider.class.mq5"
|
||||
|
||||
//
|
||||
@@ -76,9 +75,6 @@ int OnInit()
|
||||
return INIT_PARAMETERS_INCORRECT;
|
||||
}
|
||||
|
||||
//
|
||||
logTag = ShortName;
|
||||
|
||||
//
|
||||
// Initial Providers ...
|
||||
if (!InitialProviders())
|
||||
|
||||
@@ -107,10 +107,6 @@ input bool scDrawLL = true; // Draw Lowest Low
|
||||
// END Inputs ...
|
||||
//
|
||||
|
||||
//
|
||||
// Includes Logging Library ...
|
||||
#include "../Libraries/x-saherelm.log.lib.mq5";
|
||||
|
||||
//
|
||||
// Includes Common Library ...
|
||||
#include "../Libraries/x-saherelm.common.lib.mq5";
|
||||
|
||||
@@ -71,10 +71,6 @@ input bool showVerifierMa = true; // Show Verifier
|
||||
// START Includes and Imports ...
|
||||
//
|
||||
|
||||
//
|
||||
// Includes Logging Library ...
|
||||
#include "../Libraries/x-saherelm.log.lib.mq5"
|
||||
|
||||
//
|
||||
// Includes Common Library ...
|
||||
#include "../Libraries/x-saherelm.common.lib.mq5"
|
||||
@@ -169,9 +165,6 @@ int OnInit()
|
||||
return INIT_PARAMETERS_INCORRECT;
|
||||
}
|
||||
|
||||
//
|
||||
logTag = ShortName;
|
||||
|
||||
//
|
||||
// because in some cases we may have more than one input for
|
||||
// calculation and we must prevent any calculation
|
||||
@@ -201,11 +194,6 @@ int OnInit()
|
||||
fastMaAppliedTo);
|
||||
if (fastMaHandler == INVALID_HANDLE)
|
||||
{
|
||||
//
|
||||
string msg = "Error in Initilizing Indicator ...";
|
||||
LogMessage(msg);
|
||||
|
||||
//
|
||||
return INIT_FAILED;
|
||||
}
|
||||
|
||||
@@ -220,11 +208,6 @@ int OnInit()
|
||||
slowMaAppliedTo);
|
||||
if (slowMaHandler == INVALID_HANDLE)
|
||||
{
|
||||
//
|
||||
string msg = "Error in Initilizing Indicator ...";
|
||||
LogMessage(msg);
|
||||
|
||||
//
|
||||
return INIT_FAILED;
|
||||
}
|
||||
|
||||
@@ -239,11 +222,6 @@ int OnInit()
|
||||
verifierMaAppliedTo);
|
||||
if (verifierMaHandler == INVALID_HANDLE)
|
||||
{
|
||||
//
|
||||
string msg = "Error in Initilizing Indicator ...";
|
||||
LogMessage(msg);
|
||||
|
||||
//
|
||||
return INIT_FAILED;
|
||||
}
|
||||
|
||||
@@ -348,8 +326,7 @@ int OnCalculate(
|
||||
int copiedVerifierMas = CopyBuffer(verifierMaHandler, 0, 0, limit, verifierMaBuffer);
|
||||
if (copiedFastMas <= 0 ||
|
||||
copiedSlowMas <= 0 ||
|
||||
copiedVerifierMas <= 0
|
||||
)
|
||||
copiedVerifierMas <= 0)
|
||||
{
|
||||
return prev_calculated;
|
||||
}
|
||||
|
||||
@@ -1,187 +0,0 @@
|
||||
///////////////////////////////////////////////////////
|
||||
//
|
||||
// SaherElm IT Center MQL5 Alert Library
|
||||
// --------------------------------------
|
||||
// Name: XAlert
|
||||
// Description: provides Alerts abilities ...
|
||||
//
|
||||
//
|
||||
// Maintainer:
|
||||
// ------------
|
||||
// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com)
|
||||
//
|
||||
//////////////////////////////////////////////////////
|
||||
//
|
||||
// Global Properties ...
|
||||
#property library
|
||||
#property copyright "Copyright 2023, SaherElm IT Center"
|
||||
#property link "https://www.saherelm.ir"
|
||||
#property version "1.00"
|
||||
#property strict
|
||||
|
||||
//
|
||||
// START Inputs ...
|
||||
//
|
||||
input group "Alerts";
|
||||
input bool enableAlerts = true; // Enable Alerts
|
||||
input bool logAlerts = true; // Log Alerts
|
||||
input bool terminalAlerts = false; // Terminal Alerts
|
||||
input bool mailAlerts = false; // Mail Alerts
|
||||
input bool pushAlerts = false; // Push Alerts
|
||||
//
|
||||
// END Inputs ...
|
||||
//
|
||||
|
||||
//
|
||||
#include "x-saherelm.log.lib.mq5"
|
||||
|
||||
//
|
||||
// START Global Definitions: Variables, Properties and etc ...
|
||||
//
|
||||
string alertPrefix = "X-Alert";
|
||||
//
|
||||
// END Global Definitions: Variables, Properties and etc ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Provided Functions ...
|
||||
//
|
||||
//
|
||||
// Initial Library if required ...
|
||||
bool OnInInitAlertLibrary()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
//
|
||||
// DeInitial Library if required ...
|
||||
void OnDeinitAlertLibrary()
|
||||
{
|
||||
}
|
||||
|
||||
//
|
||||
// Attach Alert Prefix to Message ...
|
||||
string PrepareAlertMessage(string message)
|
||||
{
|
||||
//
|
||||
StringReplace(message, "\n", " | ");
|
||||
|
||||
//
|
||||
StringConcatenate(message, alertPrefix, " > ", message);
|
||||
|
||||
//
|
||||
return message;
|
||||
}
|
||||
|
||||
//
|
||||
// Logging an Alert ...
|
||||
void LogAlert(string message)
|
||||
{
|
||||
//
|
||||
// Validate Args ...
|
||||
if (!enableAlerts || !logAlerts)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
//
|
||||
LogMessage(alertPrefix, message);
|
||||
}
|
||||
|
||||
//
|
||||
// Terminal Alert ...
|
||||
void TerminalAlert(string message)
|
||||
{
|
||||
//
|
||||
// Validate Args ...
|
||||
if (!enableAlerts || !terminalAlerts)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
//
|
||||
// Prepare Message ...
|
||||
message = PrepareAlertMessage(message);
|
||||
|
||||
// Send Terminal Alert ...
|
||||
Alert(message);
|
||||
}
|
||||
|
||||
//
|
||||
// Mail Alert ...
|
||||
void MailAlert(string message)
|
||||
{
|
||||
//
|
||||
// Validate Args ...
|
||||
if (!enableAlerts || !mailAlerts)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
//
|
||||
// Send Mail Alert ...
|
||||
SendMail(alertPrefix, message);
|
||||
}
|
||||
|
||||
//
|
||||
// Send Push Notification ...
|
||||
void PushAlert(string message)
|
||||
{
|
||||
//
|
||||
// Validate Args ...
|
||||
if (!enableAlerts || !pushAlerts)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
//
|
||||
// Prepare Message ...
|
||||
message = PrepareAlertMessage(message);
|
||||
|
||||
//
|
||||
// Send Push Notification Alert ...
|
||||
SendNotification(message);
|
||||
}
|
||||
|
||||
//
|
||||
// Alert Sending ...
|
||||
void SendAlert(string message)
|
||||
{
|
||||
//
|
||||
// Validate Args ...
|
||||
if (!enableAlerts)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
//
|
||||
// Log ...
|
||||
if (logAlerts)
|
||||
{
|
||||
LogAlert(message);
|
||||
}
|
||||
|
||||
//
|
||||
// Terminal ...
|
||||
if (terminalAlerts)
|
||||
{
|
||||
TerminalAlert(message);
|
||||
}
|
||||
|
||||
//
|
||||
// Mail ...
|
||||
if (mailAlerts)
|
||||
{
|
||||
MailAlert(message);
|
||||
}
|
||||
|
||||
//
|
||||
// Push ...
|
||||
if (pushAlerts)
|
||||
{
|
||||
PushAlert(message);
|
||||
}
|
||||
}
|
||||
//
|
||||
// END Provided Functions ...
|
||||
//
|
||||
@@ -3877,6 +3877,49 @@ string GetToken(T &item)
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Same as Get Token for Use in Classes ...
|
||||
template <typename T>
|
||||
string GetSpecificToken(T &item)
|
||||
{
|
||||
//
|
||||
string mType = GetTypeName(item);
|
||||
|
||||
//
|
||||
string result = mType;
|
||||
|
||||
//
|
||||
string parts[];
|
||||
int partsCount = SplitContent(
|
||||
parts,
|
||||
result,
|
||||
" "
|
||||
//
|
||||
);
|
||||
if (partsCount <= 0)
|
||||
{
|
||||
//
|
||||
result = mType;
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
bool hasLastPart = GetLastItem(
|
||||
result,
|
||||
parts
|
||||
//
|
||||
);
|
||||
if (!hasLastPart)
|
||||
{
|
||||
//
|
||||
result = mType;
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Generate Unique Tags ...
|
||||
template <typename T>
|
||||
@@ -4874,29 +4917,32 @@ bool Contains(
|
||||
// Validate Queries ...
|
||||
int queriesCount = ArraySize(mQueries);
|
||||
result = queriesCount > 0;
|
||||
if (!result) {
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Validate Content ...
|
||||
result = IsValid(mContent);
|
||||
if (!result) {
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
int containsCount = 0;
|
||||
for (int i = 0; i < queriesCount; i++) {
|
||||
for (int i = 0; i < queriesCount; i++)
|
||||
{
|
||||
//
|
||||
bool isContains = Contains(
|
||||
mQueries[i],
|
||||
mContent,
|
||||
ignoreCase
|
||||
);
|
||||
ignoreCase);
|
||||
|
||||
//
|
||||
if (!isContains) {
|
||||
if (!isContains)
|
||||
{
|
||||
//
|
||||
result = false;
|
||||
break;
|
||||
|
||||
@@ -1,177 +0,0 @@
|
||||
///////////////////////////////////////////////////////
|
||||
//
|
||||
// SaherElm IT Center MQL5 Http Library
|
||||
// ------------------------------------------
|
||||
// Name: XHttp
|
||||
// Description: provide http communication
|
||||
// abilities ...
|
||||
//
|
||||
//
|
||||
// Maintainer:
|
||||
// ------------
|
||||
// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com)
|
||||
//
|
||||
//////////////////////////////////////////////////////
|
||||
//
|
||||
// Global Properties ...
|
||||
#property library
|
||||
#property copyright "Copyright 2023, SaherElm IT Center"
|
||||
#property link "https://www.saherelm.ir"
|
||||
#property version "1.00"
|
||||
#property strict
|
||||
|
||||
//
|
||||
// START Model Definition ...
|
||||
//
|
||||
enum X_HTTP_METHOD
|
||||
{
|
||||
X_HTTP_GET,
|
||||
X_HTTP_POST
|
||||
};
|
||||
//
|
||||
// END Model Definition ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Inputs ...
|
||||
//
|
||||
//
|
||||
// END Inputs ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Global Definitions: Variables, Properties and etc ...
|
||||
//
|
||||
//
|
||||
// END Global Definitions: Variables, Properties and etc ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Provided Functions ...
|
||||
//
|
||||
//
|
||||
// Initial Library if required ...
|
||||
bool OnInInitHttpLibrary()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
//
|
||||
// DeInitial Library if required ...
|
||||
void OnDeinitHttpLibrary()
|
||||
{
|
||||
}
|
||||
|
||||
//
|
||||
// Convert enum to String ...
|
||||
string ToString(X_HTTP_METHOD method)
|
||||
{
|
||||
//
|
||||
string result = "";
|
||||
|
||||
//
|
||||
switch (method)
|
||||
{
|
||||
//
|
||||
case X_HTTP_GET:
|
||||
result = "GET";
|
||||
break;
|
||||
|
||||
//
|
||||
case X_HTTP_POST:
|
||||
result = "POST";
|
||||
break;
|
||||
}
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Send Global Request ...
|
||||
int SendRequest(
|
||||
X_HTTP_METHOD method, // Httm Request Method
|
||||
const string url, // Server Address
|
||||
const string headers, // Headers providing
|
||||
const char &payload[], // the Data which needs to Send
|
||||
char &response[], // Response of request
|
||||
string responseHeaders, // Response Headers
|
||||
int timeout = 500 // Timeout for response default is 500
|
||||
)
|
||||
{
|
||||
//
|
||||
int result = -1;
|
||||
|
||||
//
|
||||
string strMethod = ToString(method);
|
||||
if (StringLen(strMethod) == 0) {
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
result = WebRequest(
|
||||
strMethod,
|
||||
url,
|
||||
headers,
|
||||
timeout,
|
||||
payload,
|
||||
response,
|
||||
responseHeaders
|
||||
);
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Get Request ...
|
||||
int GetRequest(
|
||||
const string url, // Server Address
|
||||
const string headers, // Headers providing
|
||||
const char &payload[], // the Data which needs to Send
|
||||
char &response[], // Response of request
|
||||
string responseHeaders, // Response Headers
|
||||
int timeout = 500 // Timeout for response default is 500
|
||||
) {
|
||||
//
|
||||
int result = SendRequest(
|
||||
X_HTTP_GET,
|
||||
url,
|
||||
headers,
|
||||
payload,
|
||||
response,
|
||||
responseHeaders,
|
||||
timeout
|
||||
);
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Post Request ...
|
||||
int PostRequest(
|
||||
const string url, // Server Address
|
||||
const string headers, // Headers providing
|
||||
const char &payload[], // the Data which needs to Send
|
||||
char &response[], // Response of request
|
||||
string responseHeaders, // Response Headers
|
||||
int timeout = 500 // Timeout for response default is 500
|
||||
) {
|
||||
//
|
||||
int result = SendRequest(
|
||||
X_HTTP_POST,
|
||||
url,
|
||||
headers,
|
||||
payload,
|
||||
response,
|
||||
responseHeaders,
|
||||
timeout
|
||||
);
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
//
|
||||
// END Provided Functions ...
|
||||
//
|
||||
File diff suppressed because it is too large
Load Diff
@@ -53,6 +53,9 @@ string XSymbolToken = "SMBL";
|
||||
string XSupportToken = "SP";
|
||||
string XEQMSupportToken = "EQM";
|
||||
|
||||
//
|
||||
string XSLTrailToken = "SLT";
|
||||
|
||||
//
|
||||
string XActionToken = "A";
|
||||
|
||||
@@ -107,6 +110,19 @@ enum ENUM_X_SIGNAL_MANAGING_ACTIONS
|
||||
X_SIGNAL_PARTIAL_TRAIL, // Use 0 index as SL and Trail Stop on TP Levels and also Partial Close on TP Levels
|
||||
};
|
||||
|
||||
//
|
||||
// Available Guard Action ...
|
||||
enum ENUM_X_GUARD_ACTIONS
|
||||
{
|
||||
X_GUARD_ACTION_NOTHING, // Nothing
|
||||
X_GUARD_ACTION_HEDGE, // Hedge
|
||||
X_GUARD_PARTIAL_CLOSE, // Partial Close
|
||||
X_GUARD_ACTION_TRAIL_STOP, // Trail StopLoss
|
||||
X_GUARD_ACTION_FORCE_CLOSE, // Force Close
|
||||
X_GUARD_ACTION_ADD_SUPPORT_SIGNAL, // Add Support Signal
|
||||
X_GUARD_ACTION_CANCEL_PENDING_ORDERS, // Cancel Pending Orders
|
||||
};
|
||||
|
||||
//
|
||||
// Structs ...
|
||||
|
||||
@@ -2427,6 +2443,96 @@ struct XOnTradeHandlerState
|
||||
}
|
||||
};
|
||||
|
||||
//
|
||||
// Model Guard Info ...
|
||||
struct XGuard
|
||||
{
|
||||
//
|
||||
string symbol; // Trading Symbol ...
|
||||
string provider; // Signal Provider ...
|
||||
ENUM_TIMEFRAMES period; // Trading Timeframe ...
|
||||
ENUM_POSITION_TYPE type; // Position Type ...
|
||||
ENUM_X_GUARD_ACTIONS action; // Which Action to Do ...
|
||||
|
||||
//
|
||||
double dblPayLoad;
|
||||
string strPayload;
|
||||
|
||||
//
|
||||
// Constructor ...
|
||||
XGuard()
|
||||
{
|
||||
Clean();
|
||||
}
|
||||
|
||||
//
|
||||
// Initialize ...
|
||||
|
||||
//
|
||||
// Global Initializer ...
|
||||
bool Init(
|
||||
string mSymbol, // Trading Symbol ...
|
||||
ENUM_TIMEFRAMES mPeriod, // Trading Timeframe ...
|
||||
ENUM_X_GUARD_ACTIONS mAction, // Which Action to Do ...
|
||||
ENUM_POSITION_TYPE mType = NULL, // Position Type ...
|
||||
string mProvider = NULL, // Signal Provider ...
|
||||
double mDblPayLoad = NULL,
|
||||
string mStrPayload = NULL //
|
||||
)
|
||||
{
|
||||
//
|
||||
type = mType;
|
||||
symbol = mSymbol;
|
||||
period = mPeriod;
|
||||
action = mAction;
|
||||
provider = mProvider;
|
||||
dblPayLoad = mDblPayLoad;
|
||||
strPayload = mStrPayload;
|
||||
|
||||
//
|
||||
bool result = IsValid();
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Tools ...
|
||||
|
||||
//
|
||||
// Cleanup ...
|
||||
void Clean()
|
||||
{
|
||||
//
|
||||
symbol = NULL;
|
||||
provider = NULL;
|
||||
period = NULL;
|
||||
action = X_GUARD_ACTION_NOTHING;
|
||||
|
||||
//
|
||||
strPayload = NULL;
|
||||
dblPayLoad = EMPTY_VALUE;
|
||||
}
|
||||
|
||||
//
|
||||
// Validate ...
|
||||
bool IsValid()
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
result =
|
||||
//
|
||||
action != X_GUARD_ACTION_NOTHING
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
};
|
||||
|
||||
//
|
||||
// Model a Position with all of it's Supports ...
|
||||
struct XPositionPack
|
||||
@@ -3717,6 +3823,73 @@ int FindIndex(
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Retrieve String Representation ...
|
||||
string ToString(ENUM_X_SIGNAL_EXECUTION_RESULT value)
|
||||
{
|
||||
//
|
||||
string result = NULL;
|
||||
|
||||
//
|
||||
switch (value)
|
||||
{
|
||||
//
|
||||
case X_SIGNAL_EXECUTION_UNKNOWN:
|
||||
result = "Unknown";
|
||||
break;
|
||||
|
||||
//
|
||||
case X_SIGNAL_EXECUTION_SUCCEED:
|
||||
result = "Succed";
|
||||
break;
|
||||
|
||||
//
|
||||
case X_SIGNAL_EXECUTION_FAILED_SPREAD:
|
||||
result = "Spread more than Max Allowed";
|
||||
break;
|
||||
|
||||
//
|
||||
case X_SIGNAL_EXECUTION_FAILED_NO_EQUITY:
|
||||
result = "No Equity for Trade";
|
||||
break;
|
||||
|
||||
//
|
||||
case X_SIGNAL_EXECUTION_FAILED_PRICE_ERROR:
|
||||
result = "Price Error";
|
||||
break;
|
||||
|
||||
//
|
||||
case X_SIGNAL_EXECUTION_FAILED_MAX_REACHED:
|
||||
result = "Max Allowed Positions Reached";
|
||||
break;
|
||||
|
||||
//
|
||||
case X_SIGNAL_EXECUTION_FAILED_INVALID_PARAMS:
|
||||
result = "Invalid Params";
|
||||
break;
|
||||
}
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Converts Position Type to Order Type ...
|
||||
ENUM_ORDER_TYPE ToOrderType(ENUM_POSITION_TYPE value)
|
||||
{
|
||||
//
|
||||
bool isLong = IsLong(value);
|
||||
|
||||
//
|
||||
ENUM_ORDER_TYPE result =
|
||||
isLong
|
||||
? ORDER_TYPE_BUY
|
||||
: ORDER_TYPE_SELL;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Tagging ...
|
||||
|
||||
@@ -3830,3 +4003,96 @@ ulong ExtractEQMSupportedTicket(string value)
|
||||
}
|
||||
|
||||
//
|
||||
// SL Trails ...
|
||||
|
||||
//
|
||||
// Extract SL Trail Level ...
|
||||
int ExtractSLTrailLevel(string comment)
|
||||
{
|
||||
//
|
||||
int result = 0;
|
||||
|
||||
//
|
||||
if (!IsValid(comment))
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
result = ParseIntSurrounded(
|
||||
comment,
|
||||
XSLTrailToken
|
||||
//
|
||||
);
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Generate SL Trail Comment Tag ...
|
||||
string GenerateSLTrailTag(int level)
|
||||
{
|
||||
//
|
||||
string result = NULL;
|
||||
|
||||
//
|
||||
if (level <= 0)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
result = Surround(
|
||||
XSLTrailToken,
|
||||
level
|
||||
//
|
||||
);
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Prepare SL Trail Comment ...
|
||||
string PrepareSLTrailTag(
|
||||
const string comment // Original Position Comment ...
|
||||
)
|
||||
{
|
||||
//
|
||||
string result = NULL;
|
||||
|
||||
//
|
||||
int level = 0;
|
||||
result = comment;
|
||||
|
||||
//
|
||||
// Check Comment Contains SL Trailing or not ...
|
||||
int lastTrailLevel = ExtractSLTrailLevel(comment);
|
||||
if (lastTrailLevel <= 0)
|
||||
{
|
||||
level++;
|
||||
}
|
||||
else
|
||||
{
|
||||
//
|
||||
level = lastTrailLevel + 1;
|
||||
string lastLevelStr = GenerateSLTrailTag(lastTrailLevel);
|
||||
StringReplace(
|
||||
result,
|
||||
lastLevelStr,
|
||||
""
|
||||
//
|
||||
);
|
||||
}
|
||||
|
||||
//
|
||||
// Generate level Comment ...
|
||||
string levelStr = GenerateSLTrailTag(level);
|
||||
result += levelStr;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
|
||||
Reference in New Issue
Block a user