Thursday, October 16, 2025
HomeTradingMonitoring a number of crypto exchanges on-line through MQL5 library for Node.js/CCXT...

Monitoring a number of crypto exchanges on-line through MQL5 library for Node.js/CCXT – Different – 5 July 2025


CcxtAppServerLib is meant for working with all top-100 crypto exchanges from MQL5 through Node.js and CCXT Utility Server, and it’s evolving step-by-step. Newest beta-version consists of optimized caching of change “markets” (instrument specs and different buying and selling situations), non-blocking studying of websocket messages, and extra.
One introductory instance of utilizing the library – the script CcxtAppSrvShowcase.mq5 – was posted within the weblog earlier.
As one other instance of customized software growth utilizing the library, we offer a script for parallel monitoring of a number of exchanges for chosen kind of information. This function is carried out by subscribing by way of CCXT on Node.js to particular websocket “watches”, akin to watchOrderBook, watchTicker, watchTrades, and many others. For particulars, please, see widespread CCXT documentation and extra superior on CCXT PRO. Because the script is meant to make use of solely public APIs, consumer credentials aren’t concerned right here, however the library helps them in full diploma.

Right here is a very powerful elements of the brand new demo-script MultiExchangeWatch.mq5 (it is offered together with the beta-version of the library).

NB: If the script is working very first time, it should ask to unpack (manually) CCXT Utility Server (extracted as ccxtappsrvbundle.jsc from built-in useful resource), and run Node.js with it.

First, embody the headers.

#embody "ccxtjsmtlib.mqh" 
#embody "ccxtutil.mqh"
#embody 

Within the inputs, the Node server setup needs to be completed.

enter group "Connection settings"
enter string NodeServer = "http://127.0.0.1:8124";
enter string NodeAuth = ""; 

Subsequent, specify a lot of exchanges you need to monitor, a ticker, and a sort of the watch. By default, the script watches for order books for BCH/USDT.

To fill in these inputs correctly with most well-liked values, you need to most likely have to output the record of supported exchanges and their markets beforehand. It may be considered in one other instance script CcxtAppSrvShowcase.mq5, supplied with the lib.

enter string Exchanges = "ascendex,bitmart,binance"; 
enter string Ticker = "BCH/USDT";
enter string Watch = "watchOrderBook";
enter uint WatchingDuration = 10; 

Then OnStart occasion handler does its job. Inline feedback clarify the method. The imported capabilities, lessons and strategies from the library are highlighted in yellow.

string Trade[];

void OnStart()
{
   
   
   
   PrintFormat("CCXT AppSrvLibrary model: %.2f", AppSrvLibraryVersion());
   const static string standing[] = {"Cannot deploy",
      "App server ZIP is deployed, however not extracted",
      "App server recordsdata are deployed"};
   const int d = DeployCcxtAppServer();
   Print(standing[d + 1]);
   if(d 0)
   {
      return; 
   }
   
   
   
   
   SetNodeServer(NodeServer, NodeAuth);

   CcxtLink *hyperlink = GetLink();
   
   
   

   
   
   AutoPtrCcxtJsExchangeProIntf> ccxt[];
   const int n = StringSplit(Exchanges, ',', Trade);
   ArrayResize(ccxt, n);
   
   for(int i = 0; i CreateExchangePro(Trade[i]); 

      if(hyperlink.getLastHttpCode() != 200 || !ccxt[i][] || ccxt[i][][].t >= JS_NULL)
      {
         Print("Building failed for change: ", Trade[i]);
         return;
      }
      
      const bool isPro = !!*ccxt[i][]["pro"]; 
      
      if(!isPro)
      {
         PrintFormat("WARNING! %s is not PRO, there isn't any websocket assist", Trade[i]);
      }
      
      if(!ccxt[i][]["has"][Watch].getbool>())
      {
         PrintFormat("WARNING! %s doesn't assist '%s' subscriptions", Trade[i], Watch);
      }
   }
   
   
   
   int energetic = 0;
   
   for(int i = 0; i // begin websockets connection (if the change helps it)
      if(ccxt[i][].improve())
      {
         if(!ccxt[i][].watchAnything(StringFormat("%s("%s")", Watch, Ticker)))
         {
            PrintFormat("Cannot begin %s for %s", Watch, Trade[i]);
            ccxt[i][].shut(); 
            ccxt[i] = NULL;
         }
         else
         {
            energetic++;
         }
      }
      else
      {
         if(ccxt[i][].isConnected())
         {
            Print("Cannot improve to websockets");
            string headers[][2];
            if(ccxt[i][].ws().getHeaders(headers))
            {
               
            }
            ccxt[i][].ws().shut(); 
            ccxt[i][].shut();
            ccxt[i] = NULL;
         }
      }
   }
   
   if(!energetic) return;

   
   PrintFormat("* Monitoring %d subscriptions", energetic);

   const uint begin = GetTickCount();
   whereas(!IsStopped() && (!WatchingDuration || GetTickCount() - begin 1000))
   {
      for(int i = 0; i if(ccxt[i][] && ccxt[i][].isConnected())
         {
            AutoPtr j = ccxt[i][].readMessage(false); 
            if(j[])
            {
               ChronoComment(j[].stringify(0, 0)); 
            }
         }
      }
   }
  
   Print("* Unsubscribing...");
   for(int i = 0; i if(ccxt[i][] && ccxt[i][].isConnected())
      {
         ccxt[i][].un().watchAnything(StringFormat("%s("%s")", Watch, Ticker));
      }
   }
   
   
   GracefullClose(ccxt); // not offered right here within the weblog

   
   
   GracefullClose(ccxt, 5, true);
   
   Remark("");
}

When the script is working, the record of incoming order books (json-messages) is outputted and actively up to date on the chart.

CCXT multiple watches on different crypto exchanges in MetaTrader 5

On high of such a dataflow it is easy to implement numerous arbitrage methods and calculate mixed statistics.

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments