//subscribe some object to receive New connections public void SubscribeConnectSink(ref clsSinkManager mySManager) { if (!CheckIfMannagerWorks()) { return; } var resSManager = mySManager.RegisterSink(); var subscribeResult = m_manager.Subscribe(mySManager); }
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; } }
//+------------------------------------------------------------------+ //| Dealer starting | //+------------------------------------------------------------------+ public bool Start(string server, UInt64 login, string password) { //--- check manager if (m_manager == null) { return(false); } //--- check arguments if (server == null || login == 0 || password == null) { m_manager.LoggerOut(EnMTLogCode.MTLogErr, "Dealer: starting failed with bad arguments"); return(false); } //--- do not let exception get out here try { //--- check if dealer is started already if (m_thread_dealer != null) { //--- dealer thread is running if (m_thread_dealer.IsAlive) { return(false); } //--- m_thread_dealer = null; } //--- save authorize info m_server = server; m_login = login; m_password = password; //--- subscribe for notifications if (m_manager.Subscribe(this) != MTRetCode.MT_RET_OK) { return(false); } //--- subscribe for requests if (m_manager.RequestSubscribe(m_request_sink) != MTRetCode.MT_RET_OK) { return(false); } //--- subscribe for orders if (m_manager.OrderSubscribe(m_order_sink) != MTRetCode.MT_RET_OK) { return(false); } //--- start dealing thread m_stop_flag = 0; m_connected = 0; //--- start thread m_thread_dealer = new Thread(DealerFunc, STACK_SIZE_COMMON); m_thread_dealer.Start(); //--- done return(true); } catch (Exception ex) { if (m_manager != null) { m_manager.LoggerOut(EnMTLogCode.MTLogErr, "Dealer: starting failed - {0}", ex.Message); } //--- MessageBox.Show(ex.Message, "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error); } //--- done with errors return(false); }
public bool Start(string server, UInt64 login, string password) { //--- check manager if (m_manager == null) { return(false); } //--- check arguments if (server == null || login == 0 || password == null) { m_manager.LoggerOut(EnMTLogCode.MTLogErr, "Dealer: starting failed with bad arguments"); return(false); } //--- do not let exception get out here try { //--- check if dealer is started already if (m_thread_dealer != null) { //--- dealer thread is running if (m_thread_dealer.IsAlive) { return(false); } //--- m_thread_dealer = null; } //--- save authorize info m_server = server; m_login = login; m_password = password; //--- subscribe for notifications if (m_manager.Subscribe(this) != MTRetCode.MT_RET_OK) { return(false); } //--- subscribe for requests if (m_manager.DealSubscribe(_dealSink) != MTRetCode.MT_RET_OK) { return(false); } //--- start dealing thread m_stop_flag = 0; m_connected = 0; //--- start thread //m_thread_dealer = new Thread(DealerFunc, STACK_SIZE_COMMON); //m_thread_dealer.Start(); //--- done MTRetCode res = m_manager.Connect(m_server, m_login, m_password, null, CIMTManagerAPI.EnPumpModes.PUMP_MODE_FULL, MT5_CONNECT_TIMEOUT); if (m_manager.DealerStart() != MTRetCode.MT_RET_OK) { } return(true); } catch (Exception ex) { if (m_manager != null) { m_manager.LoggerOut(EnMTLogCode.MTLogErr, "Dealer: starting failed - {0}", ex.Message); } } //--- done with errors return(false); }