0

Basically I want my local MetaTrader 5 Terminal to do POST-requests everytime an EUR/USD pair's BID-rate changes.

And I'm going to console.log it in my nodejs server:

const express = require('express');
const app = express();
const http = require('http').Server(app);
const io = require('socket.io')(http);
const path = require('path');
const mongoose = require('mongoose');
const bodyParser = require('body-parser');

let env = process.env.NODE_ENV || 'development';

const port = 443;
const connection = 'mongodb://localhost:27017/db';

app.use(bodyParser.urlencoded({extended: true}));
app.use(bodyParser.json());
app.use(express.static(path.join(__dirname, 'public')));

mongoose.connect(connection)
    .then((db) => {
        console.log('MongoDB up and running!');

        app.post('/fxrates', (req, res) => {
            console.log(req);
        });
         // MY ROUTES for the client
    })
    .catch(console.log);

http.listen(port, () => {
    console.log(`listening on ${port}`);
});

Here is my MQ5 script which is compiled without errors. But when I run it, I don't see anything logged in my nodejs server terminal.

And I see Print("Test:",b); script printing inside Meta Trader Experts Tab

I have also added in MetaTrader 5 Terminal -> Tools -> Options -> Expert Advisors

http://localhost:443/fxrates

and

http://localhost/fxrates
http://localhost

MQ5 script

//+------------------------------------------------------------------+
//|                                                      fxrates.mq5 |
//|                        Copyright 2017, MetaQuotes Software Corp. |
//|                                             https://www.mql5.com |
//+------------------------------------------------------------------+
#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;
      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 test if good ... it is.

      WebRequest("POST","http://localhost:443/fxrates",NULL,NULL,3000,data,ArraySize(data),result,headers); 

 }


//+------------------------------------------------------------------+
user3666197
  • 1
  • 6
  • 50
  • 92
Georgi Antonov
  • 1,581
  • 21
  • 40
  • Have you at least **given a try to my previous advice + the source-code to log / show the content of the http-POST-wrapped transaction in a python console? >>> http://stackoverflow.com/a/39966404/3666197 re-run it + post outputs, what was logged, ok?** – user3666197 Feb 13 '17 at 15:20

1 Answers1

2

And why you believe that everything must go fine?
As a programmer, you are ready to catch errors ... try this:

int  res  = WebRequest( "POST", ... );
if ( res != 200 ){
     Print( "failed to send. result="
          + (string) res
          + ", LastError="
          + (string) GetLastError()
            );
     return( False );                          //+redefine void F(){} into a bool
}

Then let us see what's going wrong.

In future you may wish to extend that block with another kind of notifications ( i.e. email ) in order to know in case some error has occured.

As for now - please check the WebRequest() function, your timeout parameter is NULL.

You need WebRequest#2 for POST-methods.

user3666197
  • 1
  • 6
  • 50
  • 92
Daniel Kniaz
  • 4,603
  • 2
  • 14
  • 20