Files
MQL5Data/Classes/x-saherelm.x-alert.class.mq5
T
saherelm e46cac2ab1 - Create a Data Collector Class;
- Add Support for Save Logs in Alert Class;
- Add Propper inputs for Handle Saving Logs in EA and Expert Class;
- remove x-trade.manager Class Data Collector and use General Developed Data Collector;
- Add Support for Reading Fles in Data Collector Class for Support Configuration Parsing;
- Remove XCBaseAlert class and add Support for get XCAlert instance reference pointer as Dependency Injection in all used classed and Refactor all Changes;
- Apply Fix some UnImplemented Event Handlers on Ea Expert Class of XCATBEA and also change Event Handler Binding to Collection Based Model;
- Test all Functionalities ...
- Apply Some Fixes on Prevent Double Saing Same Log Messages ...
2025-06-05 05:35:47 +03:30

1438 lines
33 KiB
Plaintext

///////////////////////////////////////////////////////
//
// SaherElm IT Center MQL5 Class Library
// ----------------------------------------------
// Name: XSCAlert
// Description: provides all Alerts 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
//
// Imports ...
#include "../Classes/x-saherelm.base.class.mq5"
#include "../Classes/x-saherelm.x-data.collector.class.mq5"
//
// Class Definition ...
class XCAlert : public XCBase
{
//
// Public ...
public:
//
// Props ...
//
// Constructor ...
XCAlert(
string prefix = "X-Alert", // Alerts Prefixe
bool enableAlerts = true, // Enable Alerts
bool logAlerts = true, // Log Alerts
bool terminalAlerts = false, // Terminal Alerts
bool mailAlerts = false, // Mail Alerts
bool pushAlerts = false, // Push Alerts
bool saveAlerts = false // Save Alerts
)
{
//
mPrefix = prefix;
mLogAlerts = logAlerts;
mMailAlerts = mailAlerts;
mPushAlerts = pushAlerts;
mSaveAlerts = saveAlerts;
mEnableAlerts = enableAlerts;
mTerminalAlerts = terminalAlerts;
//
// Normalize Prefix if Not Provided ...
if (!IsValid(mPrefix))
{
mPrefix = GetTag();
}
//
// Initialize Collector ...
collector = new XCDataCollector();
collector.Path(mPrefix);
}
//
// Deconstructor ...
~XCAlert()
{
//
// Cleanup Resources ...
delete collector;
ZeroMemory(collector);
}
//
// Override ...
string GetTag() override
{
return GetSpecificToken(this);
}
//
// Properties Getter(s) / Setter(s) ...
//
string GetPrefix()
{
return mPrefix;
}
//
void SetPrefix(string value)
{
//
mPrefix = value;
collector.Path(mPrefix);
}
//
bool GetLogAlerts()
{
return mLogAlerts;
}
//
void SetLogAlerts(bool value)
{
mLogAlerts = value;
}
//
bool GetEnableAlerts()
{
return mEnableAlerts;
}
//
void SetEnableAlerts(bool value)
{
mEnableAlerts = value;
}
//
bool GetSaveAlerts()
{
return mSaveAlerts;
}
//
void SetSaveAlerts(bool value)
{
mSaveAlerts = value;
}
//
bool GetPushAlerts()
{
return mPushAlerts;
}
//
void SetPushAlerts(bool value)
{
mPushAlerts = value;
}
//
bool GetMailAlerts()
{
return mMailAlerts;
}
//
void SetMailAlerts(bool value)
{
mMailAlerts = value;
}
//
bool GetTerminalAlerts()
{
return mTerminalAlerts;
}
//
void SetTerminalAlerts(bool value)
{
mTerminalAlerts = value;
}
//
// Tools Funtions ...
//
// Alerts ...
//
// Logging an Alert ...
void LogAlert(string message)
{
//
// Validate Args ...
if (!CanLogAlert())
{
return;
}
//
message = PrepareMessage(message);
//
Log(message);
Save(message);
}
//
// Terminal Alert ...
void TerminalAlert(string message)
{
//
// Validate Args ...
if (!CanTerminalAlert())
{
return;
}
//
// Prepare Message ...
message = PrepareMessage(message);
// Send Terminal Alert ...
Alert(message);
Save(message);
}
//
// Mail Alert ...
void MailAlert(string message)
{
//
// Validate Args ...
if (!CanMailAlert())
{
return;
}
//
// Send Mail Alert ...
SendMail(GetPrefix(), message);
Save(message);
}
//
// Send Push Notification ...
void PushAlert(string message)
{
//
// Validate Args ...
if (!CanPushAlert())
{
return;
}
//
// Prepare Message ...
message = PrepareMessage(message);
//
// Send Push Notification Alert ...
SendNotification(message);
Save(message);
}
//
// Send an Alert by Handling all Different Specified
// type's of Alert's if they are Enabled ...
void SendAlert(string message)
{
//
// Handle Log, if Enabled ...
LogAlert(message);
//
// Handle Mail if Enabled ...
MailAlert(message);
//
// Handle Push if Enabled ...
PushAlert(message);
//
// Handle Terminal if Enabled ...
TerminalAlert(message);
}
//
// Logs ...
//
// Log a Message ...
void Log(string message)
{
//
if (!CanLog())
{
return;
}
//
Print(GetPrefix(), " > ", message);
}
void Log(string tag, string message)
{
//
if (!CanLog())
{
return;
}
//
Print(GetPrefix(), "_", tag, " > ", message);
}
void LogEmpty()
{
//
if (!CanLog())
{
return;
}
//
Print(" ");
}
//
// Log Specific Array ...
template <typename T>
void LogArray(
T &array[], // Array to Log
string label = NULL // Array Label
)
{
//
if (!CanLog())
{
return;
}
//
Print(GetPrefix(), ">", (IsValid(label) ? label : ""));
ArrayPrint(array);
}
//
// Error ...
//
// Log an Error ...
void LogError(
int error = -1 // Specific Error, if it's equal to -1, use Last Error ...
)
{
//
if (!CanLog())
{
return;
}
//
if (error <= -1)
{
error = GetLastError();
}
//
string errorMsg = GetErrorDescription(error);
//
Log("Error: " + errorMsg);
}
//
// Retrieve Specified Error Code Description ...
string GetErrorDescription(int err_code)
{
//
string result = "";
//
switch (err_code)
{
//
//--- Constant Description
//
case ERR_SUCCESS:
result = "The operation completed successfully";
break;
//
case ERR_INTERNAL_ERROR:
result = "Unexpected internal error";
break;
//
case ERR_WRONG_INTERNAL_PARAMETER:
result = "Wrong parameter in the inner call of the client terminal function";
break;
//
case ERR_INVALID_PARAMETER:
result = "Wrong parameter when calling the system function";
break;
//
case ERR_NOT_ENOUGH_MEMORY:
result = "Not enough memory to perform the system function";
break;
//
case ERR_STRUCT_WITHOBJECTS_ORCLASS:
result = "The structure contains objects of strings and/or dynamic arrays and/or structure of such objects and/or classes";
break;
//
case ERR_INVALID_ARRAY:
result = "Array of a wrong type, wrong size, or a damaged object of a dynamic array";
break;
//
case ERR_ARRAY_RESIZE_ERROR:
result = "Not enough memory for the relocation of an array, or an attempt to change the size of a static array";
break;
//
case ERR_STRING_RESIZE_ERROR:
result = "Not enough memory for the relocation of string";
break;
//
case ERR_NOTINITIALIZED_STRING:
result = "Not initialized string";
break;
//
case ERR_INVALID_DATETIME:
result = "Invalid date and/or time";
break;
//
case ERR_ARRAY_BAD_SIZE:
result = "Requested array size exceeds 2 GB";
break;
//
case ERR_INVALID_POINTER:
result = "Wrong pointer";
break;
//
case ERR_INVALID_POINTER_TYPE:
result = "Wrong type of pointer";
break;
//
case ERR_FUNCTION_NOT_ALLOWED:
result = "System function is not allowed to call";
break;
//
//--- Charts
//
case ERR_CHART_WRONG_ID:
result = "Wrong chart ID";
break;
//
case ERR_CHART_NO_REPLY:
result = "Chart does not respond";
break;
//
case ERR_CHART_NOT_FOUND:
result = "Chart not found";
break;
//
case ERR_CHART_NO_EXPERT:
result = "No Expert Advisor in the chart that could handle the event";
break;
//
case ERR_CHART_CANNOT_OPEN:
result = "Chart opening error";
break;
//
case ERR_CHART_CANNOT_CHANGE:
result = "Failed to change chart symbol and period";
break;
//
case ERR_CHART_CANNOT_CREATE_TIMER:
result = "Failed to create timer";
break;
//
case ERR_CHART_WRONG_PROPERTY:
result = "Wrong chart property ID";
break;
//
case ERR_CHART_SCREENSHOT_FAILED:
result = "Error creating screenshots";
break;
//
case ERR_CHART_NAVIGATE_FAILED:
result = "Error navigating through chart";
break;
//
case ERR_CHART_TEMPLATE_FAILED:
result = "Error applying template";
break;
//
case ERR_CHART_WINDOW_NOT_FOUND:
result = "Subwindow containing the indicator was not found";
break;
//
case ERR_CHART_INDICATOR_CANNOT_ADD:
result = "Error adding an indicator to chart";
break;
//
case ERR_CHART_INDICATOR_CANNOT_DEL:
result = "Error deleting an indicator from the chart";
break;
//
case ERR_CHART_INDICATOR_NOT_FOUND:
result = "Indicator not found on the specified chart";
break;
//
//--- Graphical Objects
case ERR_OBJECT_ERROR:
result = "Error working with a graphical object";
break;
//
case ERR_OBJECT_NOT_FOUND:
result = "Graphical object was not found";
break;
//
case ERR_OBJECT_WRONG_PROPERTY:
result = "Wrong ID of a graphical object property";
break;
//
case ERR_OBJECT_GETDATE_FAILED:
result = "Unable to get date corresponding to the value";
break;
//
case ERR_OBJECT_GETVALUE_FAILED:
result = "Unable to get value corresponding to the date";
break;
//
//--- MarketInfo
//
case ERR_MARKET_UNKNOWN_SYMBOL:
result = "Unknown symbol";
break;
//
case ERR_MARKET_NOT_SELECTED:
result = "Symbol is not selected in MarketWatch";
break;
//
case ERR_MARKET_WRONG_PROPERTY:
result = "Wrong identifier of a symbol property";
break;
//
case ERR_MARKET_LASTTIME_UNKNOWN:
result = "Time of the last tick is not known (no ticks)";
break;
//
case ERR_MARKET_SELECT_ERROR:
result = "Error adding or deleting a symbol in MarketWatch";
break;
//
//--- History Access
//
case ERR_HISTORY_NOT_FOUND:
result = "Requested history not found";
break;
//
case ERR_HISTORY_WRONG_PROPERTY:
result = "Wrong ID of the history property";
break;
//
//--- Global_Variables
//
case ERR_GLOBALVARIABLE_NOT_FOUND:
result = "Global variable of the client terminal is not found";
break;
//
case ERR_GLOBALVARIABLE_EXISTS:
result = "Global variable of the client terminal with the same name already exists";
break;
//
case ERR_MAIL_SEND_FAILED:
result = "Email sending failed";
break;
//
case ERR_PLAY_SOUND_FAILED:
result = "Sound playing failed";
break;
//
case ERR_MQL5_WRONG_PROPERTY:
result = "Wrong identifier of the program property";
break;
//
case ERR_TERMINAL_WRONG_PROPERTY:
result = "Wrong identifier of the terminal property";
break;
//
case ERR_FTP_SEND_FAILED:
result = "File sending via ftp failed";
break;
//
case ERR_NOTIFICATION_SEND_FAILED:
result = "Error in sending notification";
break;
//
//--- Custom Indicator Buffers
//
case ERR_BUFFERS_NO_MEMORY:
result = "Not enough memory for the distribution of indicator buffers";
break;
//
case ERR_BUFFERS_WRONG_INDEX:
result = "Wrong indicator buffer index";
break;
//
//--- Custom Indicator Properties
//
case ERR_CUSTOM_WRONG_PROPERTY:
result = "Wrong ID of the custom indicator property";
break;
//
//--- Account
//
case ERR_ACCOUNT_WRONG_PROPERTY:
result = "Wrong account property ID";
break;
//
case ERR_TRADE_WRONG_PROPERTY:
result = "Wrong trade property ID";
break;
//
case ERR_TRADE_DISABLED:
result = "Trading by Expert Advisors prohibited";
break;
//
case ERR_TRADE_POSITION_NOT_FOUND:
result = "Position not found";
break;
//
case ERR_TRADE_ORDER_NOT_FOUND:
result = "Order not found";
break;
//
case ERR_TRADE_DEAL_NOT_FOUND:
result = "Deal not found";
break;
//
case ERR_TRADE_SEND_FAILED:
result = "Trade request sending failed";
break;
//
//--- Indicators
//
case ERR_INDICATOR_UNKNOWN_SYMBOL:
result = "Unknown symbol";
break;
//
case ERR_INDICATOR_CANNOT_CREATE:
result = "Indicator cannot be created";
break;
//
case ERR_INDICATOR_NO_MEMORY:
result = "Not enough memory to add the indicator";
break;
//
case ERR_INDICATOR_CANNOT_APPLY:
result = "The indicator cannot be applied to another indicator";
break;
//
case ERR_INDICATOR_CANNOT_ADD:
result = "Error applying an indicator to chart";
break;
//
case ERR_INDICATOR_DATA_NOT_FOUND:
result = "Requested data not found";
break;
//
case ERR_INDICATOR_WRONG_HANDLE:
result = "Wrong indicator handle";
break;
//
case ERR_INDICATOR_WRONG_PARAMETERS:
result = "Wrong number of parameters when creating an indicator";
break;
//
case ERR_INDICATOR_PARAMETERS_MISSING:
result = "No parameters when creating an indicator";
break;
//
case ERR_INDICATOR_CUSTOM_NAME:
result = "The first parameter in the array must be the name of the custom indicator";
break;
//
case ERR_INDICATOR_PARAMETER_TYPE:
result = "Invalid parameter type in the array when creating an indicator";
break;
//
case ERR_INDICATOR_WRONG_INDEX:
result = "Wrong index of the requested indicator buffer";
break;
//
//--- Depth of Market
//
case ERR_BOOKS_CANNOT_ADD:
result = "Depth Of Market can not be added";
break;
//
case ERR_BOOKS_CANNOT_DELETE:
result = "Depth Of Market can not be removed";
break;
//
case ERR_BOOKS_CANNOT_GET:
result = "The data from Depth Of Market can not be obtained";
break;
//
case ERR_BOOKS_CANNOT_SUBSCRIBE:
result = "Error in subscribing to receive new data from Depth Of Market";
break;
//
//--- File Operations
//
case ERR_TOO_MANY_FILES:
result = "More than 64 files cannot be opened at the same time";
break;
//
case ERR_WRONG_FILENAME:
result = "Invalid file name";
break;
//
case ERR_TOO_LONG_FILENAME:
result = "Too long file name";
break;
//
case ERR_CANNOT_OPEN_FILE:
result = "File opening error";
break;
//
case ERR_FILE_CACHEBUFFER_ERROR:
result = "Not enough memory for cache to read";
break;
//
case ERR_CANNOT_DELETE_FILE:
result = "File deleting error";
break;
//
case ERR_INVALID_FILEHANDLE:
result = "A file with this handle was closed, or was not opening at all";
break;
//
case ERR_WRONG_FILEHANDLE:
result = "Wrong file handle";
break;
//
case ERR_FILE_NOTTOWRITE:
result = "The file must be opened for writing";
break;
//
case ERR_FILE_NOTTOREAD:
result = "The file must be opened for reading";
break;
//
case ERR_FILE_NOTBIN:
result = "The file must be opened as a binary one";
break;
//
case ERR_FILE_NOTTXT:
result = "The file must be opened as a text";
break;
//
case ERR_FILE_NOTTXTORCSV:
result = "The file must be opened as a text or CSV";
break;
//
case ERR_FILE_NOTCSV:
result = "The file must be opened as CSV";
break;
//
case ERR_FILE_READERROR:
result = "File reading error";
break;
//
case ERR_FILE_BINSTRINGSIZE:
result = "String size must be specified, because the file is opened as binary";
break;
//
case ERR_INCOMPATIBLE_FILE:
result = "A text file must be for string arrays, for other arrays - binary";
break;
//
case ERR_FILE_IS_DIRECTORY:
result = "This is not a file, this is a directory";
break;
//
case ERR_FILE_NOT_EXIST:
result = "File does not exist";
break;
//
case ERR_FILE_CANNOT_REWRITE:
result = "File can not be rewritten";
break;
//
case ERR_WRONG_DIRECTORYNAME:
result = "Wrong directory name";
break;
//
case ERR_DIRECTORY_NOT_EXIST:
result = "Directory does not exist";
break;
//
case ERR_FILE_ISNOT_DIRECTORY:
result = "This is a file, not a directory";
break;
//
case ERR_CANNOT_DELETE_DIRECTORY:
result = "The directory cannot be removed";
break;
//
case ERR_CANNOT_CLEAN_DIRECTORY:
result = "Failed to clear the directory (probably one or more files are blocked and removal operation failed)";
break;
//
case ERR_FILE_WRITEERROR:
result = "Failed to write a resource to a file";
break;
//
//--- String Casting
//
case ERR_NO_STRING_DATE:
result = "No date in the string";
break;
//
case ERR_WRONG_STRING_DATE:
result = "Wrong date in the string";
break;
//
case ERR_WRONG_STRING_TIME:
result = "Wrong time in the string";
break;
//
case ERR_STRING_TIME_ERROR:
result = "Error converting string to date";
break;
//
case ERR_STRING_OUT_OF_MEMORY:
result = "Not enough memory for the string";
break;
//
case ERR_STRING_SMALL_LEN:
result = "The string length is less than expected";
break;
//
case ERR_STRING_TOO_BIGNUMBER:
result = "Too large number, more than ULONG_MAX";
break;
//
case ERR_WRONG_FORMATSTRING:
result = "Invalid format string";
break;
//
case ERR_TOO_MANY_FORMATTERS:
result = "Amount of format specifiers more than the parameters";
break;
//
case ERR_TOO_MANY_PARAMETERS:
result = "Amount of parameters more than the format specifiers";
break;
//
case ERR_WRONG_STRING_PARAMETER:
result = "Damaged parameter of string type";
break;
//
case ERR_STRINGPOS_OUTOFRANGE:
result = "Position outside the string";
break;
//
case ERR_STRING_ZEROADDED:
result = "0 added to the string end, a useless operation";
break;
//
case ERR_STRING_UNKNOWNTYPE:
result = "Unknown data type when converting to a string";
break;
//
case ERR_WRONG_STRING_OBJECT:
result = "Damaged string object";
break;
//
//--- Operations with Arrays
//
case ERR_INCOMPATIBLE_ARRAYS:
result = "Copying incompatible arrays. String array can be copied only to a string array, and a numeric array - in numeric array only";
break;
//
case ERR_SMALL_ASSERIES_ARRAY:
result = "The receiving array is declared as AS_SERIES, and it is of insufficient size";
break;
//
case ERR_SMALL_ARRAY:
result = "Too small array, the starting position is outside the array";
break;
//
case ERR_ZEROSIZE_ARRAY:
result = "An array of zero length";
break;
//
case ERR_NUMBER_ARRAYS_ONLY:
result = "Must be a numeric array";
break;
//
case ERR_ONEDIM_ARRAYS_ONLY:
result = "Must be a one-dimensional array";
break;
//
case ERR_SERIES_ARRAY:
result = "Timeseries cannot be used";
break;
//
case ERR_DOUBLE_ARRAY_ONLY:
result = "Must be an array of type double";
break;
//
case ERR_FLOAT_ARRAY_ONLY:
result = "Must be an array of type float";
break;
//
case ERR_LONG_ARRAY_ONLY:
result = "Must be an array of type long";
break;
//
case ERR_INT_ARRAY_ONLY:
result = "Must be an array of type int";
break;
//
case ERR_SHORT_ARRAY_ONLY:
result = "Must be an array of type short";
break;
//
case ERR_CHAR_ARRAY_ONLY:
result = "Must be an array of type char";
break;
//
//--- Operations with OpenCL
//
case ERR_OPENCL_NOT_SUPPORTED:
result = "OpenCL functions are not supported on this computer";
break;
//
case ERR_OPENCL_INTERNAL:
result = "Internal error occurred when running OpenCL";
break;
//
case ERR_OPENCL_INVALID_HANDLE:
result = "Invalid OpenCL handle";
break;
//
case ERR_OPENCL_CONTEXT_CREATE:
result = "Error creating the OpenCL context";
break;
//
case ERR_OPENCL_QUEUE_CREATE:
result = "Failed to create a run queue in OpenCL";
break;
//
case ERR_OPENCL_PROGRAM_CREATE:
result = "Error occurred when compiling an OpenCL program";
break;
//
case ERR_OPENCL_TOO_LONG_KERNEL_NAME:
result = "Too long kernel name (OpenCL kernel)";
break;
//
case ERR_OPENCL_KERNEL_CREATE:
result = "Error creating an OpenCL kernel";
break;
//
case ERR_OPENCL_SET_KERNEL_PARAMETER:
result = "Error occurred when setting parameters for the OpenCL kernel";
break;
//
case ERR_OPENCL_EXECUTE:
result = "OpenCL program runtime error";
break;
//
case ERR_OPENCL_WRONG_BUFFER_SIZE:
result = "Invalid size of the OpenCL buffer";
break;
//
case ERR_OPENCL_WRONG_BUFFER_OFFSET:
result = "Invalid offset in the OpenCL buffer";
break;
//
case ERR_OPENCL_BUFFER_CREATE:
result = "Failed to create and OpenCL buffer";
break;
//
//--- User-Defined Errors
default:
result = "UNKNOWN Erro ...";
break;
}
//
return result;
}
//
// Retrieve Specified Error Code Description ...
string GetTradeServerReturnCodeDescription(int return_code)
{
//
string result = "";
//
switch (return_code)
{
//
case TRADE_RETCODE_REQUOTE:
result = "Requote";
break;
//
case TRADE_RETCODE_REJECT:
result = "Request rejected";
break;
//
case TRADE_RETCODE_CANCEL:
result = "Request canceled by trader";
break;
//
case TRADE_RETCODE_PLACED:
result = "Order placed";
break;
//
case TRADE_RETCODE_DONE:
result = "Request completed";
break;
//
case TRADE_RETCODE_DONE_PARTIAL:
result = "Only part of the request was completed";
break;
//
case TRADE_RETCODE_ERROR:
result = "Request processing error";
break;
//
case TRADE_RETCODE_TIMEOUT:
result = "Request canceled by timeout";
break;
//
case TRADE_RETCODE_INVALID:
result = "Invalid request";
break;
//
case TRADE_RETCODE_INVALID_VOLUME:
result = "Invalid volume in the request";
break;
//
case TRADE_RETCODE_INVALID_PRICE:
result = "Invalid price in the request";
break;
//
case TRADE_RETCODE_INVALID_STOPS:
result = "Invalid stops in the request";
break;
//
case TRADE_RETCODE_TRADE_DISABLED:
result = "Trade is disabled";
break;
//
case TRADE_RETCODE_MARKET_CLOSED:
result = "Market is closed";
break;
//
case TRADE_RETCODE_NO_MONEY:
result = "There is not enough money to complete the request";
break;
//
case TRADE_RETCODE_PRICE_CHANGED:
result = "Prices changed";
break;
//
case TRADE_RETCODE_PRICE_OFF:
result = "There are no quotes to process the request";
break;
//
case TRADE_RETCODE_INVALID_EXPIRATION:
result = "Invalid order expiration date in the request";
break;
//
case TRADE_RETCODE_ORDER_CHANGED:
result = "Order state changed";
break;
//
case TRADE_RETCODE_TOO_MANY_REQUESTS:
result = "Too frequent requests";
break;
//
case TRADE_RETCODE_NO_CHANGES:
result = "No changes in request";
break;
//
case TRADE_RETCODE_SERVER_DISABLES_AT:
result = "Autotrading disabled by server";
break;
//
case TRADE_RETCODE_CLIENT_DISABLES_AT:
result = "Autotrading disabled by client terminal";
break;
//
case TRADE_RETCODE_LOCKED:
result = "Request locked for processing";
break;
//
case TRADE_RETCODE_FROZEN:
result = "Order or position frozen";
break;
//
case TRADE_RETCODE_INVALID_FILL:
result = "Invalid order filling type";
break;
//
case TRADE_RETCODE_CONNECTION:
result = "No connection with the trade server";
break;
//
case TRADE_RETCODE_ONLY_REAL:
result = "Operation is allowed only for live accounts";
break;
//
case TRADE_RETCODE_LIMIT_ORDERS:
result = "The number of pending orders has reached the limit";
break;
//
case TRADE_RETCODE_LIMIT_VOLUME:
result = "The volume of orders and positions for the symbol has reached the limit";
break;
//
default:
result = "Invalid return code of the trade server";
break;
}
//
return result;
}
//
// Protected ...
protected:
//
// Private ...
//
bool CanLog()
{
return mLogAlerts;
}
//
bool CanLogAlert()
{
//
bool result = GetEnableAlerts() && GetLogAlerts();
//
return result;
}
//
bool CanTerminalAlert()
{
//
bool result = GetEnableAlerts() && GetTerminalAlerts();
//
return result;
}
//
bool CanMailAlert()
{
//
bool result = GetEnableAlerts() && GetMailAlerts();
//
return result;
}
//
bool CanPushAlert()
{
//
bool result = GetEnableAlerts() && GetPushAlerts();
//
return result;
}
//
void Save(string message)
{
//
if (!mSaveAlerts ||
!IsValid(message) ||
message == mLastSavedMessage ||
PrepareMessage(message) == mLastSavedMessage)
{
return;
}
//
string filePath = collector.GetFilePath("XLogs");
if (!IsValid(filePath))
{
return;
}
//
// Attach Time ...
string savedMessage = ToString(TimeCurrent()) + " " + message;
//
bool has = collector.Append(
filePath,
savedMessage //
);
if (has)
{
mLastSavedMessage = message;
}
}
private:
//
// Props ...
string mPrefix; // Alerts Prefixe
bool mEnableAlerts; // Enable Alerts
bool mSaveAlerts; // Save Alerts
bool mLogAlerts; // Log Alerts
bool mTerminalAlerts; // Terminal Alerts
bool mMailAlerts; // Mail Alerts
bool mPushAlerts; // Push Alerts
//
string mLastSavedMessage; // For Prevent Multiple Saving Same Mesage ...
XCDataCollector *collector;
//
// Tools ...
//
// Clear Escape String and
// Attach Alert Prefix to Message ...
string PrepareMessage(string message)
{
//
StringReplace(message, "\n", " | ");
//
StringConcatenate(message, GetPrefix(), " > ", message);
//
return message;
}
};
//