ServerPortfolio  2.0
Python parsers and server
 All Classes Namespaces Files Functions Variables Properties Pages
Public Member Functions | Public Attributes | Private Member Functions | Private Attributes | Static Private Attributes | List of all members
serverportfolio.DictionaryStocks.DictionaryStocks Class Reference

Container of all Stocks objects, it also reads the static stocks configuration file "dictstocks.txt". More...

Inheritance diagram for serverportfolio.DictionaryStocks.DictionaryStocks:
Inheritance graph
[legend]
Collaboration diagram for serverportfolio.DictionaryStocks.DictionaryStocks:
Collaboration graph
[legend]

Public Member Functions

def __init__
 Initialise the singleton dictionary and read the configuration text file. More...
 
def get_stocks
 Return a Stock (or a list of Stock) object(s) from a symbol (or a list of symbols). More...
 
def get_stock_keys
 Return the list of stock symbols loaded from the configuration file, do not create the Stock objects. More...
 
def get_dict_static
 Return the static template from a stock symbol. More...
 
def print_dict_stocks
 Print (a nice) output of the data. More...
 
Basic dictionary functionalities to access the Stock objects
def __getitem__
 Access by key. More...
 
def __setitem__
 Set with key / value. More...
 

Public Attributes

 logger
 

Private Member Functions

def _create_stocks
 Create and initialise Stock objects. More...
 
def _read_config_txt
 Read static definition of the stocks from the configuration text file. More...
 

Private Attributes

 _dictstocks
 Dictionary containing Stock objects with key/value = 'symbol' : Stock object. More...
 
 _dictstocks_config
 Store the content of the static stocks definitions (dictstocks.txt). More...
 
 _file_stocks
 Store the name of the configuration file. More...
 
 _tcp_client
 Access to the TCPClient for sending update to the GUIServer. More...
 

Static Private Attributes

 __metaclass__ = Singleton
 Define DictionaryStocks as a Singleton. More...
 

Detailed Description

Container of all Stocks objects, it also reads the static stocks configuration file "dictstocks.txt".

It is a singleton object, responsible of:

The singleton will be normally initialized at its first use (with the reading of the Static stocks data).
The Stock objects are then initialised on demand by calls to get_stocks()
To force the initialisation of all the stocks in the configuration file, one must call explicitely the constructor:

1 DictionaryStocks.DictionaryStocks(load_all_stock=True)

Functionalities:

The container is basically implemented as a dictionary of Stock.

Definition at line 78 of file DictionaryStocks.py.

Constructor & Destructor Documentation

def serverportfolio.DictionaryStocks.DictionaryStocks.__init__ (   self,
  file_stocks = GlobalDicts.DEFAULT_DICTIONARY,
  load_all_stocks = False 
)

Initialise the singleton dictionary and read the configuration text file.

By default store the content of the stocks definition, but do not initialise the Stock objects.
These objects will be created on demand by calls to get_stocks().
The boolean option load_all_stocks will force to create and initialise all Stock present in the configuration file.

Parameters
file_stocksoptional with default name 'dictstocks.txt'
load_all_stocksif True will create and initialise all Stock objects.

Definition at line 90 of file DictionaryStocks.py.

Member Function Documentation

def serverportfolio.DictionaryStocks.DictionaryStocks.__getitem__ (   self,
  item 
)

Access by key.

return a Stock object, may be an InvalidStock if not present in the configuration file

Definition at line 139 of file DictionaryStocks.py.

References serverportfolio.DictionaryStocks.DictionaryStocks._dictstocks, and serverportfolio.DictionaryStocks.DictionaryStocks.get_stocks().

Here is the call graph for this function:

def serverportfolio.DictionaryStocks.DictionaryStocks.__setitem__ (   self,
  key,
  value 
)

Set with key / value.

Definition at line 148 of file DictionaryStocks.py.

References serverportfolio.DictionaryStocks.DictionaryStocks._dictstocks.

def serverportfolio.DictionaryStocks.DictionaryStocks._create_stocks (   self,
  stock_symbol 
)
private

Create and initialise Stock objects.

If stock_symbol = None, all stocks are loaded. Not good in public interface, ok if private.
Only called by DictionaryStock (with load_all_stocks = True)
If a symbol is wrong (not in the configuration file) an InvalidStock is created instead.

Precondition
The stock(s) should be created only once(assert)
Postcondition
Return a valid list of Stock objects, maybe InvalidStock
Todo:
in case of reload, should recreate the Stock(problem with threads) ?
Parameters
stock_symbollist of symbols to create, if None create all from the configuration file

Definition at line 264 of file DictionaryStocks.py.

References serverportfolio.DictionaryStocks.DictionaryStocks._dictstocks, serverportfolio.DictionaryStocks.DictionaryStocks._dictstocks_config, and serverportfolio.DictionaryStocks.DictionaryStocks.get_dict_static().

Referenced by serverportfolio.DictionaryStocks.DictionaryStocks.get_stocks().

Here is the call graph for this function:

Here is the caller graph for this function:

def serverportfolio.DictionaryStocks.DictionaryStocks._read_config_txt (   self,
  file_stocks 
)
private

Read static definition of the stocks from the configuration text file.

It sets the static data key in the global StockTemplates.StTmpl from the header of dictstocks.txt
Then fill _dictstocks_config with Static stock template (config and template) Use later for Stock creation

Todo:
To implement: reload the file with new stocks or new parameters.
Parameters
file_stocksfilename of the portfolio file, default "dictstocks.txt"
Exceptions
PortfolioErrorif the file cannot be opened

