I would prefer to share an concept of integrating MetaTrader 5 and CCXT library.
For individuals who do not know what CCXT is I’ve offered a small introduction within the README textual content introduced beneath.
To place it briefly, CCXT is an open-source library for accessing all well-liked crypto exchanges.
CCXT is obtainable in lots of programming languages and platforms, amongst which is a mix of JavaScript operating on the well-known Node.js server.
Therefore we are able to use WebRequest and socket-functions constructed into MQL5 to attach MetaTrader 5 and a JavaScript/Node.js utility.
Right here is the scheme of already carried out structure (restricted beta-version).
Connecting MetaTrader 5 with crypto exchanges through CCXT Software Server on Node.js
MetaTrader 5 hosts an MQL5-application which requests JavaScript/Node.js server, which in flip makes use of CCXT library to translate and ship these requests additional to distant exchanges of your selection.
The great factor right here is that we leverage all the facility of CCXT.
The unhealthy factor is that we have to setup many components of the structure manually, principally due to limitations imposed by MQL5 sandbox (safety mechanisms).
1. We’d like Node.js server put in in your PC (we will not do it from MT5).
2. We have to set up the JavaScript utility server on the Node.js (we will not do it from MT5).
3. The Node.js and the app server have to be run manually or through Home windows scheduler (we will not do it from MT5).
The final process of set up of a hypothetical MQL5-product from the Market is proven on the next diagram.
Organising CCXT Software Server on Node.js for MetaTrader 5
The method would be the identical for any ready-made product with the library embedded into it (when/if such merchandise change into obtainable, from me or 3D occasion builders).
The event of utilized MQL5-programs based mostly on the library requires a set of mqh-headers and mq5-files with API interface declarations and implementation of auxiliary features (all these usually are not wanted for extraordinary customers).
CCXT Software Server executable and supply code information
Examples of programming customized scripts utilizing the library will probably be offered for builders as properly.
The supply code of the implementation of the library’s core is closed, that’s each the MQL5 half and the JavaScript half are distributed in precompiled kind (ex5 and jsc, respectively).
The library continues to be underneath improvement and testing.
Be happy to ship me your ideas on whether or not you discover the described course of too sophisticated or acceptable. You possibly can recommend a option to make person expertise simpler, however please keep in mind that MQL5-products are topic to restrictions utilized by MetaTrader 5 and MQL5 market.
When you’re desirous about participation within the testing or creating a particular product on prime of the library, please contact me through non-public messaging.
===== R E A D M E =====
CCXT Software Server on Node.js for MetaTrader 5
CCXT stands for Crypto-Foreign money eXchange Buying and selling Library obtainable at https://github.com/ccxt/ in quite a few programming languages and for various platforms.
CCXT gives unified entry to 100+ Crypto-exchanges with totally carried out private and non-private APIs (candles, trades, orderbooks, image specs, positions, account administration, and so on).
CCXT Software Server is a HTTPS/websockets server for Node.js (powered by JavaScript V8 engine), which delivers CCXT capabilities to internet shoppers, and particularly to MetaTrader 5 with its WebRequest and sockets assist constructed into MQL5.
Integration of the appserver with MetaTrader 5 is carried out by way of CCXTAppSrvLibrary – it is a native MQL5 library, to be put in into MQL5/Libraries folder, that then maps CCXT strategies into MQL5 interfaces. MQL5-programs can import CCXTAppSrvLibrary‘s interfaces and construct variuos utilized instruments on prime of it – skilled advisers, indicators, providers, customized charts, and so on.
The library itself doesn’t present such instruments! You possibly can order their improvement within the freelance part or (because it’s deliberate for the longer term) search mql5.com for ready-made merchandise based mostly on the library. With some information of programming you may mix the library together with your program your self.
CCXT Software Server is embedded into the CCXTAppSrvLibrary as a ZIP-archive with bytecode (see beneath) and might be upgraded upon request as part of assist of verified prospects.
The steps of constructing CCXT up and operating on MT5 embrace:
1. Getting Node.js
This part is for many who do not have Node.js but. If you have already got Node, you may skip this part and use your occasion of Node.
You possibly can get hold of Node.js and discover out extra details about it at https://nodejs.org/.
For direct obtain go to https://nodejs.org/en/obtain, the place you may select between:
- Home windows Installer (.msi)
- Standalone Binary (.zip)
Use msi if you are going to entry the server from many cases of MetaTrader 5.
Use zip for fine-grained setup of every occasion underneath particular MetaTrader 5 (with skill to run completely different Node variations and configurations) or for single occasion.
Amongst many model numbers of Node offered on the positioning, it is advisable to decide on newest LTS (long-term-support) model.
For instance, on the time of writing LTS model was (zip variant): https://nodejs.org/dist/v22.14.0/node-v22.14.0-win-x64.zip.
However on the web page of the newest releases https://nodejs.org/dist/newest/ one might discover newer (however not LTS) model node-v23.10.0-win-x64.zip.
Which one to decide on is as much as you.
Please, word that for Home windows/MetaTrader 5 you need to select a distribution set with …-win-x64 suffix.
2. Downloading CCXTAppSrvLibrary
CCXTAppSrvLibrary is (purported to be) obtainable in MQL5 Market and downloadable proper from MetaTrader 5 or from mql5.com.
The library is downloaded into MQL5/Scripts/Market/ folder by default (that is how MQL5 Market works). It’s a necessity to repeat it into MQL5/Libraries/ccxt/ folder manually. You may as well copy it to many MT5 cases.
Along with ex5-file downloaded from the market, for developement of MQL5-programs based mostly on the library you will have mqh-files with exports and interface declarations. They’re (going to be) obtainable on the product web page and within the weblog.
When you use ready-made or customized constructed merchandise, mqh-files are helpful for reference solely.
3. Deploying CCXT Software Server
Amongst different issues declared within the mqh-files, CCXTAppSrvLibrary exports the perform DeployCcxtAppServer. Name it out of your MQL5-program at startup to extract ZIP-archive with CCXT Software Server, which is embedded into the ex5-file. When you use a ready-made or customized product, it ought to present some controls in its GUI to provoke this motion.
For instance, a attainable inside implementation might be:
void OnStart() { Â Â const int d = DeployCcxtAppServer(); Â Â if(d <= 0) Â Â { Â Â Â Â Â Â return; Â Â } Â Â Â Â Â Â ... }
The perform DeployCcxtAppServer returns one of many following values:
- -1 – an error, cannot deploy the app server;
- 0 – ZIP with the app server is deployed, however not extracted but;
- +1 – the app server information are in place (ZIP is extracted);
Usually, after the very first run you may get consequence 0, and might discover new ZIP-archive in MQL5/Information/ccxt-app-srv/ccxtappsrv-1-0.zip (model might fluctuate).
It is best to unzip it manually. It is a limitation imposed by MQL5 sandbox – the terminal doesn’t permit programmatic extraction of JavaScript information.
When you choose to make use of a easy console window for unzipping, the next command will do the job:
tar -xf ccxtappsrv-1-0.zip
This could extract the app server information from the ZIP into the present /ccxt-app-srv/ folder:
- ccxtappsrvbundle.jsc – fundamental program (bytecode);
- ccxtappsrvbundle.loader.cjs – loader script for the principle program;
- run.cmd – a command to run the appliance server; alternatively you may launch node.exe immediately (see subsequent sections).
As well as, unzipped stuff incorporates the subfolder ccxt-app-srv/node_modules/ with required packages utilized by the loader.
After this, all subsequent calls to DeployCcxtAppServer in MQL5 will return +1, which signifies that the surroundings is deployed and prepared for execution by Node.
4. Operating Node.js
To make node.exe acknowledged command in Home windows, you may set up Node by way of msi-installer or register its unzipped information within the system surroundings, for instance by way of nodevars.bat (equipped with Node).
Additionally you may setup a devoted copy of Node in particular folder (akin to MQL5/Information/ccxt-app-srv/) by extracting Node’s standalone binary (zip from p.1) into it.
To begin Node.js with the appliance server use run.cmd or customary command line (proper within the MQL5/Information/ccxt-app-srv/):
node ccxtappsrvbundle.loader.cjs parameters >
You possibly can contemplate making a job for Home windows scheduler or add the command into Home windows autostart, when you want the appliance server operating on a regular basis.
5. Command line arguments / choices
The app server helps the next arguments within the command line:
node ccxtappsrvbundle.loader.cjs [https-cert-files] [port] [IP] [username]
The primary argument is a reputation of SSL certiciate information (identify.key and identify.crt), which allow safe connections HTTPS/WSS on the server. By default, the identify is empty “” (no certificates), and connections are established through plain HTTP/WS (that is okay for native connections, see beneath). Please search on-line to seek out extra data on the best way to generate the certificates or get it from authorities.
Port is a communication port utilized by the server – 8124 by default;
IP is an IP-address to make use of by the server; 127.0.0.1 by default, which signifies that solely native connections are accepted (from packages on the identical PC). Use 0.0.0.0 to make the server publicly obtainable on the native community or/and Web (relies upon out of your router settings). For instance, you should utilize the only Node to entry exchanges from all computer systems in your house. When you plan to share the server through Web, it is higher to allow HTTPS/WSS.
Username is an elective authentication string – it prevents strangers from connecting to your server, if it is made seen on Web. While you set IP to 0.0.0.0, the server makes use of GROUP:USERNAME (from Home windows) because the username argument by default.
IP, port and username are additionally handed to CCXTAppSrvLibrary throughout initialization in MQL5 and all values ought to match the settings made on the server.
Right here is a few examples of the command strains:
node ccxtappsrvbundle.loader.cjs "mycert"
run with SSL utilizing mycert.key and mycert.crt in the identical folder
node ccxtappsrvbundle.loader.cjs "" 9000
run with out SSL on port 9000
node ccxtappsrvbundle.loader.cjs "" 8124 0.0.0.0 "confidential"
run with out SSL on port 8124 and settle for all connections handed computerized authentication by the desired non-public string.
6. Warning
NB: Please word, that the appliance server is a single person server – it accepts and applies your non-public keys/passwords for chosen exchanges. When you share the server with another person, this particular person could have entry to all of your favorite exchanges together with your rights, and vice versa – you’ll act underneath his/her credentials on all exchanges which she or he accesses through the proxy server.