Discussion of article "Websockets for MetaTrader 5"

 

New article Websockets for MetaTrader 5 has been published:

Before the introduction of the network functionality provided with the updated MQL5 API, MetaTrader programs have been limited in their ability to connect and interface with websocket based services. But of course this has all changed, in this article we will explore the implementation of a websocket library in pure MQL5. A brief description of the websocket protocol will be given along with a step by step guide on how to use the resulting library.

Here is a video of the program running whilst connected to the server.


Author: Francis Dube

 
Excellent article. It's about time that MT5 has native websocket support.
Hopefully this code will be included as MT5 standard include files.
Or even better, MT5 shall provide native websocket API for performance reason.

Thank you for your effort.
 
"The release folder contains prebuilt dll and .exe files available for immediate use."

Did you forget that mentioned Release folder on your github page? ;)

 

Did you test it on external public servers, especially with TLS? Would be great to see an example(s).

PS. I'm asking because your test doesn't work with wss://echo.websocket.org (I'm attaching the log, BTW - why do you write so bulky useless info?). Pure ws (port 80) works ok. In past I also tried to run my implementation of WebSockets in MQL5, but failed because MQL's sockets have some intricacies with TLS layer. They seem still not solved. And wss is a must nowadays, because all production servers use TLS and decline non-secured connections.

Files:
log.txt  1113 kb
 
Did you manage to connect via WSS?
 

Nice work @Francis Dube, Thanks!

Is it possible to create a MQL5 service that acts as the WebSocket server? Do you have some examples?

 

Hey great work, 

I just tested your ea and it did connect to my C# websocket server, however after it connects and sends the message The journal tab spans this error

2022.02.08 07:33:36.176 Websocketclient_test (XAUUSD,M15) [MQL error ID: 5270][Is Socket Readable ][Line: 238][Function: CSocket::Readable]


any idea how I can get this fixed. Also sending back to Mt4 didn't seem to work

 

@Francis Dube Thank you for this library. There is a small change I had to make for it to work with URLs after /, e.g. /ws/..

However I find that it is not stable and doesn't always work, where as your WinAPI version works lot better.

As this one is a native library, do you have an improved version with the stability issues fixed?

Thank you

 
MetaQuotes:

New article Websockets for MetaTrader 5 has been published:

Author: Francis Dube

Great! So how do you parse the continuation frame? So far it only parses frames that is in the first response. I’m using nodejs websocket.
 

Hi great work there @Francis Dube

I have implemented your library to work with my web socket server in nodejs/nestjs. The issue i'm facing is that when i'm using the sockets locally with my server, everything works fine. mql5 socket send the handshake i get the correct response i.e. "101 Switching protocols". 

But the things changes as soon as i deploy my nestjs app to digitalocean app-platform, Initially i was not able to connect mql5 sockets to my server but then i was able to connect to it but i'm not getting correct response for handshake due to which the connect method from "CWebsocketClient" returns false as upgrade method didn't get to parse any response, I only get "H" as the response from my deployed app.

though i'm not sure about the rest of the functionality as the socket status consistently set to "CONNECTING" i'm not able to do anything after the successful connection. However, when after calling the connect method if send the data to my server using "sendString" method the data get delivered. 

And thats where i'm confused on how to implement things in my app, as i'm not able to test thing handshake thing any other way, i have tried extensions to check if my web socket is working in my app turns out its working fine, but as soon as it comes to mql5 things are messed up and not entirely elaborative enough to get the cause of this behaviour.

Any leads or guidance on this issue will be very much appreciated.

PS: I'm not doing any fancy stuff for now in my mql5 EA, i'm just following the connection guide in the article and just connecting with the server. Nothing else! :(