Visión general de las funciones para obtener las propiedades de la cuenta

El conjunto completo de propiedades de las cuentas se divide lógicamente en tres grupos en función de su tipo. Las propiedades de cadena se resumen en la enumeración ENUM_ACCOUNT_INFO_STRING y se consultan mediante la función AccountInfoString. Las propiedades de tipo real se combinan en la enumeración ENUM_ACCOUNT_INFO_DOUBLE, y la función que trabaja para ellas es AccountInfoDouble. La enumeración ENUM_ACCOUNT_INFO_INTEGER utilizada en la función AccountInfoInteger contiene identificadores de propiedades de enteros y booleanos (banderas), así como varias enumeraciones ENUM_ACCOUNT_INFO aplicadas.

double AccountInfoDouble(ENUM_ACCOUNT_INFO_DOUBLE property)

long AccountInfoInteger(ENUM_ACCOUNT_INFO_INTEGER property)

string AccountInfoString(ENUM_ACCOUNT_INFO_STRING property)

Hemos creado la clase AccountMonitor (AccountMonitor.mqh) para simplificar la lectura de las propiedades. Mediante la sobrecarga de los métodos get, la clase proporciona la llamada automática de la función API requerida dependiendo del elemento de una enumeración específica pasada en el parámetro.

class AccountMonitor
{
public:
   long get(const ENUM_ACCOUNT_INFO_INTEGER propertyconst
   {
      return AccountInfoInteger(property);
   }
   
   double get(const ENUM_ACCOUNT_INFO_DOUBLE propertyconst
   {
      return AccountInfoDouble(property);
   }
   
   string get(const ENUM_ACCOUNT_INFO_STRING propertyconst
   {
      return AccountInfoString(property);
   }
   
   long get(const int propertyconst longconst
   {
      return AccountInfoInteger((ENUM_ACCOUNT_INFO_INTEGER)property);
   }
   
   double get(const int propertyconst doubleconst
   {
      return AccountInfoDouble((ENUM_ACCOUNT_INFO_DOUBLE)property);
   }
   
   string get(const int propertyconst stringconst
   {
      return AccountInfoString((ENUM_ACCOUNT_INFO_STRING)property);
   }
   ...

Además, dispone de varias sobrecargas del método stringify, que forman una representación de cadena fácil de usar de los valores de las propiedades (en concreto, esto es útil para las enumeraciones aplicadas, que de otro modo se mostrarían como números poco informativos). Las características de cada propiedad se analizarán en las secciones siguientes.

   static string boolean(const long v)
   {
      return v ? "true" : "false";
   }
   
   template<typename E>
   static string enumstr(const long v)
   {
      return EnumToString((E)v);
   }
   
   // "decode" properties according to subtype inside integer values
   static string stringify(const long vconst ENUM_ACCOUNT_INFO_INTEGER property)
   {
      switch(property)
      {
         case ACCOUNT_TRADE_ALLOWED:
         case ACCOUNT_TRADE_EXPERT:
         case ACCOUNT_FIFO_CLOSE:
            return boolean(v);
         case ACCOUNT_TRADE_MODE:
            return enumstr<ENUM_ACCOUNT_TRADE_MODE>(v);
         case ACCOUNT_MARGIN_MODE:
            return enumstr<ENUM_ACCOUNT_MARGIN_MODE>(v);
         case ACCOUNT_MARGIN_SO_MODE:
            return enumstr<ENUM_ACCOUNT_STOPOUT_MODE>(v);
      }
      
      return (string)v;
   }
   
   string stringify(const ENUM_ACCOUNT_INFO_INTEGER propertyconst
   {
      return stringify(AccountInfoInteger(property), property);
   }
   
   string stringify(const ENUM_ACCOUNT_INFO_DOUBLE propertyconst string format = NULLconst
   {
      if(format == NULLreturn DoubleToString(AccountInfoDouble(property),
         (int)get(ACCOUNT_CURRENCY_DIGITS));
      return StringFormat(formatAccountInfoDouble(property));
   }
   
   string stringify(const ENUM_ACCOUNT_INFO_STRING propertyconst
   {
      return AccountInfoString(property);
   }
   ...

Por último, existe un método de plantilla list2log que permite obtener información exhaustiva sobre la cuenta.

   // list of names and values of all properties of enum type E
   template<typename E>
   void list2log()
   {
      E e = (E)0// suppress warning 'possible use of uninitialized variable'
      int array[];
      const int n = EnumToArray(earray0USHORT_MAX);
      Print(typename(E), " Count="n);
      for(int i = 0i < n; ++i)
      {
         e = (E)array[i];
         PrintFormat("% 3d %s=%s"iEnumToString(e), stringify(e));
      }
   }
};

Veremos la nueva clase en acción en la siguiente sección.