ROOT_Application  2.0
C++ Core modules and GUIStock
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
StockManager.cpp
Go to the documentation of this file.
1 
9 #include "StockManager.h"
10 
11 #include "TCPServer.h"
12 #include "SMSubject.h"
13 #include "Stock.h"
14 #include "ListDataStock.h"
15 
16 // strange needed for TimeScale operator<<, otherwise does not compile
17 // happens because boost libraries ??
18 using namespace TimeScale;
19 
20 // should make a namespace, this variable should not be called anyway
21 // could be in constructor / getInstance ??
22 // cannot make a namespace ?? unamed to try, should make test ...
23 bool StockManager::status_sm = false;
25 // to get a default value ?? not only, needed because static
26 std::string StockManager::fpath = ".";
27 
30 
31 
33 {
34  for (it_stock it_s = vec_stock.begin(); it_s != vec_stock.end(); it_s++)
35  delete(*it_s);
36 
37  vec_stock.clear();
38  status_sm = false;
39  DesactivateServer();
40  ftcp = 0;
41  fstockmanager = 0;
42 #ifdef DEBUG_CPP
43  std::cout << "Destructor StockManager" << std::endl;
44 #endif
45 }
46 
47 StockManager* StockManager::getInstance( std::string new_path )
48 {
49  if (status_sm) {
50 #ifdef DEBUG_CPP
51  std::cout << "return already created fstockmanager " << fstockmanager << std::endl;
52 #endif
53 
54  } else {
55  fstockmanager = new StockManager();
56  status_sm = true;
57  // stupid ?? no it is static...
58  //StockManager::fpath = new_path;
59  fpath = new_path;
60 #ifdef DEBUG_CPP
61  std::cout << "new StockManager::getInstance set fpath " << fpath << std::endl;
62 #endif
63  //by default server, but inactive ??
64  //easy no server
65  ftcp = 0;
66  // by default observer pattern active
67  fsubject = new SMSubject();
68  }
69 
70  return fstockmanager;
71 }
72 
74 {
75  if (!status_sm) {
76  //return fstockmanager;
77 #ifdef DEBUG_CPP
78  std::cout << " StockManager::killInstance, but has not been run, nothing to do " << std::endl;
79 #endif
80  return;
81  }
82  else {
83 #ifdef DEBUG_CPP
84  std::cout << "Entry StockManager::killInstance( )" << std::endl;
85 #endif
86  fpath.clear();
87  delete ( fstockmanager );
88  fstockmanager = 0;
89  delete ( fsubject );
90  fsubject = 0;
91 
92  // Should be in calling function, link ftcp to delete anyway
93  if ( ftcp ) {
94  //ftcp->StopServer(); //not necessary for valgrind
95  delete ftcp;
96  ftcp = 0;
97  }
98  // cannot call without object...
99  //StockManager::DesactivateServer();
100 
101  status_sm = false;
102  }
103  return;
104 }
105 
106 // cannot call erase with const iterator, try two version, need to not be const as well
107 StockManager::it_stock StockManager::GetItStock ( const std::string& namestock )
108 {
109 #ifdef DEBUG_CPP
110  std::cout << "Entry StockManager::GetItStock namestock " << namestock << std::endl;
111 #endif
112 
113  it_stock it_s;
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 )
117  return it_s;
118  }
119  return it_s;
120 }
121 
122 StockManager::cit_stock StockManager::GetItStock ( const std::string& namestock ) const
123 {
124 #ifdef DEBUG_CPP
125  std::cout << "Entry StockManager::GetItStock namestock " << namestock << std::endl;
126 #endif
127 
128  cit_stock it_s;
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 )
132  return it_s;
133  }
134  return it_s;
135 }
136 
137 
138 // do not check if already existing, private ok
140 {
141  //add to vector list of StockManager
142  vec_stock.push_back( stock );
143 }
144 
145 
147 {
148 #ifdef DEBUG_CPP
149  std::cout << "Entry StockManager::ActivateServer()" << std::endl;
150 #endif
151 
152  if ( ftcp == 0 ) {
153  std::cout << "Will create a new TCPServer" << std::endl;
154  //ftcp = new TCPServer( this, 9998 );
155 
156  } else
157  std::cout << "StockManager::ActivateServer already activated" << std::endl;
158 
159  return true;
160 }
161 
163 {
164 #ifdef DEBUG_CPP
165  std::cout << "Entry StockManager::DesactivateServer()" << std::endl;
166 #endif
167  // commented, but still double free, nothing to see it was garbage
168  // still something missing
169  if ( ftcp != 0 ) {
170  std::cout << "Will delete the TCPServer " << std::endl;
171  delete ftcp;
172  ftcp = 0;
173  } else
174  std::cout << "StockManager::DesactivateServer was not activated !" << std::endl;
175 
176  return true;
177 }
178 
179 // Called by TCPServer, which sends the new data by string.
180 //
181 // Problem, how to notify GUI from here:
182 // - A ( optional ) pointer to GUI or MainGUIController, strong coupling GUI and ROOT classes.
183 // - A mediator pattern : Mediator_gui, need only class Mediator;
184 // StockManager refer to Mediator only and call mediator->StockUpdated( option )
185 // // mediator need GUI/MainController.h in//cpp, so coupling again
186 // Mediator has a pointer to GUI or MainGUIController and call gui->Update( option )
187 //
188 // - An observer pattern : ++ more decoupling, run-time registration.
189 // -- complex, need class to derive from Subject and Observer
190 // Powerfull, but necessary here ???
191 // Can try to use only the necessary part of it, but maybe later need a full implementation
192 // see template approach for Observer http://accu.org/index.php/journals/308
193 //
194 // Seems the best solution, if general could be applied with gui_app or other...,
195 // whenever StockManager needs to send a signal ( after any computation in fact, good for threading )
196 // StockManager is Subject/Observable
197 // gui is an Observer it must register to be informed, easy because StockManager is singleton !
198 //
199 // - Just need derivation for decoupling ?? and/or registration ?? so full pattern !
200 // can optional in this way, not a bad idea !
201 // alternative StockManager has an object Subject/Observable and send to this object the update
202 //
203 // link to observer pattern :
204 // http://www.oodesign.com/observer-pattern.html
205 // see template approach for Observer http://accu.org/index.php/journals/308
206 //
207 void StockManager::SendDatadCSV( const std::string& message ) throw (StockException)
208 {
209 #ifdef DEBUG_CPP
210  std::cout << "StockManager::SendDatadCSV message " << message << std::endl;
211 #endif
212 
213  std::string namestock;
214  std::vector<std::string> line_split, messages_str;
215  time_t tmp_date;
216  SimpleData sp_data, sp_vol;
217  Stock * stock;
218 
219  ListDataStockBase *list_dcsv;
220  //ldata_volume *list_single;
221  ListDataStockBase *list_single, *list_single_vol;
222 
223  // split message by comma
224  Utils::splitline ( message, ",", line_split );
225 
226  // Nothing to delete here, can exit without problem
227  // check size after split , always 4 for instantaneous data
228  if ( line_split.size() != 4 )
229  throw StockException( namestock, "StockManager::SendDatadCSV missing field in message : "+message);
230 
231  // Extract namestock
232  namestock = line_split[0];
233 
234  // Extract date
235  tmp_date = Utils::StringToTime_t( line_split[1] );
236  if ( tmp_date == Utils::ERROR_StrToTime ) {
237  throw StockException( namestock, "StockManager::SendDatadCSV error in parsing date from TCPServer message : "+message);
238  }
239 
240 
241  // If value is missing set value to 0, no exception generated. better to test the size
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]) );
244 
245  sp_data.PrintData( 3 );
246  sp_vol.PrintData( 3 );
247 
248  // to check exists !
249  it_stock it = GetItStock ( namestock );
250 
251  if ( it != vec_stock.end() ) {
252  //std::cout << "found it_stock " << std::endl;
253  // Get the stock and the list
254  stock = *it;
255 
256  // no need to test if use stock AddListDataToMap, no need to load list_dcsv ??
257  // test, because do not want to create a new entry in stock
258  list_dcsv = stock->GetListData( ETime::INST, Indicator::StockInst );
259  if ( list_dcsv == 0 ) {
260 #ifdef DEBUG_CPP
261  std::cout << "namestock " << namestock << " not loaded return " << std::endl;
262 #endif
263  return;
264  }
265 
266  // update the list, tricky directly, better to create a list_single
267  list_single = new ldata_volume( "StockInst", ETime::INST, 1 );
268  // here only one, no problem of order
269  list_single->AddData( sp_data );
270  // get dates from the data
271  list_single->SetDates();
272 
273  // general function to call, maybe general call from Stock is better, safer...
274  // need to test if delete, should be always called
275  if ( stock->AddListDataToMap( ETime::INST, list_single ) == 1 ) {
276  delete list_single; list_single = 0;
277  }
278  //same for volume
279  list_single_vol = new ldata_volume( "Volume", ETime::INST, 1 );
280  list_single_vol->AddData( sp_vol );
281  list_single_vol->SetDates();
282  // need to test if need to be deleted
283  if ( stock->AddListDataToMap( ETime::INST, list_single_vol ) == 1 ) {
284  delete list_single_vol; list_single_vol = 0;
285  }
286 
287 #ifdef DEBUG_CPP
288  std::cout << "\nEnd AddListDataToMap, so need to update" << std::endl;
289 #endif
290  // better in Stock. independent, will call UpdateAllTimeScale
291  // should assure than related indicator are updated
292  // a different thread may be good here, or even before.
293  stock->Updated ( ETime::INST );
294 
295  // if threaded here wait for the end join ??
296 
297  // can broadcast to observers than data changed
298  // need to add argument... namestock / TimeScale ??
299  // if threaded update, should wait the update is done
300 #ifdef DEBUG_CPP
301  fstockmanager->PrintMap();
302 #endif
303  // add data about the update
304  // all indicators have been update, frame_name is possible
305  // ok only dcsv updated, but influence all, even DAY, WEEK, MONTH...
306  // namestock is needed
307  messages_str.push_back("update_dcsv"); //action
308  messages_str.push_back(namestock);
309  fstockmanager->GetSubject()->Updated( messages_str );
310 
311  // by default do not create a new stock if not already loaded, maybe easily changed
312  // Should be exception ?? not realyy
313  } else {
314 #ifdef DEBUG_CPP
315  std::cout << " it_stock not found ! return !" << std::endl;
316 #endif
317  return;
318  }
319  return;
320 }
321 
322 //keep only name for getting Stock, this stock will contain all variant: time and indicator.
323 Stock * StockManager::Find( const std::string & namestock ) const
324 {
325  cit_stock it_s;
326  for (it_s = vec_stock.cbegin(); it_s != vec_stock.cend(); it_s++) {
327  if ( (*it_s)->GetName() == namestock )
328  return *it_s;
329  }
330 #ifdef DEBUG_CPP
331  std::cout << "StockManager did not find " << namestock << std::endl;
332 #endif
333  return nullptr;
334 }
335 
336 // here only GetListData throw exception
337 ListDataStockBase * StockManager::GetListData ( const std::string& fullname ) const throw(StockException)
338 {
339 #ifdef DEBUG_CPP
340  std::cout << "Entry in StockManager::GetListData " << fullname << std::endl;
341 #endif
342 
343  Stock *stock= nullptr;
344  ListDataStockBase* listdata = nullptr;
345 
346  stock = Find ( FullName::GetNameStock( fullname ) );
347  //std::cout << "pointer stock " << stock << std::endl;
348  if ( stock ) {
349  //std::cout << "found stock" << std::endl;
350  //std::cout << FullName::GetTimeScale( fullname ) << " " << FullName::GetShortName( fullname ) << std::endl;
351  listdata = stock->GetListData ( FullName::GetTimeScale( fullname ), FullName::GetShortName( fullname ) );
352  // throw exception now ?? to check !
353  //if ( listdata )
354  //std::cout << "StockManager::GetListData ldata size " << listdata->GetSize() << std::endl;
355  return listdata;
356  }
357 
358  // Find does not send exception, but GetListData will do
359  // want a stock exception send from here ?? makes sense
360 #ifdef DEBUG_CPP
361  std::cout << "\n\tNot found in StockManager::GetListData return 0" << std::endl;
362 #endif
363  return nullptr;
364 }
365 
366 // not reference for namestock, test "CAC40" need to cast char * to std::string
367 Stock * StockManager::Load ( const std::string namestock , const ETime& tmscl, const Indicator& indic,
368  std::vector< int > param, Utils::firstlast_dates dates ) throw(StockException)
369 {
370  //if error in reading, we can delete the newly added stock, else keep existing (if DAY is ok, but dcsv is missing)
371  // why not to be sure it is correct ?
372  bool new_added = false;
373  Stock * stock;
374 
375  // from Stock, not really logic, separate indic param or use short_name ?? redundant
376  std::string short_name = ShortName::MakeShortName( indic, param);
377  std::cout << "\n timescale " << tmscl;
378 
379 #ifdef DEBUG_CPP
380  std::cout << "\n\tStockManager::Load name " << namestock << " short_name " << short_name << std::endl;
381  // do not compile here ??
382  //std::cout << "\n timescale " << tmscl;
383  //std::cout << " fpath " << fpath << std::endl;
384  std::cout << " first date " << dates.first << " last_date " << dates.last << std :: endl;
385 #endif
386 
387  stock = Find ( namestock );
388 
389  // it does not exist, create a new one
390  if ( !stock ) {
391 #ifdef DEBUG_CPP
392  std::cout << "Stock " << namestock << " not loaded, Make a new stock and insert in Vec" << std::endl;
393 #endif
394  stock = new Stock ( namestock, namestock, fpath );
395  InsertVec_Stock ( stock );
396  new_added = true;
397  //std::cout << "StockManager after InsertVec_Stock size " << vec_stock.size() << std::endl;
398  }
399 #ifdef DEBUG_CPP
400  else
401  std::cout << "Stock " << namestock << " already exists in StockManager" << std::endl;
402 #endif
403 
404  // Test if the indicator is already loaded
405  if ( stock->CheckLoaded ( tmscl, short_name ) ) {
406  //std::cout << "StockManager::Load Data for stock " << namestock << " data " << tmscl << " " << short_name << " already loaded " << std::endl;
407  return stock;
408  }
409  //std::cout << " StockManager::Load Need to create and load a new ListDataStock " << tmscl << " " << short_name << std::endl;
410 
411  // here catch, because nay need to delete the stock object
412  try {
413  stock->LoadListData ( tmscl, indic, param, dates );
414  // here wait for StockException get the Error file but downgrad !!
415  // it receives a FileError or TALibError or other...
416  // to check
417  } catch ( const StockException & e ) {
418 #ifdef DEBUG_CPP
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;
422 #endif
423  // clean before throwing the error
424  if ( new_added ) {
425 #ifdef DEBUG_CPP
426  std::cout << "Delete local copy of stock in StockManager::Load" << std::endl;
427 #endif
428  DeleteStock ( namestock );
429  }
430  // rethrow the StockException
431  throw;
432  }
433  //stock->PrintMap();
434 #ifdef DEBUG_CPP
435  std::cout << "\tStockManager::Load retour of Stock::LoadListData " << std::endl; //<< retour << "\n" << std::endl;
436 #endif
437 
438  return stock;
439 }
440 
441 // used from GUI, inserting a new stock
442 // should check if already exists, not done in InsertVec_Stock
443 // convenient function, allow to create the stock, check dates (like in GUI)
444 // what so ever and insert after,
445 // how to report error ? status ? exception ? exception is better
446 int StockManager::AddStock ( Stock *stock ) //throw (StockException)
447 {
448  // to check if already in vec_stock
449 #ifdef DEBUG_CPP
450  std::cout << "Entry AddStock name " << stock->GetName() << std::endl;
451  std::cout << "Stock name " << stock->GetName() << std::endl;
452 #endif
453  std::string stockname = stock->GetName();
454  // works, what to do
455  Stock *prev_stock = Find( stockname );
456 
457  // if not existing create a new one
458  if ( prev_stock == nullptr ) {
459 #ifdef DEBUG_CPP
460  std::cout << "Stock did not exist, insert it as a new one " << std::endl;
461 #endif
462  InsertVec_Stock ( stock );
463  return 0;
464  } else {
465  //throw( StockException( stockname, "Error in StockManager::AddStock, the stock already exists: "+stockname+" !!") );
466  prev_stock->MergeStock( stock, true );
467  }
468  return 0;
469 }
470 
471 // All delete are mainly wrapper to Stock delete function
472 // Should check if Stock is empty, and then delete Stock
473 // Except for StockCSV/dCSV, may stay in memory from GUI because loaded by default
474 
475 // check if stock is empty and delete it, fname is fullname
476 void StockManager::DeleteListData( const std::string & fname )
477 {
478 #ifdef DEBUG_CPP
479  std::cout << " StockManager::DeleteListData " << fname << std::endl;
480 #endif
481  std::string namestock = FullName::GetNameStock( fname );
482  ETime tmscl = FullName::GetTimeScale ( fname );
483  std::string shortname = FullName::GetShortName( fname );
484 
485  Stock *stock = Find ( namestock );
486 
487  // checks if map entry is valid, case double delete is fine for DeleteListData
488  if ( stock )
489  // case double delete is fine as well inside
490  stock->DeleteListData( tmscl, shortname );
491  else {
492 #ifdef DEBUG_CPP
493  std::cout << "ERROR ?? StockManager::DeleteListData do not find stock, error ?? " << namestock << std::endl;
494 #endif
495  return;
496  }
497 
498 #ifdef DEBUG_CPP
499  std::cout << " StockManager::DeleteListData namestock " << stock->GetName(); //<< std::endl;
500  std::cout << " shortname " << shortname << std::endl;
501  std::cout << "stock after find " << stock << std::endl;
502  //stock->PrintMapChrono();
503 #endif
504 
505  // if stock is empty delete it
506 #ifdef DEBUG_CPP
507  std::cout << " Stock->Empty() " << stock->IsEmpty() << std::endl;
508  //stock->PrintMapChrono();
509 #endif
510  if ( stock->IsEmpty() ) {
511  std::cout << " StockManager has an empty Stock " << stock->GetName() << std::endl;
512 
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;
516  }
517  // delete entry in vector and object
518  vec_stock.erase ( it_s );
519  delete (stock);
520  stock = 0;
521  }
522  //stock->PrintMap();
523  //PrintMap();
524 }
525 
526 
527 void StockManager::DeleteAllListDataFromFrame ( const std::string& frame_name )
528 {
529  std::cout << " StockManager::DeleteListDataFromFrame with frame_name " << frame_name << std::endl;
530  std::string namestock = FrameName::GetNameStock( frame_name );
531  ETime tmscl = FrameName::GetTimeScale( frame_name );
532  DeleteAllListDataFromTimeScale ( namestock, tmscl );
533 }
534 
535 void StockManager::DeleteAllListDataFromTimeScale ( const std::string& namestock, const ETime& tmscl)
536 {
537 #ifdef DEBUG_CPP
538  std::cout << "Entry StockManager::DeleteAllListData from Timescale " << namestock << " tmscl " << tmscl << std::endl;
539 #endif
540 
541  //Could be replaced by iterator GetItStock
542  Stock *stock = Find ( namestock );
543 
544  if ( stock == 0 ) {
545 #ifdef DEBUG_CPP
546  std::cout << " Stock not found in StockManager::DeleteAllListData" << std::endl;
547 #endif
548  return;
549  }
550  // call Stock function, check if map entry has to be deleted
551  stock->DeleteAllListData ( tmscl );
552 
553  //check if vector stock need to be deleted
554  //std::cout << "stock->IsEmpty() " << stock->IsEmpty() << std::endl;
555  //stock->PrintMap();
556 
557  if ( stock->IsEmpty() ) {
558 #ifdef DEBUG_CPP
559  std::cout << " StockManager has an empty Stock " << stock->GetName() << std::endl;
560 #endif
561 
562  it_stock it_s;
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;
566  }
567  vec_stock.erase ( it_s );
568  delete (stock);
569  stock = 0;
570  } else {
571  std::cout << "ERROR in StockManager::DeleteAllListData, stock is not empty " << std::endl;
572  }
573 
574 }
575 
576 void StockManager::DeleteStock ( std::string namestock )
577 {
578  it_stock it_s;
579  // with it_stock, not needed
580  //Stock *stock = Find ( namestock );
581  std::cout << "StockManager::DeleteStock " << namestock << std::endl;
582  //std::cout << "StockManager::DeleteStock size of vec_stock " << vec_stock.size() << std::endl;
583 
584  for (it_s = vec_stock.begin(); it_s != vec_stock.end(); it_s++) {
585  //std::cout << "loop over iterator" << std::endl;
586  if ( (*it_s)->GetName() == namestock ) {
587  // delete the map in Stock
588  delete ( *it_s );
589  //can remove from map here, because break
590  vec_stock.erase ( it_s );
591  //break;
592  return;
593  }
594  // check if not found, not working here, never reach end()
595  //if ( it_s == vec_stock.end() ) {
596  // std::cout << "Stock no found" << std::endl;
597  // return;
598  //}
599  //end loop for
600  }
601 
602  // if here, stock not found
603  std::cout << "\n\tStockManager::DeleteStock Stock no found" << namestock << "\n" << std::endl;
604 }
605 
607 {
608  std::cout << "===================\n\tShowMap Manager Stock" << std::endl;
609  std::cout << "Size of StockManager " << vec_stock.size() << "\n" << std::endl;
610 
611  // printMap for each Stock
612  for ( it_stock it_s = vec_stock.begin(); it_s != vec_stock.end(); it_s++)
613  {
614  std::cout << "name stock " << (*it_s)->GetName() ; // << std::endl;
615  std::cout << " symbol stock " << (*it_s)->GetSymbol() << std::endl;
616 
617  (*it_s)->PrintMapChrono();
618  }
619 
620 }
Singleton class, stores all loaded stocks.
Definition: StockManager.h:42
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,...
Definition: Indicator.h:29
virtual const char * what() const noexcept
std::string GetNameStock(const std::string &frame_name)
Extract the stock name from a frame name.
Definition: FullName.cpp:116
ETime GetTimeScale(const std::string &frame_name)
Extract the TimeScale from a frame name.
Definition: FullName.cpp:122
ListDataStock< SimpleData, VecChronologic > ldata_volume
Volume has also one value.
Definition: typedef.h:38
void PrintData(const unsigned int verbose=0) const
User friendly output on screen.
Definition: DataStock.cpp:363
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.
Definition: Stock.cpp:567
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.
Definition: FullName.cpp:46
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.
Definition: Stock.h:56
bool ActivateServer()
Activate the server, by default null in constructor.
int AddListDataToMap(const ETime &tmscl, ListDataStockBase *p_listdata)
Insert a ListDataStock to the map.
Definition: Stock.cpp:622
const time_t ERROR_StrToTime
Error code returned by StringToTime_t if the string cannot be parsed correctly Must be a time_t...
Definition: Utils.h:51
Concrete class for the subject/observable of StockManager.
static TCPServer * ftcp
owns a TCPServer, but inverse is true as well.
Definition: StockManager.h:64
static bool status_sm
static boolean status
Definition: StockManager.h:54
void DeleteListData(const ETime &tmscl, const Indicator &indic, std::vector< int > param=std::vector< int >())
Delete a list given the TimeScale, Indicator and param.
Definition: Stock.cpp:872
ETime
Enumeration for the different time representation, from instantaneous (INST) to year(YEAR) ...
Definition: TimeScale.h:48
static Indicator const StockInst
Definition: Indicator.h:44
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.
Definition: Stock.cpp:581
static SMSubject * fsubject
owns a subject/observable for the observer pattern
Definition: StockManager.h:66
bool CheckLoaded(const ETime &tmscl) const
Definition: Stock.cpp:529
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.
Definition: DataStock.h:366
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 .
Definition: Utils.cpp:93
std::string GetShortName(const std::string &fname)
Extract Indicator_params (string) from a fullname.
Definition: FullName.cpp:78
void MergeStock(const Stock *new_stock, bool)
Merge entries with an other stock.
Definition: Stock.cpp:730
Use with RealTime to receive messages from python ServerPortfolio.
Definition: TCPServer.h:122
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).
Definition: DataStock.h:335
virtual void SetDates(const time_t first, const time_t last)
Set dates, 2 arguments.
Definition: ListDataStock.h:93
std::vector< Stock * >::iterator it_stock
Definition: StockManager.h:47
std::vector< Stock * >::const_iterator cit_stock
Definition: StockManager.h:48
Abstract base class for the ListDataStock, for storing base pointers in vectors.
Definition: ListDataStock.h:50
bool DesactivateServer()
void Updated(const ETime tmscl)
Return the last available date of historical data.
Definition: Stock.cpp:1799
void DeleteAllListData(const ETime &tmscl)
Delete all data of the given TimeScale.
Definition: Stock.cpp:916
static void killInstance()
Delete the instance and allocated ressources.
static StockManager * fstockmanager
static instance
Definition: StockManager.h:56
int LoadListData(const ETime &tmscl, const Indicator &indic=Indicator::StockCSV, const std::vector< int > &param=std::vector< int >(), Utils::firstlast_dates dates=Utils::get_fldate_default())
Load or/and compute an indicator in the Stock.
Definition: Stock.cpp:801
std::string MakeShortName(const Indicator &indic, const std::vector< int > &param)
Create a short name from its components.
Definition: FullName.cpp:109
static std::string fpath
path of the data, set during singleton initialization
Definition: StockManager.h:61
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
Definition: Utils.cpp:56
general structure for dates in csv files
Definition: Utils.h:54
int AddStock(Stock *)
Add a stock to the stockmanager.
void PrintMap()
Print an user-friendly view of the StockManger content.
std::string GetName() const
Definition: Stock.h:210
void DeleteListData(const std::string &fname)
Delete a specific ListDataStcok, just wrappers to Stock.
Derive from Subject class.
Definition: SMSubject.h:24
ETime GetTimeScale(const std::string &fname)
Extract the TimeScale from a fullname.
Definition: FullName.cpp:53
void InsertVec_Stock(Stock *)
Insert a vector.
Server to receive new Instantaneous data from ServerPortfolio.