I would wish to share an concept of integrating MetaTrader 5 and CCXT library.
For many who do not know what CCXT is I’ve supplied a small introduction within the README textual content introduced under.
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 working 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 software.
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 alternative.
The nice factor right here is that we leverage all the facility of CCXT.
The unhealthy factor is that we have to setup many elements of the structure manually, largely due to limitations imposed by MQL5 sandbox (safety mechanisms).
1. We want Node.js server put in in your PC (we will not do it from MT5).
2. We have to set up the JavaScript software server on the Node.js (we will not do it from MT5).
3. The Node.js and the app server should 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 turn into out there, from me or three-D celebration 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 bizarre customers).
CCXT Software Server executable and supply code recordsdata
Examples of programming customized scripts utilizing the library can be supplied for builders as nicely.
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 type (ex5 and jsc, respectively).
The library remains to be below growth and testing.
Be at liberty to ship me your ideas on whether or not you discover the described course of too sophisticated or acceptable. You’ll be able to counsel a strategy to make consumer expertise simpler, however please do not forget that MQL5-products are topic to restrictions utilized by MetaTrader 5 and MQL5 market.
If you happen to’re eager about participation within the testing or creating a selected product on high of the library, please contact me through personal messaging.
===== R E A D M E =====
CCXT Software Server on Node.js for MetaTrader 5
CCXT stands for Crypto-Forex eXchange Buying and selling Library out there at https://github.com/ccxt/ in quite a few programming languages and for various platforms.
CCXT supplies unified entry to 100+ Crypto-exchanges with totally carried out private and non-private APIs (candles, trades, orderbooks, image specs, positions, account administration, and many others).
CCXT Software Server is a HTTPS/websockets server for Node.js (powered by JavaScript V8 engine), which delivers CCXT capabilities to net shoppers, and particularly to MetaTrader 5 with its WebRequest and sockets help constructed into MQL5.
Integration of the appserver with MetaTrader 5 is carried out via 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 high of it – knowledgeable advisers, indicators, companies, customized charts, and many others.
The library itself doesn’t present such instruments! You’ll be able to order their growth 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 possibly can mix the library along with your program your self.
CCXT Software Server is embedded into the CCXTAppSrvLibrary as a ZIP-archive with bytecode (see under) and could be upgraded upon request as part of help of verified clients.
The steps of creating CCXT up and working on MT5 embody:
1. Getting Node.js
This part is for individuals who haven’t got Node.js but. If you have already got Node, you possibly can skip this part and use your occasion of Node.
You’ll be able to acquire 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 possibly can 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 below particular MetaTrader 5 (with means to run completely different Node variations and configurations) or for single occasion.
Amongst many model numbers of Node supplied on the location, 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 may discover more moderen (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 must select a distribution set with …-win-x64 suffix.
2. Downloading CCXTAppSrvLibrary
CCXTAppSrvLibrary is (alleged to be) out there 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 can even 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 have to mqh-files with exports and interface declarations. They’re (going to be) out there on the product web page and within the weblog.
If you happen to 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 operate 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. If you happen to 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 could possibly be:
void OnStart() { const int d = DeployCcxtAppServer(); if(d 0) { return; } ... }
The operate 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 recordsdata are in place (ZIP is extracted);
Usually, after the very first run you may get outcome 0, and might discover new ZIP-archive in MQL5/Information/ccxt-app-srv/ccxtappsrv-1-0.zip (model could range).
You need to unzip it manually. This can be a limitation imposed by MQL5 sandbox – the terminal doesn’t enable programmatic extraction of JavaScript recordsdata.
If you happen to favor 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 recordsdata from the ZIP into the present /ccxt-app-srv/ folder:
- ccxtappsrvbundle.jsc – most important program (bytecode);
- ccxtappsrvbundle.loader.cjs – loader script for the primary program;
- run.cmd – a command to run the applying server; alternatively you possibly can launch node.exe immediately (see subsequent sections).
As well as, unzipped stuff comprises 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 implies that the setting is deployed and prepared for execution by Node.
4. Working Node.js
To make node.exe acknowledged command in Home windows, you possibly can set up Node via msi-installer or register its unzipped recordsdata within the system setting, for instance via nodevars.bat (provided with Node).
Additionally you possibly can setup a devoted copy of Node in particular folder (equivalent to MQL5/Information/ccxt-app-srv/) by extracting Node’s standalone binary (zip from p.1) into it.
To begin Node.js with the applying server use run.cmd or customary command line (proper within the MQL5/Information/ccxt-app-srv/):
node ccxtappsrvbundle.loader.cjs parameters >
You’ll be able to think about making a job for Home windows scheduler or add the command into Home windows autostart, in the event you want the applying server working 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 recordsdata (title.key and title.crt), which allow safe connections HTTPS/WSS on the server. By default, the title is empty “” (no certificates), and connections are established through plain HTTP/WS (that is okay for native connections, see under). Please search on-line to seek out extra data on easy methods 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 implies that solely native connections are accepted (from applications on the identical PC). Use 0.0.0.0 to make the server publicly out there 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. If you happen to plan to share the server through Web, it is higher to allow HTTPS/WSS.
Username is an optionally available authentication string – it prevents strangers from connecting to your server, if it is made seen on Web. Whenever 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 automated authentication by the desired personal string.
6. Warning
NB: Please word, that the applying server is a single consumer server – it accepts and applies your personal keys/passwords for chosen exchanges. If you happen to share the server with another person, this particular person could have entry to all of your favorite exchanges along with your rights, and vice versa – you can act below his/her credentials on all exchanges which she or he accesses through the proxy server.