Beispiel #1
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;
     }
 }
Beispiel #2
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);
        }
Beispiel #3
0
        public MTRetCode Initialize()
        {
            MTRetCode res = MTRetCode.MT_RET_ERROR;

            //--- Initialize the factory
            if ((res = SMTManagerAPIFactory.Initialize(@"..\..\API\")) != MTRetCode.MT_RET_OK)
            {
                LogOut($"SMTManagerAPIFactory.Initialize failed - {res}");
                return(res);
            }

            //--- Receive the API version
            uint version = 0;

            if ((res = SMTManagerAPIFactory.GetVersion(out version)) != MTRetCode.MT_RET_OK)
            {
                LogOut($"SMTManagerAPIFactory.GetVersion failed - {res}");
                return(res);
            }
            //--- Compare the obtained version with the library one
            if (version != SMTManagerAPIFactory.ManagerAPIVersion)
            {
                LogOut($"Manager API version mismatch - {version}!={SMTManagerAPIFactory.ManagerAPIVersion}");
                return(MTRetCode.MT_RET_ERROR);
            }
            //--- Create an instance
            m_manager = SMTManagerAPIFactory.CreateManager(SMTManagerAPIFactory.ManagerAPIVersion, out res);
            if (res != MTRetCode.MT_RET_OK)
            {
                LogOut($"SMTManagerAPIFactory.CreateManager failed - {res}");
                return(res);
            }

            //--- For some reasons, the creation method returned OK and the null pointer
            if (m_manager == null)
            {
                LogOut("SMTManagerAPIFactory.CreateManager was ok, but ManagerAPI is null");
                return(MTRetCode.MT_RET_ERR_MEM);
            }

            //--- All is well
            LogOut($"Using ManagerAPI v. {version}");
            return(res);
        }
Beispiel #4
0
        //+------------------------------------------------------------------+
        //| Initialize library                                               |
        //+------------------------------------------------------------------+
        public bool Initialize(CDealerExampleDlg parent)
        {
            //---
            string    message = string.Empty;
            MTRetCode res     = MTRetCode.MT_RET_OK_NONE;
            uint      version = 0;

            //--- check
            if (parent == null)
            {
                return(false);
            }
            m_parent = parent;
            //---
            try
            {
                //--- init CIMTManagerSink native link
                if ((res = RegisterSink()) != MTRetCode.MT_RET_OK)
                {
                    message = string.Format("Register sink failed ({0})", res);
                    MessageBox.Show(message, "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return(false);
                }
                //--- loading manager API
                if ((res = SMTManagerAPIFactory.Initialize(@"..\..\..\API\")) != MTRetCode.MT_RET_OK)
                {
                    message = string.Format("Loading manager API failed ({0})", res);
                    MessageBox.Show(message, "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return(false);
                }
                //--- check Manager API version
                if ((res = SMTManagerAPIFactory.GetVersion(out version)) != MTRetCode.MT_RET_OK)
                {
                    message = string.Format("Dealer: getting version failed ({0})", res);
                    MessageBox.Show(message, "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return(false);
                }
                if (version != SMTManagerAPIFactory.ManagerAPIVersion)
                {
                    message = string.Format("Dealer: wrong Manager API version, version {0} required", SMTManagerAPIFactory.ManagerAPIVersion);
                    MessageBox.Show(message, "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return(false);
                }
                //--- create manager interface
                if ((m_manager = SMTManagerAPIFactory.CreateManager(SMTManagerAPIFactory.ManagerAPIVersion, out res)) == null || res != MTRetCode.MT_RET_OK)
                {
                    message = string.Format("Dealer: creating manager interface failed ({0})", res);
                    MessageBox.Show(message, "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return(false);
                }
                //--- create request object
                if ((m_request = m_manager.RequestCreate()) == null)
                {
                    m_manager.LoggerOut(EnMTLogCode.MTLogErr, "Dealer: creating request object failed");
                    MessageBox.Show("Dealer: creating request object failed", "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return(false);
                }
                //--- create confirmation object
                if ((m_confirm = m_manager.DealerConfirmCreate()) == null)
                {
                    m_manager.LoggerOut(EnMTLogCode.MTLogErr, "Dealer: creating confirmation object failed");
                    MessageBox.Show("Dealer: creating confirmation object failed", "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return(false);
                }
                //--- create requests event
                m_event_request = new EventWaitHandle(false, EventResetMode.ManualReset);
                //--- create requests event
                m_event_answer = new EventWaitHandle(false, EventResetMode.AutoReset);
                //---
                m_request_sink = new CRequestSink();
                if ((res = m_request_sink.Initialize(m_manager, m_event_request)) != MTRetCode.MT_RET_OK)
                {
                    m_manager.LoggerOut(EnMTLogCode.MTLogErr, "Dealer: creating request sink failed");
                    MessageBox.Show("Dealer: creating request sink failed", "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return(false);
                }
                //---
                m_order_sink = new COrderSink();
                if ((res = m_order_sink.Initialize(m_manager)) != MTRetCode.MT_RET_OK)
                {
                    m_manager.LoggerOut(EnMTLogCode.MTLogErr, "Dealer: creating request sink failed");
                    MessageBox.Show("Dealer: creating request sink failed", "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return(false);
                }
                //--- done
                return(true);
            }
            catch (Exception ex)
            {
                if (m_manager != null)
                {
                    m_manager.LoggerOut(EnMTLogCode.MTLogErr, "Dealer: initialization failed - {0}", ex.Message);
                }
                //---
                MessageBox.Show(ex.Message, "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            //--- done with errors
            return(false);
        }