Exemple #1
0
 //+------------------------------------------------------------------+
 //| 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);
 }