- Sending push notifications
- Sending email notifications
- Sending files to an FTP server
- Data exchange with a web server via HTTP/HTTPS
- Establishing and breaking a network socket connection
- Checking socket status
- Setting data send and receive timeouts for sockets
- Reading and writing data over an insecure socket connection
- Preparing a secure socket connection
- Reading and writing data over a secure socket connection
Sending push notifications
As you know, the terminal allows you to send push notifications from MetaQuotes services, the terminal itself, and MQL programs to a mobile device with iOS or Android operating systems. This technology uses MetaQuotes ID, a unique identifier of a user (see the note). MetaQuotes ID is allocated when installing the mobile version of the terminal on the user's device, after which the ID must be specified in the terminal settings, on the Notifications tab (several identifiers can be specified separated by commas). After that, the functionality for sending push notifications becomes available for MQL programs.
In fact, MetaQuotes ID does not identify a user, but a specific installation of a mobile terminal; a user can have several installations. The ID is not associated with the registration in the mql5.com community by default, although such a binding can be specified on the site. Do not confuse user registration in the community with MetaQuotes ID. To work with notifications, the terminal user is not required to log into the community.
bool SendNotification(const string text)
The SendNotification function sends push notifications with the specified text to all mobile terminals that have a MetaQuotes ID from the terminal settings. The message length is no more than 255 characters.
If the notification is successfully sent from the terminal, the function returns true, and it returns false if an error occurs. Possible error codes in _LastError include:
- 4515 ERR_NOTIFICATION_SEND_FAILED communication problems
- 4516 ERR_NOTIFICATION_WRONG_PARAMETER an invalid parameter, for example, an empty string
- 4517 ERR_NOTIFICATION_WRONG_SETTINGS MetaQuotes ID is incorrectly configured or missing
- 4518 ERR_NOTIFICATION_TOO_FREQUENT too frequent function calls
If there is a connection to the server, the message is sent instantly. If the user's device is online, the message should reach the addressee, but delivery cannot be guaranteed in the general case. There is no return notification to the program about the delivery of the message. The history of push messages on the server for deferred delivery is not saved.
The function has restrictions on the frequency of use: no more than 2 calls per second and no more than 10 per minute.
The SendNotification function is not executed in the strategy tester.
The book includes a simple script NetNotification.mq5 that sends a test notification when the settings are correct.
void OnStart()
|