Exemple #1
0
 //Do all stuff to shut down connection with server
 public void Shutdown()
 {
     try
     {
         LogOut("Shuting down");
         this.m_manager.Disconnect();
         this.m_manager.Release();
         SMTManagerAPIFactory.Shutdown();
     }
     catch
     {
         //throw;
     }
 }
Exemple #2
0
 private void Initialize()
 {
     try {
         // Initialize the factory
         MTRetCode res = SMTManagerAPIFactory.Initialize(GetMTDllPath());
         if (MTRetCode.MT_RET_OK != res)
         {
             throw new MT5Exception("SMTManagerAPIFactory.Initialize failed", res);
         }
         // Receive the API version
         res = SMTManagerAPIFactory.GetVersion(out uint version);
         if (MTRetCode.MT_RET_OK != res)
         {
             throw new MT5Exception("SMTManagerAPIFactory.GetVersion failed", res);
         }
         // Check API version
         if (version != SMTManagerAPIFactory.ManagerAPIVersion)
         {
             throw new MT5Exception($"Manager API version mismatch - {version}!={SMTManagerAPIFactory.ManagerAPIVersion}");
         }
         // Create new manager
         ManagerAPI = SMTManagerAPIFactory.CreateManager(version, out res);
         if (MTRetCode.MT_RET_OK != res)
         {
             throw new MT5Exception("SMTManagerAPIFactory.CreateManager failed", res);
         }
         if (null == ManagerAPI)
         {
             throw new MT5Exception("SMTManagerAPIFactory.CreateManager returned null");
         }
         //
         res = RegisterSink();
         if (MTRetCode.MT_RET_OK != res)
         {
             throw new MT5Exception("CIMTManagerSink.RegisterSink failed", res);
         }
         // Subscribe for events
         res = ManagerAPI.Subscribe(this);
         if (MTRetCode.MT_RET_OK != res)
         {
             throw new MT5Exception("CIMTManagerAPI.Subscribe failed", res);
         }
     }
     catch {
         ManagerAPI?.Release();
         SMTManagerAPIFactory.Shutdown();
         throw;
     }
 }
Exemple #3
0
        //+------------------------------------------------------------------+
        //| Initialize library                                               |
        //+------------------------------------------------------------------+
        public bool Initialize()
        {
            string    message = string.Empty;
            MTRetCode res     = MTRetCode.MT_RET_OK_NONE;

            //--- loading manager API
            if ((res = SMTManagerAPIFactory.Initialize(null)) != MTRetCode.MT_RET_OK)
            {
                message = string.Format("Loading manager API failed ({0})", res);
                System.Console.WriteLine(message);
                return(false);
            }
            //--- creating manager interface
            m_manager = SMTManagerAPIFactory.CreateManager(SMTManagerAPIFactory.ManagerAPIVersion, out res);
            if ((res != MTRetCode.MT_RET_OK) || (m_manager == null))
            {
                SMTManagerAPIFactory.Shutdown();
                message = string.Format("Creating manager interface failed ({0})", (res == MTRetCode.MT_RET_OK ? "Managed API is null" : res.ToString()));
                System.Console.WriteLine(message);
                return(false);
            }
            //--- create deal array
            if ((m_deal_array = m_manager.DealCreateArray()) == null)
            {
                m_manager.LoggerOut(EnMTLogCode.MTLogErr, "DealCreateArray fail");
                System.Console.WriteLine("DealCreateArray fail");
                return(false);
            }
            //--- create user interface
            if ((m_user = m_manager.UserCreate()) == null)
            {
                m_manager.LoggerOut(EnMTLogCode.MTLogErr, "UserCreate fail");
                System.Console.WriteLine("UserCreate fail");
                return(false);
            }
            //--- create account interface
            if ((m_account = m_manager.UserCreateAccount()) == null)
            {
                m_manager.LoggerOut(EnMTLogCode.MTLogErr, "UserCreateAccount fail");
                System.Console.WriteLine("UserCreateAccount fail");
                return(false);
            }
            //--- all right
            return(true);
        }
Exemple #4
0
        protected override void Dispose(bool disposing)
        {
            if (Disposed)
            {
                return;
            }

            if (disposing)
            {
                ManagerAPI?.Unsubscribe(this);
                Disconnect();
                ManagerAPI?.Release();
                SMTManagerAPIFactory.Shutdown();
            }
            base.Dispose(disposing);

            Disposed = true;
        }
Exemple #5
0
 //+------------------------------------------------------------------+
 //| Shutdown                                                         |
 //+------------------------------------------------------------------+
 public void Shutdown()
 {
     if (m_deal_array != null)
     {
         m_deal_array.Dispose();
         m_deal_array = null;
     }
     if (m_manager != null)
     {
         m_manager.Dispose();
         m_manager = null;
     }
     if (m_user != null)
     {
         m_user.Dispose();
         m_user = null;
     }
     if (m_account != null)
     {
         m_account.Dispose();
         m_account = null;
     }
     SMTManagerAPIFactory.Shutdown();
 }