//+------------------------------------------------------------------+
//|                                                DomServerScan.mq5 |
//|                                  Copyright 2026, MetaQuotes Ltd. |
//|                                             https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2026, MetaQuotes Ltd."
#property link      "https://www.mql5.com"
#property version   "1.00"
#property description "Lists the symbols of the connected server that report a book depth above zero"
#property description "and calls MarketBookAdd() on each of them. No book entries are read."

//+------------------------------------------------------------------+
//| Script program start function                                    |
//+------------------------------------------------------------------+
void OnStart()
  {
//--- the server name goes first, so the output says where the scan was run
   ::PrintFormat("Server: %s",::AccountInfoString(ACCOUNT_SERVER));
//--- false: all symbols of the server, not only those in Market Watch
   const int total=::SymbolsTotal(false);
   int reporting=0;
   for(int i=0;i<total;i++)
     {
      const string name=::SymbolName(i,false);
//--- skip symbols for which the depth cannot be read or is zero
      long depth=0;
      if(!::SymbolInfoInteger(name,SYMBOL_TICKS_BOOKDEPTH,depth) || depth<=0)
         continue;
//--- the subscription is only tried, to see whether the server accepts it; no entries are read
      ::ResetLastError();
      const bool added=::MarketBookAdd(name);
      const int error=::GetLastError();
//--- release at once, so the scan does not leave subscriptions open
      if(added)
         ::MarketBookRelease(name);
      ::PrintFormat("%s depth=%I64d bookadd=%s(%d)",name,depth,added?"true":"false",error);
      reporting++;
     }
   ::PrintFormat("Scanned %d symbols, %d report depth above 0",total,reporting);
   return;
  }
//+------------------------------------------------------------------+
