Stock Engine

The stock engine library contains all the classes that implement the engines that execute the funtions related with data acquisition / examination. These features are:

  1. Realtime data acquisition.
  2. Historical data loading.

Realtime data adquisition

The main responsibility of this engine is to take the data given by the accessor and to store it on the database when values change.

Initialization: the real-time engine must initialize the stock groups on the following situations:

  1. The engine has been started: the first time the engine is started the group objects must be created for the first time and initialized to load market times, to read from the db the stock items that conform the group if available and to load the existent quotes if any. If there were stocks not read during the day and its market is closed then they will not appear until the next day.
  2. The market moves from closed to opening: the groups must be initialized to get the new group items, to clear the existent quotes and to initialize the new day. This means that the items that compose a group are read only at initialization time and the group won't be updated until the next initialization (the next day). This will make impossible to capture futures changing their symbol with their market open (like on expiration days).

The quotes to load during first time initialization are:

  • If today is not a working day find the previous working day and load its quotations.
  • If today is a working day and its past today closing time load today's quotations.
  • If today is a working day and its before today opening time find the previous working day and load its quotations.

This is the initialization workflow (to be revised, it's outdated and the workflow has changed):


These are the classes of the Real Time Engine:

  • AcquisitionSystem: this class represents the whole adquisition system. It is the glue that groups all the classes of the system and the one that routes messages from one class to another one. It also publishes the required data for other application systems (like the UI). Using this class and events on the subclasses we reduce the coupling between them.
  • AcquisitionSystemInformation: this class groups all the information about the AcquisitionSystem that could be presented to the user by the UI.
  • AcquisitionEngineScheduler: its responsibility is to start the accessor (and the adquisition engine) on working days when the first market opens and to stop it when the last market closes. To do this it will continuously check the current time. To avoid losing any data the scheduler checks each 10 seconds the market status (this way we can only lose 10 seconds of the preopening bid on the worst case scenario).
  • AcquisitionEngine:  its responsibility is to continuously monitor groups to see when one has to be initialized due to the opening of its maket and to call the acquisitor to generate at regular intervals quotations.
  • Acquisitor: its responsibility is to generate quotations taking them from the accessor if they're available or duplicating the last one and to store them on the quotation calendar and database (if needed).
  • GroupInitializer: its responsibility is to create and initialize the list of groups that the entire acquisition system will use. The initialization workflow is show in a previous figure. Its very important to add the StockItems to the group when the QuotationDailyInfo has been created because it is used by the ViewModel.

Historical data loading

The main responsibility of this engine is to load the data available at the database on request and to provide a list with all the available days with information.

Its very similar to the group initializer because its responsibility is to create and initialize the list of groups that existed at an specific date. Anyway, to avoid giving more responsibilities to the real time GroupInitializer (because this would break the single responsibility paradigm) and to avoid duplicating the GroupInitializer code (because this is agains programming) I will create a new GroupInitializer into the Historical namespace and put what is common between both GroupInitializers into a GroupInitializerBase. This way each class will have its own responsibility and there will be no code duplication.


  • HistoricalSystem: this class represents the whole historical system. . Its main responsibility is to provide all the data available for all groups on a requested day. Almost all the work is relayed on the GroupInitializer. The class also offers to upper layers all the required data (like the available days with data to be shown by the UI).
  • GroupInitializer: its responsibility is to create and initialize the list of groups that the historical system will provide. All the data available on a fixed day will be loaded and returned thru the Groups property. 

Last edited Feb 18, 2013 at 9:04 AM by somos, version 38


No comments yet.