18 using namespace TimeScale;
34 for (
it_stock it_s = vec_stock.begin(); it_s != vec_stock.end(); it_s++)
43 std::cout <<
"Destructor StockManager" << std::endl;
51 std::cout <<
"return already created fstockmanager " << fstockmanager << std::endl;
61 std::cout <<
"new StockManager::getInstance set fpath " << fpath << std::endl;
78 std::cout <<
" StockManager::killInstance, but has not been run, nothing to do " << std::endl;
84 std::cout <<
"Entry StockManager::killInstance( )" << std::endl;
87 delete ( fstockmanager );
110 std::cout <<
"Entry StockManager::GetItStock namestock " << namestock << std::endl;
114 for ( it_s = vec_stock.begin(); it_s != vec_stock.end(); it_s++) {
115 std::cout << (*it_s)->GetName() << std::endl;
116 if ( (*it_s)->GetName() == namestock )
125 std::cout <<
"Entry StockManager::GetItStock namestock " << namestock << std::endl;
129 for ( it_s = vec_stock.cbegin(); it_s != vec_stock.cend(); it_s++) {
130 std::cout << (*it_s)->GetName() << std::endl;
131 if ( (*it_s)->GetName() == namestock )
142 vec_stock.push_back( stock );
149 std::cout <<
"Entry StockManager::ActivateServer()" << std::endl;
153 std::cout <<
"Will create a new TCPServer" << std::endl;
157 std::cout <<
"StockManager::ActivateServer already activated" << std::endl;
165 std::cout <<
"Entry StockManager::DesactivateServer()" << std::endl;
170 std::cout <<
"Will delete the TCPServer " << std::endl;
174 std::cout <<
"StockManager::DesactivateServer was not activated !" << std::endl;
210 std::cout <<
"StockManager::SendDatadCSV message " << message << std::endl;
213 std::string namestock;
214 std::vector<std::string> line_split, messages_str;
228 if ( line_split.size() != 4 )
229 throw StockException( namestock,
"StockManager::SendDatadCSV missing field in message : "+message);
232 namestock = line_split[0];
237 throw StockException( namestock,
"StockManager::SendDatadCSV error in parsing date from TCPServer message : "+message);
242 sp_data.
SetData( tmp_date, Utils::fromString<type_value_data>(line_split[2]) );
243 sp_vol.
SetData( tmp_date, Utils::fromString<type_value_data>(line_split[3]) );
249 it_stock it = GetItStock ( namestock );
251 if ( it != vec_stock.end() ) {
259 if ( list_dcsv == 0 ) {
261 std::cout <<
"namestock " << namestock <<
" not loaded return " << std::endl;
269 list_single->
AddData( sp_data );
276 delete list_single; list_single = 0;
280 list_single_vol->
AddData( sp_vol );
284 delete list_single_vol; list_single_vol = 0;
288 std::cout <<
"\nEnd AddListDataToMap, so need to update" << std::endl;
301 fstockmanager->PrintMap();
307 messages_str.push_back(
"update_dcsv");
308 messages_str.push_back(namestock);
309 fstockmanager->GetSubject()->Updated( messages_str );
315 std::cout <<
" it_stock not found ! return !" << std::endl;
326 for (it_s = vec_stock.cbegin(); it_s != vec_stock.cend(); it_s++) {
327 if ( (*it_s)->GetName() == namestock )
331 std::cout <<
"StockManager did not find " << namestock << std::endl;
340 std::cout <<
"Entry in StockManager::GetListData " << fullname << std::endl;
343 Stock *stock=
nullptr;
361 std::cout <<
"\n\tNot found in StockManager::GetListData return 0" << std::endl;
372 bool new_added =
false;
377 std::cout <<
"\n timescale " << tmscl;
380 std::cout <<
"\n\tStockManager::Load name " << namestock <<
" short_name " << short_name << std::endl;
384 std::cout <<
" first date " << dates.first <<
" last_date " << dates.last << std :: endl;
387 stock = Find ( namestock );
392 std::cout <<
"Stock " << namestock <<
" not loaded, Make a new stock and insert in Vec" << std::endl;
394 stock =
new Stock ( namestock, namestock, fpath );
395 InsertVec_Stock ( stock );
401 std::cout <<
"Stock " << namestock <<
" already exists in StockManager" << std::endl;
419 std::cout <<
"\nStockManager got a StockException" << std::endl;
420 std::cout <<
"with message " << e.
what() << std::endl;
421 std::cout <<
"will rethrow" << std::endl;
426 std::cout <<
"Delete local copy of stock in StockManager::Load" << std::endl;
428 DeleteStock ( namestock );
435 std::cout <<
"\tStockManager::Load retour of Stock::LoadListData " << std::endl;
450 std::cout <<
"Entry AddStock name " << stock->
GetName() << std::endl;
451 std::cout <<
"Stock name " << stock->
GetName() << std::endl;
453 std::string stockname = stock->
GetName();
455 Stock *prev_stock = Find( stockname );
458 if ( prev_stock ==
nullptr ) {
460 std::cout <<
"Stock did not exist, insert it as a new one " << std::endl;
462 InsertVec_Stock ( stock );
479 std::cout <<
" StockManager::DeleteListData " << fname << std::endl;
485 Stock *stock = Find ( namestock );
493 std::cout <<
"ERROR ?? StockManager::DeleteListData do not find stock, error ?? " << namestock << std::endl;
499 std::cout <<
" StockManager::DeleteListData namestock " << stock->
GetName();
500 std::cout <<
" shortname " << shortname << std::endl;
501 std::cout <<
"stock after find " << stock << std::endl;
507 std::cout <<
" Stock->Empty() " << stock->
IsEmpty() << std::endl;
511 std::cout <<
" StockManager has an empty Stock " << stock->
GetName() << std::endl;
513 it_stock it_s = GetItStock ( namestock );
514 if ( it_s == vec_stock.end() ) {
515 std::cout <<
"Get last entry, stock has not been found in vec_stock, ERROR !! " << std::endl;
518 vec_stock.erase ( it_s );
529 std::cout <<
" StockManager::DeleteListDataFromFrame with frame_name " << frame_name << std::endl;
532 DeleteAllListDataFromTimeScale ( namestock, tmscl );
538 std::cout <<
"Entry StockManager::DeleteAllListData from Timescale " << namestock <<
" tmscl " << tmscl << std::endl;
542 Stock *stock = Find ( namestock );
546 std::cout <<
" Stock not found in StockManager::DeleteAllListData" << std::endl;
559 std::cout <<
" StockManager has an empty Stock " << stock->
GetName() << std::endl;
563 it_s = GetItStock ( namestock );
564 if ( it_s == vec_stock.end() ) {
565 std::cout <<
"ERROR ! Get last entry, stock has not been found in vec_stock !!" << std::endl;
567 vec_stock.erase ( it_s );
571 std::cout <<
"ERROR in StockManager::DeleteAllListData, stock is not empty " << std::endl;
581 std::cout <<
"StockManager::DeleteStock " << namestock << std::endl;
584 for (it_s = vec_stock.begin(); it_s != vec_stock.end(); it_s++) {
586 if ( (*it_s)->GetName() == namestock ) {
590 vec_stock.erase ( it_s );
603 std::cout <<
"\n\tStockManager::DeleteStock Stock no found" << namestock <<
"\n" << std::endl;
608 std::cout <<
"===================\n\tShowMap Manager Stock" << std::endl;
609 std::cout <<
"Size of StockManager " << vec_stock.size() <<
"\n" << std::endl;
612 for (
it_stock it_s = vec_stock.begin(); it_s != vec_stock.end(); it_s++)
614 std::cout <<
"name stock " << (*it_s)->GetName() ;
615 std::cout <<
" symbol stock " << (*it_s)->GetSymbol() << std::endl;
617 (*it_s)->PrintMapChrono();
Singleton class, stores all loaded stocks.
Define the class Stock to deal with an unique stock: DJ, IBM...
Define a list of DataStock objects.
virtual void AddData(DataStock &)=0
Add a copy of the DataStock into the ListDataStock.
"Clever" enumeration of the ListDataStock type : StockCSV, Volume, EMA, BOLL,...
virtual const char * what() const noexcept
std::string GetNameStock(const std::string &frame_name)
Extract the stock name from a frame name.
ETime GetTimeScale(const std::string &frame_name)
Extract the TimeScale from a frame name.
ListDataStock< SimpleData, VecChronologic > ldata_volume
Volume has also one value.
void PrintData(const unsigned int verbose=0) const
User friendly output on screen.
Stock * Load(const std::string namestock, const ETime &tmscl, const Indicator &indic, std::vector< int > param=std::vector< int >(), Utils::firstlast_dates dates=Utils::get_fldate_default())
Load a specific ListDataStock.
Base Exception for Stock and StockManager, all src_cpp code.
bool IsEmpty() const
Test if some ListData are still present, whatever the timescale.
void DeleteAllListDataFromTimeScale(const std::string &namestock, const ETime &tmscl)
Delete all listdata of a stock for a timescale.
static StockManager * getInstance(std::string new_path=".")
Get a singleton instance.
std::string GetNameStock(const std::string &fname)
Extract the name of the stock.
ListDataStockBase * GetListData(const std::string &fullname) const
Retrieve an instance of a ListDataStock.
void DeleteStock(const std::string namestock)
Delete a stock and all its content.
Main class to deal with one stock.
bool ActivateServer()
Activate the server, by default null in constructor.
int AddListDataToMap(const ETime &tmscl, ListDataStockBase *p_listdata)
Insert a ListDataStock to the map.
const time_t ERROR_StrToTime
Error code returned by StringToTime_t if the string cannot be parsed correctly Must be a time_t...
Concrete class for the subject/observable of StockManager.
static TCPServer * ftcp
owns a TCPServer, but inverse is true as well.
static bool status_sm
static boolean status
void DeleteListData(const ETime &tmscl, const Indicator &indic, std::vector< int > param=std::vector< int >())
Delete a list given the TimeScale, Indicator and param.
ETime
Enumeration for the different time representation, from instantaneous (INST) to year(YEAR) ...
static Indicator const StockInst
ListDataStockBase * GetListData(const ETime &tmscl, const Indicator &indic, const std::vector< int > param=std::vector< int >()) const
Get the ListDataStock from a TimeScale, Indicator and vector of parameters.
static SMSubject * fsubject
owns a subject/observable for the observer pattern
bool CheckLoaded(const ETime &tmscl) const
it_stock GetItStock(const std::string &namestock)
Return iterator on the element.
virtual void SetData(const time_t d, const std::vector< type_value_data > &vec)
Set a full Data : date + value(s) in a vector.
void SendDatadCSV(const std::string &message)
Extract info from the message coming from TCPServer, update the Lists and notify observers (GUIMainCo...
time_t StringToTime_t(const std::string &str_date)
Return the time_t from a string .
std::string GetShortName(const std::string &fname)
Extract Indicator_params (string) from a fullname.
void MergeStock(const Stock *new_stock, bool)
Merge entries with an other stock.
Use with RealTime to receive messages from python ServerPortfolio.
Stock * Find(const std::string &namestock) const
Retrieve an instance of a stock.
Stores all stocks and defines convenient functions.
Derive class which contains only one value of type type_value_data (float or double).
virtual void SetDates(const time_t first, const time_t last)
Set dates, 2 arguments.
std::vector< Stock * >::iterator it_stock
std::vector< Stock * >::const_iterator cit_stock
Abstract base class for the ListDataStock, for storing base pointers in vectors.
void Updated(const ETime tmscl)
Return the last available date of historical data.
void DeleteAllListData(const ETime &tmscl)
Delete all data of the given TimeScale.
static void killInstance()
Delete the instance and allocated ressources.
static StockManager * fstockmanager
static instance
int LoadListData(const ETime &tmscl, const Indicator &indic=Indicator::StockCSV, const std::vector< int > ¶m=std::vector< int >(), Utils::firstlast_dates dates=Utils::get_fldate_default())
Load or/and compute an indicator in the Stock.
std::string MakeShortName(const Indicator &indic, const std::vector< int > ¶m)
Create a short name from its components.
static std::string fpath
path of the data, set during singleton initialization
void DeleteAllListDataFromFrame(const std::string &frame_name)
Delete all data of a frame_name,i.e, CAC40_DAY just easy to use from GUI, just call DeleteAllListData...
void splitline(const std::string &str, const std::string &delimiters, std::vector< std::string > &tokens)
splitline
general structure for dates in csv files
int AddStock(Stock *)
Add a stock to the stockmanager.
void PrintMap()
Print an user-friendly view of the StockManger content.
std::string GetName() const
void DeleteListData(const std::string &fname)
Delete a specific ListDataStcok, just wrappers to Stock.
Derive from Subject class.
ETime GetTimeScale(const std::string &fname)
Extract the TimeScale from a fullname.
void InsertVec_Stock(Stock *)
Insert a vector.
Server to receive new Instantaneous data from ServerPortfolio.