ServerPortfolio
2.0
Python parsers and server
|
Container of all Stocks objects, it also reads the static stocks configuration file "dictstocks.txt". More...
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... | |
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:
Functionalities:
The container is basically implemented as a dictionary of Stock.
Definition at line 78 of file DictionaryStocks.py.
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.
file_stocks | optional with default name 'dictstocks.txt' |
load_all_stocks | if True will create and initialise all Stock objects. |
Definition at line 90 of file DictionaryStocks.py.
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().
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.
|
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.
stock_symbol | list 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().
|
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
file_stocks | filename of the portfolio file, default "dictstocks.txt" |
PortfolioError | if 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
symbol | of the stock |
Definition at line 203 of file DictionaryStocks.py.
References serverportfolio.DictionaryStocks.DictionaryStocks._dictstocks_config.
Referenced by serverportfolio.DictionaryStocks.DictionaryStocks._create_stocks().
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.
all_stocks | True : 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.
input_stock | a stock symbol or a list of symbols |
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().
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'
action | type of data/EAction to return |
input_stocks | one stock(string) or list of stocks, default None to use with opt_all_stocks |
opt_all_stocks | print data from all stocks read in the configuration file, not only loaded as Stocks (InvalidStock do not appear) |
opt_header | add a header line to describe the data |
Definition at line 218 of file DictionaryStocks.py.
References serverportfolio.DictionaryStocks.DictionaryStocks.get_stocks().
Referenced by serverportfolio.UpdateStocks.UpdateStocks.get_string_data().
|
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.
|
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().
|
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().
|
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().
|
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
Definition at line 130 of file DictionaryStocks.py.
serverportfolio.DictionaryStocks.DictionaryStocks.logger |
Definition at line 91 of file DictionaryStocks.py.
Referenced by serverportfolio.Validation.ValidationTkHP.__init__(), and serverportfolio.SocketServer_Server.MyHandler_Parser.handle().