How can someone send data from MetaTrader 4/5 Terminal to external server?

血红的双手。 提交于 2020-01-11 07:39:06

问题


this is somehow intended to (maybe) be(come) a guideline post in terms of MetaTrader 4/5 and its corresponding language MQL4 both set into context with sending data to external servers.

In my special case I am building a Django/Python based web application that will process FOREX trading data for further use.

Thus, I am in search for a proper solution to send data from the MetaTrader 4/5 Terminal to an external server periodically (e.g. every 60 seconds) formatted as json or csv (if possible). In particular, the data to be sent is the accounts trade history and the running + pending trades set.

After doing the research I basically found the following approaches:

1.) Using webrequest() in MQL4 wrapped in an expert advisor

As the official MQL4 docu suggests, the webrequest() function sends an http:// request to a specified server.
This is a related SO thread:
How to post from MetaTrader Terminal 5 MQL 5 a request to my nodejs server, which is running locally on my MT5 host?

and the official documentation:

https://docs.mql4.com/common/webrequest

This could be wrapped into an expert advisor to execute the request periodically on defined events given.

Which kind of data from the MT4/5 terminal can be populated into the data array?
How can that data be formatted? Is it possible to format it as json straight away or should that be done on the server-side?

2.) Using ZeroMQ

This is a setup I found in this thread: How to send a message in MQL4/5 from MetaTrader Terminal to python using ZeroMQ?

How would this be accomplished within the MetaTrader environment? Will this still be an expert advisor or some kind of DLL solution? What is the ZeroMQ's role within the setup?

What are the pros and cons compared to the webrequest() function?

3.) Others?

Are there any other possible approaches on achieving this like e.g. with APIs or MQL4 scripts?

Since this is a rare topic, I am loooking forward to any however small idea and input.


回答1:


Since this is a rare topic, ... is it, indeed, so rare to need this ?

Welcome to the club - my above cited answer has received within 1,5 years Zero-votes so far

Nevertheless,
having used ZeroMQ since v2.11+, thanks to the R&D work published by Austen CONRAD - all thanks and deep respect for his persistence we owe to him.

Q : "How would this be accomplished within the MetaTrader environment?"

One simply #import-s the DLL and starts to use ZeroMQ-API-wrapper calls. A few details went a bit more complex, after MetaTrader has silently changed internal representation of string to cease to be a string ( becoming a struct in "New"-MQL4.56789, but you will learn how to live with this "Always On Watch"-style, so as to survive in production )

Q : "Will this still be an expert advisor or some kind of DLL solution?"

ZeroMQ can be used in either and/or all of:
- Expert Advisor-type of MQL4-code
- Custom Indicator-type of MQL4-code
- Script-type of MQL4-code
and
can even provide a proxy-signaling/messaging-layer, so as to communicate among these otherwise separate and not-cooperating processes inside the MT4-Terminal Ecosystem.

Example:
I have MT4-Terminal processes cooperate with external AI/ML-based market analyser, which auto-detects windows-of-opportunity plus having an external CLI-console, as a remote-keyboard for MT4-Terminal hosted Control Panel, showing system health-state and listening to a remote-keyboard, used for a remote CLI-command control ( for both configuration and maintenance tasks of the whole multi-party distributed trading system )

Q : "What is the ZeroMQ's role within the setup?"

ZeroMQ provides an independent, smart and industry-standard, smart and low-latency signaling/messaging layer among any kind of needed nodes ( grid-computing, GPU-computing, CLI-treminal, AI/ML-decision making, system-wide consolidated central logging, anything one may need )

Try to setup and use a remote tipc://-transport-class for cross-cluster computing paradigm with any other approach.

Try to setup and use an M:N-redundant Strategy Trading, operated accross a mix of tcp:// + tipc:// + norm:// + vmci:// transport-classes, used so as to interconnect ( A x M + N x B )-nodes' exo-systems.

Try to setup a system, that asks MetaTrader to do some work from outside, without this technology ( webrequest() is not ready for any "qestions from outside", is it? )

Q : "What are the pros and cons compared to the webrequest() function?"

Feel free to read about this in StackOverflow answers.



来源:https://stackoverflow.com/questions/58845664/how-can-someone-send-data-from-metatrader-4-5-terminal-to-external-server

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!