// *****************************************************************
 // ****                     Constructors                        ****
 // *****************************************************************
 //
 //
 //    
 /// <summary>
 /// Set values to session, tickers and economic data manager in future listener.
 /// </summary>
 /// <param name="session"></param>
 /// <param name="tickers"></param>
 /// <param name="newTickers"></param>
 /// <param name="economicDataManager"></param>
 public FutureDataListener(Session session, EconomicDataManager economicDataManager, Timer timer)
 {
     m_Session = session;
     m_EconomicDataManager = economicDataManager;
     m_Timer = timer;
     m_Timer.Elapsed += new ElapsedEventHandler(OnFutureDataListeningTimeOut);
 }
Пример #2
0
        // *****************************************************************
        // ****                     Constructors                        ****
        // *****************************************************************
        //
        //
        //
        /// <summary>
        /// Set values to members of writer manager by ticker list, economic data manager, listener manager and connect to the database.
        /// </summary>
        /// <param name="tickers"></param>
        /// <param name="economicDataManager"></param>
        /// <param name="listenerManager"></param>
        public Writer(EconomicDataManager economicDataManager, ListenerManager listenerManager, DataBaseReader dataBaseReader)
        {
            // Set values to members.
            m_EconomicDataManager           = economicDataManager;
            listenerManager.ListenComplete += new EventHandler(Writer_ListenComplete);
            m_DataBaseReader = dataBaseReader;

            // Instantiate other members.
            m_EconomicDataPointQueue = new Queue <EconomicDataPoint>();
            m_WaitHandle             = new EventWaitHandle(false, EventResetMode.ManualReset);

            // Get the current row count in the database.
            m_Row = m_DataBaseReader.DataBaseRowCount;

            try
            {
                // Writing SQL connection.
                StringBuilder dataBaseString = new StringBuilder();
                dataBaseString.AppendFormat("Server={0};User Id={1};Password={2};Database={3};Connection Timeout ={4};"
                                            , m_DataBaseReader.m_Host, m_DataBaseReader.m_Login, m_DataBaseReader.m_Password, m_DataBaseReader.m_DataBase, m_DataBaseReader.m_TimeOutMinutes * 60);
                m_MySqlEconomicDataTableConnection = new MySqlConnection(dataBaseString.ToString());
                m_MySqlEconomicDataTableConnection.Open();
            }
            catch (MySqlException ex)
            {
                Console.WriteLine(ex.ToString());
                Logging.WriteErrorLog(ex.ToString());
            }
        }
        // *****************************************************************
        // ****                     Constructors                        ****
        // *****************************************************************
        //
        //
        //
        /// <summary>
        /// Set values to session, tickers and economic data manager in historical listener.
        /// </summary>
        /// <param name="session"></param>
        /// <param name="tickers"></param>
        /// <param name="newTickers"></param>
        /// <param name="economicDataManager"></param>
        public HistoricalDataListener(Session session, EconomicDataManager economicDataManager, Timer timer)
        {
            m_Session             = session;
            m_EconomicDataManager = economicDataManager;
            m_Timer = timer;

            m_RequestStartDate = economicDataManager.StartDate;
            m_RequestEndDate   = economicDataManager.EndDate;

            m_Timer.Elapsed += new ElapsedEventHandler(OnHistoricalDataListeningTimeOut);
        }
Пример #4
0
        // *****************************************************************
        // ****                     Properties                          ****
        // *****************************************************************
        //
        //
        #endregion//Properties


        #region Public Methods
        // *****************************************************************
        // ****                     Public Methods                      ****
        // *****************************************************************
        //
        //
        //
        //
        //
        //
        /// <summary>
        /// Operate in order and the last step contains creation of another thread.
        /// </summary>
        public void Run()
        {
            // Initiatelize the logging instrument.
            Logging.InitiateLogging(m_CountryCode);
            // Read configuration parameters that include start date, end date and future date from the txt file.
            ReadConfigFile();
            // Create data base reader connection and read all ticker info and economic data from the database.
            DataBaseReader m_DataBaseReader = new DataBaseReader();
            // Create the tickerlist from what we got from the data base reader and also get tickers by country.
            TickerList m_TickerList = new TickerList(m_DataBaseReader, m_CountryCode);

            // Get all tickers from one specified country and prepare chunks of tickers.
            m_TickerList.SetTickersToChunks(m_CountryCode);
            //// Connect to the Bloomberg to get economic data.
            ConnectToBloomberg();

            ////// Test only one ticker!!!
            //m_TickerList.TryOneTicker("UGRSSOTO Index", true);
            //m_StartDate = "20110101";
            //m_FutureDate = "20140201";
            //m_EconomicDataManager = new EconomicDataManager(m_StartDate, m_EndDate, m_FutureDate);
            //m_ListenerManager = new ListenerManager(m_Session, m_TickerList, m_EconomicDataManager);
            //m_Writer = new Writer(m_EconomicDataManager, m_ListenerManager, m_DataBaseReader);
            //m_EconomicDataManager.SetWriter(m_Writer);
            //m_Writer.StringGeneratingComplete += new EventHandler(WriterManager_StringGeneratingComplete);
            //m_ListenerManager.StartEconomicDataListening();

            //// Assign date range for economic data manager.
            m_EconomicDataManager = new EconomicDataManager(m_StartDate, m_EndDate, m_FutureDate);
            // Create listener manager to do chunk by chunk listening.
            m_ListenerManager = new ListenerManager(m_Session, m_TickerList, m_EconomicDataManager);
            // Create writer and currently there is other thread created.
            m_Writer = new Writer(m_EconomicDataManager, m_ListenerManager, m_DataBaseReader);
            // Economic data series need writer.
            m_EconomicDataManager.SetWriter(m_Writer);
            // Subscribe to the event when string generates complete.
            m_Writer.StringGeneratingComplete += new EventHandler(WriterManager_StringGeneratingComplete);
            // Launch listener manager.
            m_ListenerManager.StartEconomicDataListening();
        }