Definition at line 298 of file DictionaryStocks.py.

References serverportfolio.DictionaryStocks.DictionaryStocks._dictstocks_config, and serverportfolio.DictionaryStocks.DictionaryStocks._file_stocks.

def serverportfolio.DictionaryStocks.DictionaryStocks.get_dict_static (   self,
  symbol 
)

Return the static template from a stock symbol.

If the symbol is not in the configuration file, the default Static template is returned

Parameters
symbolof the stock

Definition at line 203 of file DictionaryStocks.py.

References serverportfolio.DictionaryStocks.DictionaryStocks._dictstocks_config.

Referenced by serverportfolio.DictionaryStocks.DictionaryStocks._create_stocks().

Here is the caller graph for this function:

def serverportfolio.DictionaryStocks.DictionaryStocks.get_stock_keys (   self,
  all_stocks = False 
)

Return the list of stock symbols loaded from the configuration file, do not create the Stock objects.

Parameters
all_stocksTrue : return all stocks read from the config file, False : only Stock in memory

Definition at line 193 of file DictionaryStocks.py.

def serverportfolio.DictionaryStocks.DictionaryStocks.get_stocks (   self,
  input_stock 
)

Return a Stock (or a list of Stock) object(s) from a symbol (or a list of symbols).

Initialise the Stock object if necessary.

Postcondition
Always return the required stocks, maybe an InvalidStock exception but assert
Return an InvalidStock if the stock symbol is not in the configuration file
Parameters
input_stocka stock symbol or a list of symbols
Returns
a stock object or a list of stock objects (depends on input)

Definition at line 163 of file DictionaryStocks.py.

References serverportfolio.DictionaryStocks.DictionaryStocks._create_stocks(), and serverportfolio.DictionaryStocks.DictionaryStocks._dictstocks.

Referenced by serverportfolio.DictionaryStocks.DictionaryStocks.__getitem__(), serverportfolio.UpdateStocks.UpdateStocks.check_open(), serverportfolio.DictionaryStocks.DictionaryStocks.print_dict_stocks(), and serverportfolio.UpdateStocks.UpdateStocks.update_xml().

Here is the call graph for this function:

Here is the caller graph for this function:

def serverportfolio.DictionaryStocks.DictionaryStocks.print_dict_stocks (   self,
  action,
  input_stocks = None,
  opt_all_stocks = False,
  opt_header = False 
)

Print (a nice) output of the data.

Can print more than one stock.
If data have not been loaded or Stock is invalid, the format is: 'symbol ERROR error_message'

Parameters
actiontype of data/EAction to return
input_stocksone stock(string) or list of stocks, default None to use with opt_all_stocks
opt_all_stocksprint data from all stocks read in the configuration file, not only loaded as Stocks (InvalidStock do not appear)
opt_headeradd a header line to describe the data
Returns
a string with '
' as separator

Definition at line 218 of file DictionaryStocks.py.

References serverportfolio.DictionaryStocks.DictionaryStocks.get_stocks().

Referenced by serverportfolio.UpdateStocks.UpdateStocks.get_string_data().

Here is the call graph for this function:

Here is the caller graph for this function:

Member Data Documentation

serverportfolio.DictionaryStocks.DictionaryStocks.__metaclass__ = Singleton
staticprivate

Define DictionaryStocks as a Singleton.

A call to DictionaryStocks() will always return the unique instance of the class

Definition at line 81 of file DictionaryStocks.py.

serverportfolio.DictionaryStocks.DictionaryStocks._dictstocks
private

Dictionary containing Stock objects with key/value = 'symbol' : Stock object.

getitem / setitem are implemented to avoid a call to the private data member

Definition at line 96 of file DictionaryStocks.py.

Referenced by serverportfolio.DictionaryStocks.DictionaryStocks.__getitem__(), serverportfolio.DictionaryStocks.DictionaryStocks.__setitem__(), serverportfolio.DictionaryStocks.DictionaryStocks._create_stocks(), and serverportfolio.DictionaryStocks.DictionaryStocks.get_stocks().

serverportfolio.DictionaryStocks.DictionaryStocks._dictstocks_config
private

Store the content of the static stocks definitions (dictstocks.txt).

'Static' data are ead from this configuration file and stored in the 'Static' template

Definition at line 100 of file DictionaryStocks.py.

Referenced by serverportfolio.DictionaryStocks.DictionaryStocks._create_stocks(), serverportfolio.DictionaryStocks.DictionaryStocks._read_config_txt(), and serverportfolio.DictionaryStocks.DictionaryStocks.get_dict_static().

serverportfolio.DictionaryStocks.DictionaryStocks._file_stocks
private

Store the name of the configuration file.

The full path is created in the function _read_config_txt()
multiple configuration files not implemented yet

Definition at line 105 of file DictionaryStocks.py.

Referenced by serverportfolio.DictionaryStocks.DictionaryStocks._read_config_txt().

serverportfolio.DictionaryStocks.DictionaryStocks._tcp_client
private

Access to the TCPClient for sending update to the GUIServer.

If data do not come back after an update, it should be done by Stock or Parser.
keep here is not bad, or independent singleton... but activated only if GUI or receive a message

Todo:
to re-implement, test functionalities

Definition at line 130 of file DictionaryStocks.py.

serverportfolio.DictionaryStocks.DictionaryStocks.logger

The documentation for this class was generated from the following file: