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

Update data of a list of Stock's (only one action by call is possible). More...

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

Public Member Functions

def __init__
 Constructor. More...
 
def set_option_post
 To set/unset the options b_save and b_interactive. More...
 
def get_option_post
 Return a new dictionary with the option for post-processing. More...
 
def update_xml
 
def get_string_data
 Update the stock(s) and return the data as multi lines string. More...
 
def check_open
 Parse instantaneous value and check the stock is in state 'OPEN'. More...
 
Wrapper to DictionaryStocks functionalities
def get_stocks
 Return a Stock (or a list of Stock) object(s) from a symbol (or a list of symbols). More...
 
def print_dict_stocks
 Print one line strings of the data. More...
 

Public Attributes

 e_action
 
 b_save
 Indicates if the new data must be saved into the file system, post-processing stage. More...
 
 b_interactive
 Set interactive mode, the user is required to accept / reject the update of data. More...
 

Static Public Attributes

tuple t = threading.Thread(target=run_thread_pool_parser, args=(list_stock, self.e_action, option_post))
 

Private Member Functions

def _set_parser
 Set or reset an action, a correct parser depending on the action. More...
 
def _update_data
 Update stock(s) data according to the specified action. More...
 

Private Attributes

 _logger
 
 _myparser
 
 _dictstocks
 Link to the DictionaryStocks singleton. More...
 
 _multithread
 Allow multi-threading for executing _update_data. More...
 

Detailed Description

Update data of a list of Stock's (only one action by call is possible).

This module allows to choose:

Create and store a appropriate parser object to query a web page and make the post-processing: validation/interactive mode, save_to_file/save_to_xml.
Re-use of the internal parser object needed only for Server, to improve.
Used mainly by the RunParser tool.
Used by C++, with simple arguments.
If optional argument easy to implement in C++, can be provided in constructor.

Definition at line 45 of file UpdateStocks.py.

Constructor & Destructor Documentation

def serverportfolio.UpdateStocks.UpdateStocks.__init__ (   self,
  action,
  option_parser = None,
  opt_multithread = False 
)

Constructor.

Parameters
actionEAction or string of the action to perform, 'NoAction' will not initialise the internal parser.
option_parser(not implemented)
option_multithreadif possible for the action, parsers are run in independent threads

Definition at line 51 of file UpdateStocks.py.

Member Function Documentation

def serverportfolio.UpdateStocks.UpdateStocks._set_parser (   self,
  action_name 
)
private

Set or reset an action, a correct parser depending on the action.

Try to re-use the same parser object if the same action is required.
If not possible, create a new one
Called from _update_data

Parameters
action_namestring or EAction to execute

Definition at line 116 of file UpdateStocks.py.

References serverportfolio.UpdateStocks.UpdateStocks._myparser, serverportfolio.Parsers.Abstract.AbstractParser.e_action, serverportfolio.UpdateStocks.UpdateStocks.e_action, serverportfolio.Parsers.YahooYQL.YahooYQL.e_action, and serverportfolio.Parsers.YahooCSV.YahooCSV.e_action.

Referenced by serverportfolio.UpdateStocks.UpdateStocks._update_data().

Here is the caller graph for this function:

def serverportfolio.UpdateStocks.UpdateStocks._update_data (   self,
  stock,
  action = None 
)
private

Update stock(s) data according to the specified action.

If a specific stock or list of stocks symbol is provided, the Stock object may be created on the fly
If the default None is used, only the Stock objects already loaded in the dictionary are used(option update_all may be added)
The function provides access to any action. if option save is set (by default) data are saved in their respective file. If multithread is required with action InstValue or HistPrice, a thread is created for each thread in this function.

Other post-processes (print, send data to gui_server) must be done by the caller

Parameters
stocksymbol (or list of symbols) of the stock, default None update all stocks from the loaded Stocks (not all from config)
actionstring of the action, must be valid as defined in GlobalDicts.EAction. If None use the default specified in constructor. All cases check the parser is compatible with the action.
opt_parseroption to use a specific parser(not implemented, use only the default one)

Definition at line 157 of file UpdateStocks.py.

References serverportfolio.UpdateStocks.UpdateStocks._multithread, serverportfolio.UpdateStocks.UpdateStocks._myparser, serverportfolio.UpdateStocks.UpdateStocks._set_parser(), serverportfolio.UpdateStocks.UpdateStocks.b_interactive, serverportfolio.Parsers.Abstract.AbstractParser.e_action, serverportfolio.UpdateStocks.UpdateStocks.e_action, serverportfolio.Parsers.YahooYQL.YahooYQL.e_action, serverportfolio.Parsers.YahooCSV.YahooCSV.e_action, and serverportfolio.UpdateStocks.UpdateStocks.get_option_post().

Referenced by serverportfolio.UpdateStocks.UpdateStocks.check_open(), and serverportfolio.UpdateStocks.UpdateStocks.get_string_data().

Here is the call graph for this function:

Here is the caller graph for this function:

def serverportfolio.UpdateStocks.UpdateStocks.check_open (   self,
  stock 
)

Parse instantaneous value and check the stock is in state 'OPEN'.

Called only at the start of AutoParser.
or may call _update_data from AutoParser, and then check with Stock get_state

Precondition
Parser must be loaded with InstValue action (done in AutoParser)
Parameters
stockone unique stock symbol
Returns
boolean if state is 'OPEN'

Definition at line 426 of file UpdateStocks.py.

References serverportfolio.UpdateStocks.UpdateStocks._update_data(), serverportfolio.UpdateStocks.UpdateStocks.get_stocks(), and serverportfolio.DictionaryStocks.DictionaryStocks.get_stocks().

Here is the call graph for this function:

def serverportfolio.UpdateStocks.UpdateStocks.get_option_post (   self)

Return a new dictionary with the option for post-processing.

An entry 'tk_manager' will be added only if needed (interactive/multithread) and supported by action

Returns
dictionary with keys: 'to_save', 'interactive' and 'tk_manager'

Definition at line 103 of file UpdateStocks.py.

References serverportfolio.UpdateStocks.UpdateStocks.b_interactive, and serverportfolio.UpdateStocks.UpdateStocks.b_save.

Referenced by serverportfolio.UpdateStocks.UpdateStocks._update_data().

Here is the caller graph for this function:

def serverportfolio.UpdateStocks.UpdateStocks.get_stocks (   self,
  stock 
)

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

May return InvalidStocks, wrapper to DictionaryStocks.get_stocks()

Definition at line 132 of file UpdateStocks.py.

Referenced by serverportfolio.UpdateStocks.UpdateStocks.check_open(), and serverportfolio.UpdateStocks.UpdateStocks.update_xml().

Here is the caller graph for this function:

def serverportfolio.UpdateStocks.UpdateStocks.get_string_data (   self,
  list_stock,
  action = None,
  opt_header = False,
  opt_parse = True 
)

Update the stock(s) and return the data as multi lines string.

Should work for all actions, print one line by stock.
Easy to call and parse from C++ or other scripts. Called by default by RunParsers.

Parameters
list_stockof the stock symbols
action
opt_headeroptional boolean, print a header before the data
opt_parseif True call an update of the data, if False only print values in memory

Definition at line 407 of file UpdateStocks.py.

References serverportfolio.UpdateStocks.UpdateStocks._update_data(), serverportfolio.Parsers.Abstract.AbstractParser.e_action, serverportfolio.UpdateStocks.UpdateStocks.e_action, serverportfolio.Parsers.YahooYQL.YahooYQL.e_action, serverportfolio.Parsers.YahooCSV.YahooCSV.e_action, serverportfolio.UpdateStocks.UpdateStocks.print_dict_stocks(), and serverportfolio.DictionaryStocks.DictionaryStocks.print_dict_stocks().

Here is the call graph for this function:

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

Print one line strings of the data.

Todo:
Check arguments all used ? all needed ?

Definition at line 137 of file UpdateStocks.py.

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

Here is the caller graph for this function:

def serverportfolio.UpdateStocks.UpdateStocks.set_option_post (   self,
  bool_save = True,
  bool_interactive = False 
)

To set/unset the options b_save and b_interactive.

Parameters
bool_saveboolean to set/unset the option to save to file.
bool_interactiveto set/unset the interative mode

Definition at line 96 of file UpdateStocks.py.

References serverportfolio.UpdateStocks.UpdateStocks.b_interactive, and serverportfolio.UpdateStocks.UpdateStocks.b_save.

def serverportfolio.UpdateStocks.UpdateStocks.update_xml (   self,
  stock 
)

Member Data Documentation

serverportfolio.UpdateStocks.UpdateStocks._dictstocks
private

Link to the DictionaryStocks singleton.

Could pass the option load_all_stocks if created from here...

Definition at line 82 of file UpdateStocks.py.

serverportfolio.UpdateStocks.UpdateStocks._logger
private

Definition at line 63 of file UpdateStocks.py.

serverportfolio.UpdateStocks.UpdateStocks._multithread
private

Allow multi-threading for executing _update_data.

Todo:
check if works for InstValue, HistPrice (DivSplit also).

Definition at line 85 of file UpdateStocks.py.

Referenced by serverportfolio.UpdateStocks.UpdateStocks._update_data().

serverportfolio.UpdateStocks.UpdateStocks._myparser
private
serverportfolio.UpdateStocks.UpdateStocks.b_interactive
serverportfolio.UpdateStocks.UpdateStocks.b_save

Indicates if the new data must be saved into the file system, post-processing stage.

Apply to all types : 'csv' and 'xml'
Default is True, for debugging/testing may need to set to False

Definition at line 89 of file UpdateStocks.py.

Referenced by serverportfolio.UpdateStocks.UpdateStocks.get_option_post(), and serverportfolio.UpdateStocks.UpdateStocks.set_option_post().

serverportfolio.UpdateStocks.UpdateStocks.e_action
tuple serverportfolio.UpdateStocks.UpdateStocks.t = threading.Thread(target=run_thread_pool_parser, args=(list_stock, self.e_action, option_post))
static

Definition at line 213 of file UpdateStocks.py.


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