问题描述
我试图在运行MetaTrader Terminal 5或4的同时,在我的nodejs服务器中获取外汇汇率,然后socke.io将其发送给客户端.
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.
所以我想我必须使用MQL4/5.我知道如何在我的nodejs服务器中处理请求.我不知道在哪里编写MQL4代码,在MetaTrader终端中要配置什么.
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.
让我们说我想在每次更改时将EUR/USD出价汇率发送到我的nodejs服务器.如何使用MT4/5和MQL4/5实现这一目标?
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?
我的nodejs代码:
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脚本:
#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.
}
编译并运行时,我看到它是在"MT专家"选项卡中执行的,但是在我的nodejs服务器上,控制台什么都没记录.
When I compile and run, I see that it was executed in MT Experts tab, but on my nodejs server, console logs nothing.
推荐答案
工作计划:
-
启用 MT4/5以将
{http:|https:}
传输类用于所选目标
Enable MT4/5 to use
{http:|https:}
transport-class to selected targets
创建 MT4/5代码以执行某种基于{http:|https:}
的服务
Create MT4/5 code to execute some kind of {http:|https:}
based service
实施将端到端逻辑包装+隐藏在愚蠢的http协议交换中
Implement end-to-end logic to be wrapped + hidden inside the dumb http-protocol exchanges
1)终端权限:
使用终端->工具->选项启用 "允许WebRequest URL "以使用localhost
您选择的URL,与列表中的nodejs-server设置匹配
1) Terminal permissions:
Using Terminal->Tools->Options enable "Allow a WebRequest URL" to use a localhost
{http:|https:}
URL of your choice, matching the nodejs-server setup, in the list
根据您的意图,使用内置的IDE 或使用您的外部编辑器创建 MQL4
脚本选择并将生成的 .mq4
脚本文件保存在 ~an_MT4_Terminal_Home_Directory/MQL4/Scripts
目录中
Given your intentions, create an MQL4
script, using either a built-in IDE or using an external editor of your choice and save the produced .mq4
script file in ~an_MT4_Terminal_Home_Directory/MQL4/Scripts
directory
事件循环主要是您的设计工作:
The event-loop is principally your design job:
int start() {
while !isStopped() { // ACK LOOP
if ( RefreshRates() ) { // NEW QUOTE has arrived
... // JOB PROCESS Bid
int aHttpRetCODE = WebRequest(...); // SIG-> NodeJS Server
... // JOB PROCESS Response ( if a bi-directional service )
}
else {
Sleep(...); // NOP on NACK, Terminal has nothing to do
}
}
}
更多详情,请查看我的其他帖子 WebRequest()
用例和有关其主要限制的警告.
For further details, may like to check my other posts on WebRequest()
use-cases and warnings about it's principal limitations.
这是您的设计的极致之宝.
Here comes the creme-ala-creme of your design.
是的,有. 那将是我的选择之一-使用 ZeroMQ
或 nanomsg
(MT4/5 Terminal& NodeJS),因此能够完全.
Yes, there is. That would be the one of my choice - using ZeroMQ
or nanomsg
on both sides ( MT4/5 Terminal & NodeJS ), thus being able to fully enjoy the freedom of a full-scale distributed systems design.
这篇关于如何从MetaTrader Terminal 5 MQL 5发布请求到我的MT5主机本地运行的nodejs服务器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!