Full-fledged Framework CCXT for Top 100+ Crypto Exchanges can be Integrated into MetaTrader 5: Pros and Cons

I'd like to share an idea of integrating MetaTrader 5 and CCXT library.
For those who don't know what CCXT is I've provided a small introduction in the README text presented below.
To put it briefly, CCXT is an open-source library for accessing all popular crypto exchanges.
CCXT is available in many programming languages and platforms, among which is a combination of JavaScript running on the well-known Node.js server.
Hence we can use WebRequest and socket-functions built into MQL5 to connect MetaTrader 5 and a JavaScript/Node.js application.
Here is the scheme of already implemented architecture (limited beta-version).
Connecting MetaTrader 5 with crypto exchanges via CCXT Application Server on Node.js
MetaTrader 5 hosts an MQL5-application which requests JavaScript/Node.js server, which in turn uses CCXT library to translate and send these requests further to remote exchanges of your choice.
The good thing here is that we leverage all the power of CCXT.
The bad thing is that we need to setup many parts of the architecture manually, mostly because of limitations imposed by MQL5 sandbox (security mechanisms).
1. We need Node.js server installed on your PC (we can't do it from MT5).
2. We need to install the JavaScript application server on the Node.js (we can't do it from MT5).
3. The Node.js and the app server must be run manually or via Windows scheduler (we can't do it from MT5).
The general procedure of installation of a hypothetical MQL5-product from the Market is shown on the following diagram.
Setting up CCXT Application Server on Node.js for MetaTrader 5
The process will be the same for any ready-made product with the library embedded into it (when/if such products become available, from me or 3-d party developers).
The development of applied MQL5-programs based on the library requires a set of mqh-headers and mq5-files with API interface declarations and implementation of auxiliary functions (all these are not needed for ordinary users).
CCXT Application Server executable and source code files
Examples of programming custom scripts using the library will be provided for developers as well.
The source code of the implementation of the library's core is closed, that is both the MQL5 part and the JavaScript part are distributed in precompiled form (ex5 and jsc, respectively).
The library is still under development and testing.
Feel free to send me your thoughts on whether you find the described process too complicated or acceptable. You can suggest a way to make user experience easier, but please remember that MQL5-products are subject to restrictions applied by MetaTrader 5 and MQL5 market.
If you're interested in participation in the testing or developing a specific product on top of the library, please contact me via private messaging.
===== R E A D M E =====
CCXT Application Server on Node.js for MetaTrader 5
CCXT stands for Crypto-Currency eXchange Trading Library available at https://github.com/ccxt/ in numerous programming languages and for different platforms.
CCXT provides unified access to 100+ Crypto-exchanges with fully implemented public and private APIs (candles, trades, orderbooks, symbol specifications, positions, account management, etc).
CCXT Application Server is a HTTPS/websockets server for Node.js (powered by JavaScript V8 engine), which delivers CCXT capabilities to web clients, and specifically to MetaTrader 5 with its WebRequest and sockets support built into MQL5.
Integration of the appserver with MetaTrader 5 is implemented by means of CCXTAppSrvLibrary - it's a native MQL5 library, to be installed into MQL5/Libraries folder, that then maps CCXT methods into MQL5 interfaces. MQL5-programs can import CCXTAppSrvLibrary's interfaces and build variuos applied tools on top of it - expert advisers, indicators, services, custom charts, etc.
The library itself does not provide such tools! You can order their development in the freelance section or (as it's planned for the future) search mql5.com for ready-made products based on the library. With some knowledge of programming you can combine the library with your program yourself.
CCXT Application Server is embedded into the CCXTAppSrvLibrary as a ZIP-archive with bytecode (see below) and can be upgraded upon request as a part of support of verified customers.
The steps of making CCXT up and running on MT5 include:
1. Getting Node.js
This section is for those who don't have Node.js yet. If you already have Node, you can skip this section and use your instance of Node.
You can obtain Node.js and find out more information about it at https://nodejs.org/.
For direct download visit https://nodejs.org/en/download, where you can choose between:
- Windows Installer (.msi)
- Standalone Binary (.zip)
Use msi if you're going to access the server from many instances of MetaTrader 5.
Use zip for fine-grained setup of each instance under specific MetaTrader 5 (with ability to run different Node versions and configurations) or for single instance.
Among many version numbers of Node provided on the site, it's recommended to choose latest LTS (long-term-support) version.
For example, at the time of writing LTS version was (zip variant): https://nodejs.org/dist/v22.14.0/node-v22.14.0-win-x64.zip.
But at the page of the latest releases https://nodejs.org/dist/latest/ one could find more recent (but not LTS) version node-v23.10.0-win-x64.zip.
Which one to choose is up to you.
Please, note that for Windows/MetaTrader 5 you should choose a distribution set with ...-win-x64 suffix.
2. Downloading CCXTAppSrvLibrary
CCXTAppSrvLibrary is (supposed to be) available in MQL5 Market and downloadable right from MetaTrader 5 or from mql5.com.
The library is downloaded into MQL5/Scripts/Market/ folder by default (this is how MQL5 Market works). It's necessary to copy it into MQL5/Libraries/ccxt/ folder manually. You can also copy it to many MT5 instances.
In addition to ex5-file downloaded from the market, for developement of MQL5-programs based on the library you will need mqh-files with exports and interface declarations. They are (going to be) available at the product page and in the blog.
If you use ready-made or custom built products, mqh-files are useful for reference only.
3. Deploying CCXT Application Server
Among other things declared in the mqh-files, CCXTAppSrvLibrary exports the function DeployCcxtAppServer. Call it from your MQL5-program at startup to extract ZIP-archive with CCXT Application Server, which is embedded into the ex5-file. If you use a ready-made or custom product, it should provide some controls in its GUI to initiate this action.
For example, a possible internal implementation could be:
void OnStart() { const int d = DeployCcxtAppServer(); if(d <= 0) { return; } // here d is +1 // now proceed to normal operation, provided that Node is started with the deployed files ... }
The function DeployCcxtAppServer returns one of the following values:
- -1 - an error, can't deploy the app server;
- 0 - ZIP with the app server is deployed, but not extracted yet;
- +1 - the app server files are in place (ZIP is extracted);
Normally, after the very first run you'll get result 0, and can find new ZIP-archive in MQL5/Files/ccxt-app-srv/ccxtappsrv-1-0.zip (version may vary).
You should unzip it manually. This is a limitation imposed by MQL5 sandbox - the terminal does not allow programmatic extraction of JavaScript files.
If you prefer to use a simple console window for unzipping, the following command will do the job:
tar -xf ccxtappsrv-1-0.zipThis should extract the app server files from the ZIP into the current /ccxt-app-srv/ folder:
- ccxtappsrvbundle.jsc - main program (bytecode);
- ccxtappsrvbundle.loader.cjs - loader script for the main program;
- run.cmd - a command to run the application server; alternatively you can launch node.exe directly (see next sections).
In addition, unzipped stuff contains the subfolder ccxt-app-srv/node_modules/ with required packages used by the loader.
After this, all subsequent calls to DeployCcxtAppServer in MQL5 will return +1, which means that the environment is deployed and ready for execution by Node.
4. Running Node.js
To make node.exe recognized command in Windows, you can install Node through msi-installer or register its unzipped files in the system environment, for example through nodevars.bat (supplied with Node).
Also you can setup a dedicated copy of Node in specific folder (such as MQL5/Files/ccxt-app-srv/) by extracting Node's standalone binary (zip from p.1) into it.
To start Node.js with the application server use run.cmd or standard command line (right in the MQL5/Files/ccxt-app-srv/):
node ccxtappsrvbundle.loader.cjs <optional parameters>
You can consider creating a task for Windows scheduler or add the command into Windows autostart, if you need the application server running all the time.
5. Command line arguments / options
The app server supports the following arguments in the command line:
node ccxtappsrvbundle.loader.cjs [https-cert-files] [port] [IP] [username]The first argument is a name of SSL certiciate files (name.key and name.crt), which enable secure connections HTTPS/WSS on the server. By default, the name is empty "" (no certificates), and connections are established via plain HTTP/WS (this is ok for local connections, see below). Please search online to find more information on how to generate the certificate or get it from authorities.
Port is a communication port used by the server - 8124 by default;
IP is an IP-address to use by the server; 127.0.0.1 by default, which means that only local connections are accepted (from programs on the same PC). Use 0.0.0.0 to make the server publicly available on the local network or/and Internet (depends from your router settings). For example, you can use the single Node to access exchanges from all computers in your home. If you plan to share the server via Internet, it's better to enable HTTPS/WSS.
Username is an optional authentication string - it prevents strangers from connecting to your server, if it's made visible on Internet. When you set IP to 0.0.0.0, the server uses GROUP:USERNAME (from Windows) as the username argument by default.
IP, port and username are also passed to CCXTAppSrvLibrary during initialization in MQL5 and all values should match the settings made on the server.
Here is some examples of the command lines:
node ccxtappsrvbundle.loader.cjs "mycert"
run with SSL using mycert.key and mycert.crt in the same folder
node ccxtappsrvbundle.loader.cjs "" 9000run without SSL on port 9000
node ccxtappsrvbundle.loader.cjs "" 8124 0.0.0.0 "confidential"
run without SSL on port 8124 and accept all connections passed automatic authentication by the specified private string.
6. Warning
NB: Please note, that the application server is a single user server - it accepts and applies your private keys/passwords for selected exchanges. If you share the server with someone else, this person will have access to all your favourite exchanges with your rights, and vice versa - you'll be able to act under his/her credentials on all exchanges which he or she accesses via the proxy server.