Пример #5
0
        // *****************************************************************
        // ****                     Constructors                        ****
        // *****************************************************************
        //
        //
        //
        /// <summary>
        /// Set values to the members.
        /// </summary>
        /// <param name="session"></param>
        /// <param name="tickers"></param>
        /// <param name="economicDataManager"></param>
        public ListenerManager(Session session, TickerList tickerList, EconomicDataManager economicDataManager)
        {
            // Set corresponding values to members.
            m_TickerList          = tickerList;
            m_Session             = session;
            m_EconomicDataManager = economicDataManager;
            m_EventWaitHandle     = new EventWaitHandle(false, EventResetMode.ManualReset);

            // After future data listen complete, get valid tickers and do latest and historical listening only to those good tickers.
            m_ValidTickers = new List <string>();

            // Set timer.
            m_Timer                  = new Timer();
            m_Timer.Interval         = m_WaitingSeconds * 1000;
            m_Timer.Enabled          = true;
            m_FutureDataListener     = new FutureDataListener(m_Session, m_EconomicDataManager, m_Timer);
            m_LatestDataListener     = new LatestDataListener(m_Session, m_EconomicDataManager, m_Timer);
            m_HistoricalDataListener = new HistoricalDataListener(m_Session, m_EconomicDataManager, m_Timer);
            m_FutureDataListener.FutureListenComplete         += new EventHandler(FutureDataListener_FutureListenComplete);
            m_LatestDataListener.LatestListenComplete         += new EventHandler(LatestDataListener_LatestListenComplete);
            m_HistoricalDataListener.HistoricalListenComplete += new EventHandler(HistoricalDataListener_HistoricalListenComplete);
        }
Пример #6
0
        // *****************************************************************
        // ****                     Constructors                        ****
        // *****************************************************************
        //
        //
        //
        /// <summary>
        /// Set values to members of writer manager by ticker list, economic data manager, listener manager and connect to the database.
        /// </summary>
        /// <param name="tickers"></param>
        /// <param name="economicDataManager"></param>
        /// <param name="listenerManager"></param>
        public WriterManager(List <string> tickers, EconomicDataManager economicDataManager, ListenerManager listenerManager, DataBaseReader dataBaseReader)
        {
            // Set values to members.
            m_Tickers                       = tickers;
            m_EconomicDataManager           = economicDataManager;
            listenerManager.ListenComplete += new EventHandler(WriterManager_ListenComplete);
            m_DataBaseReader                = dataBaseReader;

            // Instantiate other members.
            m_EconomicDataPointQueue = new Queue <EconomicDataPoint>();
            m_WaitHandle             = new EventWaitHandle(false, EventResetMode.ManualReset);

            // Get the current row count in the database.
            m_Row = m_DataBaseReader.DataBaseRowCount;

            // Connect to the data base.
            StringBuilder stringBuilder = new StringBuilder();

            stringBuilder.AppendFormat("Server={0};User Id={1};Password={2};Database={3};Connection Timeout ={4};"
                                       , m_DataBaseReader.m_Host, m_DataBaseReader.m_Login, m_DataBaseReader.m_Password, m_DataBaseReader.m_DataBase, m_DataBaseReader.m_TimeOutMinutes * 60);
            m_MySqlEconomicDataTableConnection = new MySqlConnection(stringBuilder.ToString());
        }