如何制作MetaTrader 5 Terminal脚本,将EURUSD BID汇率发送到端口443上的nodejs服务器?

时间:2017-02-12 16:26:14

标签: node.js mql4 metatrader4 mql5 metatrader5

基本上我希望我的本地MetaTrader 5终端在每次EUR / USD对的BID率变化时都会发出POST请求。

我将在我的nodejs服务器中 console.log

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}`);
});

这是我的MQ5脚本,编译时没有错误。 但是当我运行它时,我在nodejs服务器终端上看不到任何记录。

我在Meta Trader Print("Test:",b);

中看到Experts Tab脚本打印

我还在MetaTrader 5终端中添加了 - >工具 - >选项 - >专家顾问

http://localhost:443/fxrates

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

MQ5脚本

//+------------------------------------------------------------------+
//|                                                      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); 

 }


//+------------------------------------------------------------------+

1 个答案:

答案 0 :(得分:2)

为什么你相信一切都会好起来?
作为一名程序员,你已经准备好抓住错误了......试试这个:

[StructLayout(LayoutKind.Sequential)]
public struct SomeStructO
{
    public SomeStructO(int theNumber)
    {
        TheNumber = theNumber;
        Coordinates = PointF.Empty;
        SomeNumbers = null;
    }

    public PointF Coordinates;

    [MarshalAs(UnmanagedType.LPArray)]
    public int[] SomeNumbers;

    public int TheNumber;
}

然后让我们看看出了什么问题。

将来您可能希望使用其他类型的通知(即电子邮件)扩展该块,以便在发生某些错误时知道。

目前 - 请检查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 } 功能,您的超时参数为WebRequest()

NULL - 方法需要WebRequest#2