I'm trying to get FX rates in my nodejs server and socke.io emit them to the client, while running MetaTrader Terminal 5 or 4.
So I guess I have to use MQL4/5. I know how the handle the request in my nodejs server. What I dont know is where to write the MQL4 code, what to config in my MetaTrader Terminal.
Lets say I want to send EUR/USD bid rate to my nodejs server everytime it gets changed. How do I achieve that, using MT4/5 and MQL4/5?
My nodejs code:
app.post('/fxroute', (req, res) => {
console.log(req);
let fxRates = req.body // dont know if the payload will be in body
socket.emit('fxRates', fxRates);
});
MQL5 script:
#property copyright "Copyright 2017, MetaQuotes Software Corp."
#property link "https://www.mql5.com"
#property version "1.00"
//+------------------------------------------------------------------+
//| Script program start function |
//+------------------------------------------------------------------+
void OnStart(){
string headers;
char data[],
result[];
string str = "data=value"; // POST-data, variables to send
StringToCharArray( str, data );
string b = CharArrayToString( data );
Print( "Test:", b ); // just a test of data, if good ... OK, data was setup correctly.
WebRequest( "POST",
"http://localhost:3000/fxroute",
NULL,
NULL,
3000,
data,
ArraySize( data ),
result,
headers
);
Print( CharArrayToString( result ) ); // see the results
// it returns
// "Results:" No posted data.
}
When I compile and run, I see that it was executed in MT Experts tab, but on my nodejs server, console logs nothing.