ROOT_Application  2.0
C++ Core modules and GUIStock
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
StockwrapPyParser.cpp
Go to the documentation of this file.
1 
9  // Split apart, by this way rootcint do not see this include, which makes problem
10  // Send a mail to ROOT team ?? Check before
11 
12 #ifndef Python_for_stock
13 #define Python_for_stock
14 //#include <Python.h>
15 // eclipse recognize this one
16 #include <python2.7/Python.h>
17 #endif
18 
19 using namespace TimeScale;
20 
21 // declare internal function, could be in header Stock.h
22 void GetListDataFromPyList( PyObject * pyListCSV, ldata_candle * new_listdata_csv, ldata_volume * new_listdata_vol );
23 
24 // simple test : works, in calling the python in workspace, need PYTHONPATH set correctly
43 //may extend function around the dictionary ( print content, get data )
44 // could be a class in itself
45 // Load python class DictionaryStocks.
46 //
47 // to call after PyInitialze() ( to check, seems logic )
48 // load module DictionaryStocks and call constructor DictionaryStocks()
49 // name of the txt file, now use default only
50 //
51 int Stock::LoadDictionary ( std::string dict )
52 {
53 #ifdef DEBUG_CPP
54  std::cout << "Entry Stock::LoadDictionary dict " << dict << std::endl;
55 #endif
56 
57  PyObject *pModule;
58  PyObject *pFunc_Init;
59  // not used but needed for calling the function
60  PyObject *pArgs=0;
61 
62  pModule = PyImport_ImportModule( "DictionaryStocks" );
63 
64  // modify order of test, easier
65  if (pModule == NULL) {
66  std::cout << "\n\tCannot load module DictionaryStocks\n" << std::endl;
67  return 1;
68  }
69 
70 #ifdef DEBUG_CPP
71  std::cout << "DictionaryStocks imported " << std::endl;
72 #endif
73  //get the constructor ParserStock
74  //pFunc_Init = PyObject_GetAttrString(pModule, "Init");
75  pFunc_Init = PyObject_GetAttrString(pModule, "DictionaryStocks");
76 
77  if (pFunc_Init && PyCallable_Check(pFunc_Init)) {
78  //see later for arguments, now use 0=NULL
79  PyObject_CallObject( pFunc_Init, pArgs );
80  }
81  //std::cout << " function Init/Constructor done " << std::endl;
82 
83  // deallocate python pointer, may be not here in DeleteDictionary ??
84  // ok can delete the module still working, until now...
85  //Py_DECREF(pArgs);
86  Py_DECREF ( pModule );
87  Py_DECREF ( pFunc_Init );
88  //std::cout << "End LadDictionnary return 0 " << std::endl;
89  return 0;
90 }
91 
92 // Should split more : LoadModule and Function
93 // make Stock logic
94 
95 // need to know which source Boursorama or Yahoo_CSV, implemented only DAY and Yahoo
96 // to extend to Bourso, for Progress DAY.
97 //
98 // For update, in-memory like header < now : update all data->Update in-memory (Save new data? yes, consuming time Parser)
99 // in-memory shorter than header : update from Header to now->Do not update in-memory (but Save new data)
100 // do not recomputeTA, need message to the user. updated but not apply by default to in-memory
101 // in.memory > header ( because server, not really for DAY, yes but only progress DAY bourso!) :
102 // For Yahoo, (call update after loading=>Automatically if written to file, should not happen)
103 // For Bourso, only instantaneous, always get the data. For saving can check hour is not 00:00:00...
104 //
105 // In summary expects from LastCSVUpdate: last header is crucial.
106 // before LastCSVUpdate loaded always the Stock, but could be done here also...
107 // If only header (not-in-memory) is available load from header. Will be a problem of Save !
108 //
109 // create an object ParserStock( stock, "source" )
110 // call directly Parser function.
111 // implemented call to GetListCSV ( redirect to Yahoo_CSV )
112 //
113 // only with tmscl == DAY now !
114 int Stock::UpdateCSVFromWeb ( const std::string& source, Utils::firstlast_dates opt_dates )
115  throw (StockException)
116  //throw (StockPythonException,StockFileError) // by Read_HeaderCSV
117  {
118 #ifdef DEBUG_CPP
119  std::cout << "\n\tEntry Stock::UpdateCSVFromParser source " << source << std::endl;
120  std::cout << "dates first " << opt_dates.first << " " << Utils::Time_tToString( opt_dates.first ) << std::endl;
121  std::cout << "dates last " << opt_dates.last << " " << Utils::Time_tToString( opt_dates.last ) << std::endl;
122 #endif
123 
124  std::string namestock=GetName();
125  // problem with Py_DECREF, maybe because argument
126  //std::string source_copy = source;
127 
128  // first date to extract
129  time_t first_time = 0; //, opt_date_max;
130  int new_size=0;
131  int status = 0;
132  // set default 0,0 not equivalent to today ! if used with default argument (normal case)
135  // always check with today
136  //time_t now;
137 
138  ldata_candle *new_listdata_csv = 0;
139  ldata_volume *new_listdata_vol = 0;
140 
141  // Could create directly the ListDataStock in Function GetList
142  PyObject *pStockName, *pSource; //string stockname, source
143  PyObject *pModule; // module ParserStocks.py
144  PyObject *pFunc_Parser, *pInstance; // func constructor ParserStock, instance ParserStock
145  // *pFunc_LastCSV, *pFunc_Update ;
146  PyObject *pFunc_GetListCSV, *pReturn_ListCSV; //funct and return value of GetListCSV
147  PyObject *pArgs=0, *pArg_lasttime; // args for ParserStock
148 
150  Read_HeaderCSV( ETime::DAY, header_dates );
151 
152  // default date first, last from header
153  if ( opt_dates.first == 0 ) {
154  first_time = header_dates.last;
155  #ifdef DEBUG_CPP
156  std::cout << "Set First time, get the last time from header " << first_time << std::endl;
157  #endif
158  }
159 
160 // if default date last, set to today, Utils::GetTime_tToday()
161  if ( opt_dates.last == 0 ) {
162  opt_dates.last = time( NULL );
163  #ifdef DEBUG_CPP
164  std::cout << "Set last time, get to now " << Utils::Time_tToString( opt_dates.last ) << std::endl;
165  #endif
166  }
167 
168  #ifdef DEBUG_CPP
169  std::cout << "opt_dates.last " << opt_dates.last << " " << Utils::Time_tToString( opt_dates.last ) << std::endl;
170  std::cout << "Set first_time " << first_time << " " << Utils::Time_tToString( first_time ) << std::endl;
171  #endif
172 
173  // not care about .last, optional if zero up to now if already up now no problem... ??
174 
175  // Check if update is possible, with state in memory (in memory loaded until last header, or more, but not less)
176  if ( CheckLoaded( ETime::DAY ) ) {
177  in_memory_dates.first = GetListData( ETime::DAY, Indicator::StockCSV )->GetFirstTime();
178  in_memory_dates.last = GetListData( ETime::DAY, Indicator::StockCSV )->LastUpdate();
179  #ifdef DEBUG_CPP
180  std::cout << "In memory first date " << in_memory_dates.first << " " << Utils::Time_tToString( in_memory_dates.first,true ) << std::endl;
181  std::cout << "In memory last date " << in_memory_dates.last << " " << Utils::Time_tToString( in_memory_dates.last,true ) << std::endl;
182 #endif
183 
184  // Check if update impossible, only a sub-range of initial data has been read.
185  // In memory is missing last ones, problem with saving
186  //if ( in_memory_dates.last > header_dates.last ) {
187  if ( header_dates.last > in_memory_dates.last ) {
188  std::cout << "CANNOT_UPDATE UpdateFromWeb, return -1" << std::endl;
189  std::cout << "in_memory_last " << in_memory_dates.last << " " << Utils::Time_tToString(in_memory_dates.last, true) << std::endl;
190  std::cout << "header_last " << header_dates.last << " " << Utils::Time_tToString(header_dates.last, true) << std::endl;
191  return -1;
192  }
193  // do not reload what is in memory
194  first_time = in_memory_dates.last;
195 }
196 
198  //always Initialize the interpreter first
199  Py_Initialize();
200 
201  // Load global dictionary in python interpreter, use default dictionary
202  // Could throw exception directly from function
203  status = LoadDictionary("");
204  //std::cout << "status " << status << std::endl;
205  if ( status != 0 ) {
206  std::cout << "Could not load the dictionary" << std::endl;
207  throw ( StockPythonException( namestock, "Error in UpdateCSVFromWeb in loading Python dictionary" ) ) ;
208  //return -1;
209  }
210 
211  // extract arguments for ParserStocks initialization
212  pStockName = PyString_FromString( namestock.c_str() );
213  pSource = PyString_FromString( source.c_str() );
214  //pSource = PyString_FromString( source_copy.c_str() ); // try problem with Py_DECREF, change nothing
215 #ifdef DEBUG_CPP
216  std::cout << "source " << source << std::endl;
217  std::cout << "namestock " << namestock << std::endl;
218 #endif
219 
220  //std::cout << "Before import module" << std::endl;
221  pModule = PyImport_ImportModule( "ParserStocks" );
222  //std::cout << "After import module ParserStocks" << pModule << std::endl;
223  // easier to check here
224  if ( pModule == NULL ) {
225  PyErr_Print();
226  std::cout << "Error in loading module" << std::endl;
227  Py_Finalize();
228  throw ( StockPythonException( namestock, "Error in UpdateCSVFromWeb in loading Python module" ) ) ;
229  //return -1;
230  }
231 
232  // else module loaded
233  //get the constructor ParserStock
234  pFunc_Parser = PyObject_GetAttrString(pModule, "ParserStocks");
235  //std::cout << "pFunc " << pFunc_Parser << std::endl;
236 
237  //call constructor of ParserStock
238  if (pFunc_Parser && PyCallable_Check(pFunc_Parser)) {
239 
240  pArgs = PyTuple_New(2);
241  // test better after ??
242  if (!pArgs) {
243  Py_DECREF(pArgs);
244  Py_DECREF(pModule);
245  //fprintf(stderr, "Cannot convert argument, return\n");
246  throw ( StockPythonException( namestock, "Error in UpdateCSVFromWeb in calling Python" ) ) ;
247  //return -1;
248  }
249  //Set value of Tuple
250  /* pArgs reference stolen here: */
251  PyTuple_SetItem(pArgs, 0, pStockName);
252  PyTuple_SetItem(pArgs, 1, pSource);
253 
254  //Call function constructor and create instance
255  //std::cout << "CallObject " << std::endl;
256  pInstance = PyObject_CallObject( pFunc_Parser, pArgs );
257  //std::cout << "After CallObject " << std::endl;
258  //should Py_DECREF-ed the arguments just after
259  Py_DECREF(pArgs);
260 
261  // Check if null, not enough
262  // do not check if an error occurred like the symbol does not exist in the dictionary
263  if ( pInstance == NULL ) {
264  Py_DECREF(pFunc_Parser);
265  Py_DECREF(pModule);
266  //Py_DECREF(pInstance);
267  PyErr_Print();
268  //fprintf(stderr,"Call failed\n");
269  std::cout << "Call failed return -1" << std::endl;
270  throw ( StockPythonException( namestock, "Error in UpdateCSVFromWeb in loaing Python module" ) ) ;
271  //return -1;
272  }
273 
274  // here need a way to access the potential error:
275  // symbol not in dictionary...
276  // a simple SymbolExists with a bool value, or the name of the symbol, error by default
277  // ...
278 
279  } //end if pFunc && PyCallable_Check(pFunc)
280 
281  // prepare function for calling GetListCSV
282  pFunc_GetListCSV = PyObject_GetAttrString( pInstance, "GetListCSV");
283 
284  // check if instance is correct and if callable
285  if ( pFunc_GetListCSV && PyCallable_Check(pFunc_GetListCSV) ) {
286 
287  //PrintMap();
288 #ifdef DEBUG_CPP
289  std::cout << "Call python with argument first time " << Utils::Time_tToString(first_time) << std::endl;
290  std::cout << "Call python with argument last_dates " << Utils::Time_tToString(opt_dates.last) << std::endl;
291 #endif
292 
293  pArg_lasttime = Py_BuildValue("(ll)", (long int) first_time, (long int) opt_dates.last);
294 
295  // here or before need to test if symbol exists !
296  //std::cout << "Call Python GetListCSV " << std::endl;
297 
298  pReturn_ListCSV = PyObject_CallObject( pFunc_GetListCSV, pArg_lasttime);
299  Py_DECREF( pArg_lasttime );
300 #ifdef DEBUG_CPP
301  std::cout << " Size of pReturn_ListCSV " << PyList_Size( pReturn_ListCSV ) << std::endl;
302 #endif
303  // here is a test, but maybe never created by python ??
304  // ok test working ( should improve intern python, avoid to execute if clearly wrong), return
305  if ( PyList_Size( pReturn_ListCSV ) == 0 ) {
306 #ifdef DEBUG_CPP
307  std::cout << "Size of updated stockCSV == 0 " << std::endl;
308 #endif
309  //need to clean before return -1, listdatastock not yet created
310  Py_DECREF(pModule);
311  Py_DECREF(pInstance);
312  Py_Finalize();
313  // before retrun -1
314  //return -1;
315  // now send an exception, but not sure of the reason here !
316  // in test symbol not in dictionnary, but error in internet call possible also
317  // need a test, before calling the function to test the symbol
318  throw ( StockPythonException( namestock, "Error in UpdateCSVFromWeb in calling Python" ) ) ;
319  }
320 #ifdef DEBUG_CPP
321  else {
322  std::cout << "GetListCSV return with size " << PyList_Size( pReturn_ListCSV ) << std::endl;
323  }
324 #endif
325 
326  // function not callable, exit
327  } else {
328  std::cout << "error in calling pFunc_GetListCSV" << std::endl;
329  Py_DECREF(pModule);
330  Py_DECREF(pInstance);
331  PyErr_Print();
332  fprintf(stderr,"Call failed\n");
333  return -1;
334  }
335 #ifdef DEBUG_CPP
336  std::cout << "Extract data from the list " << std::endl;
337 #endif
338 
339  // get ListCSV from python to C, do not know the size here ?
340  // always create a new list to insert, before sure it was loaded, but now ??
341  new_listdata_csv = new ldata_candle( "StockCSV", ETime::DAY );
342  new_listdata_vol = new ldata_volume( "Volume", ETime::DAY );
343 
344  // extract the data and fill the lists, helper function
345  GetListDataFromPyList( pReturn_ListCSV, new_listdata_csv, new_listdata_vol );
346  /*
347  std::cout << "After GetListDataFromPyList " << std::endl;
348  new_listdata_csv->PrintData();
349  new_listdata_vol->PrintData();
350  */
351 
352  // crash, not coming from here ??
353  // cannot delete variable in C++ way (delete) will crash, should use Py_DECREF
354  // should delete all arguments ?? no garbage if embedded, but do not create errors in valgrind ?
355  Py_DECREF ( pModule );
356  Py_DECREF ( pInstance );
357  Py_DECREF ( pFunc_Parser );
358  Py_DECREF ( pArgs );
359  Py_DECREF ( pArg_lasttime );
360 
361  // crash here, exactly same, but before argument, seems order dependent !!
362  // if comented ok... other can pass. Check logic here with arguments stolen
363  //Py_DECREF ( pSource ); // 1 decrease number of error in valgrind ??
364  //Py_DECREF ( pStockName ); // origin, delete StockName, no pSource
365 
366  // new added, seems to pass, no error if included or no ?
367  // if Py_CREF pSource is commented, they can be deleted without error valgrind
368  Py_DECREF ( pFunc_GetListCSV );
369  Py_DECREF ( pReturn_ListCSV ); // change nothing
370 
371  // always close interpreter, not really needed but good habit, from doc
372  Py_Finalize();
373 
375  new_size = new_listdata_vol->GetSize();
376 
377  //std::cout << "will add listdatatomap new_size " << new_size << std::endl;
378  //std::cout << "first date " << ( new_listdata_csv->At(0) )->GetDate() << std::endl;
379  //std::cout << "size " << new_listdata_csv->GetSize() << " date " << ( new_listdata_csv->At( new_listdata_csv->GetSize()-1 ) )->GetDate() << std::endl;
380  if ( new_listdata_vol->GetSize() ) {
381 
382  // re-order if necessary
383  new_listdata_csv->Order( EPChrono::NO_CHRONO );
384  new_listdata_vol->Order( EPChrono::NO_CHRONO );
385  // set dates into the list, real dates for this list here
386  // set date before update in AddToList, or done inside ?? need to pass test inside
387  new_listdata_csv->SetDates();
388  new_listdata_vol->SetDates();
389 
390 
391  // only if in-memory !
392  // 1 means update, so need to delete the list
393  if ( AddListDataToMap( ETime::DAY, new_listdata_csv ) == 1 ) {
394  delete new_listdata_csv; new_listdata_csv=0;
395  }
396  if ( AddListDataToMap( ETime::DAY, new_listdata_vol ) == 1 ) {
397  delete new_listdata_vol; new_listdata_vol=0;
398  }
399 
400  // now, in all case save right now !
401  //SaveCSV( ETime::DAY );
402  }
403 #ifdef DEBUG_CPP
404  std::cout << "StockwrapPyStock::Update return new_size " << new_size << std::endl;
405 #endif
406  return new_size;
407 }
408 
409 //function very similar, copy from, wrapPyStock.cpp wrapUpdateCSV. Should be called by the wrapper,
410 // one function == one mehod
414 void GetListDataFromPyList( PyObject * pyListCSV, ldata_candle * new_listdata_csv, ldata_volume * new_listdata_vol )
415 {
416 #ifdef DEBUG_CPP
417  std::cout << "Entry Stock::GetListDataFromPyList" << std::endl;
418 #endif
419  long int size;
420  //create temporary object for data, will be save in the vector
421  DataCSV data_csv = DataCSV();
422  SimpleData data_vol = SimpleData();
423  //equivalent for python
424  PyObject *pyListData;
425 
426  time_t date;
427  float op,pl,mo,cl;
428  float vol;
429 
430  size=PyList_GET_SIZE(pyListCSV);
431 #ifdef DEBUG_CPP
432  std::cout << "size data pyListCSV reserve for list" << size << std::endl;
433 #endif
434  //allocate the list
435  new_listdata_csv->Reserve( size );
436  new_listdata_vol->Reserve( size );
437 
438  for ( int i=0; i<size; i++ ) {
439  pyListData = PyList_GET_ITEM(pyListCSV,i);
440  //should ??
441  Py_XINCREF(pyListData);
442 
443  date = (time_t) PyInt_AsLong(PyList_GET_ITEM(pyListData,0));
444  op = PyFloat_AsDouble(PyList_GET_ITEM(pyListData,1));
445  pl = PyFloat_AsDouble(PyList_GET_ITEM(pyListData,2));
446  mo = PyFloat_AsDouble(PyList_GET_ITEM(pyListData,3));
447  cl = PyFloat_AsDouble(PyList_GET_ITEM(pyListData,4));
448  vol = PyFloat_AsDouble(PyList_GET_ITEM(pyListData,5));
449  //std::cout << "date op " << date << " " << op << std::endl;
450 
451  //set data
452  data_csv.SetData(date,op,pl,mo,cl);
453  data_vol.SetData(date,vol);
454 
455  new_listdata_csv ->AddData ( data_csv );
456  new_listdata_vol ->AddData ( data_vol );
457  //clear the object, will see missing data
458  data_csv.SetData(0,0.,0.,-1000.0,0.);
459  data_vol.SetData(0,0.);
460 
461  //if incr should decref ??
462  Py_XDECREF(pyListData);
463  }
464  //pyListData = 0; ??
465 }
466 
467 // test function
468 int Stock::TestwrapPython( std::string source )
469 {
470  std::cout << "entry testwrappython " << std::endl;
471 
472  std::string namestock=GetName();
473  std::cout << "name " << namestock << "source " << source << std::endl;
474  //time_t last_time;
475  //int new_size=0;
476 
477  //ListDataStock<DataCSV> *new_listdata_csv=0;
478  //ListDataStock<SimpleData> *new_listdata_vol=0;
479 
480  // Could create directly the ListDataStock in Function GetList
481  PyObject *pStockName;
482  PyObject *pSource;
483  PyObject *pModule;
484  //PyObject *pFunc_Parser, *pFunc_GetListCSV; // *pFunc_LastCSV, *pFunc_Update ;
485  //PyObject *pInstance, *pReturn_ListCSV;
486  //PyObject *pArgs, *pArg_lasttime;
487 
488  //always Initialize the interpreter, if we want to embedded the interpreter
489  //needed for PyImport_ImportModule
490  Py_Initialize();
491 
492  pSource = PyString_FromString( source.c_str() );
493  Py_INCREF (pSource); // not necessary
494  pStockName = PyString_FromString( namestock.c_str() );
495  Py_INCREF (pStockName); // not necessary
496 
497 
498  //pModule = PyImport_ImportModule( "ParserStocks" );
499  pModule = PyImport_ImportModule( "ModTest" );
500 
501  if (pModule != NULL) {
502  //get the constructor ParserStock
503  //pFunc_Parser = PyObject_GetAttrString(pModule, "ParserStocks");
504  //std::cout << "pFunc " << pFunc_Parser << std::endl;
505  std::cout << " toto " << std::endl;
506 
507  } //end if pModule != NULL
508 
509  Py_DECREF(pModule);
510 
511  //namestock.clear();
512  Py_DECREF ( pStockName );
513  Py_DECREF ( pSource );
514  pStockName = 0;
515  pSource = 0;
516 
517  //always close interpreter, not really needed but good habit, from doc
518  Py_Finalize();
519 
520  return 1;
521 }
522 
523 // 2 nd version, add until error valgrind
524 int Stock::TestwrapPython2( std::string source ) //throw (std::exception)
525 {
526  std::cout << "entry testwrappython 2 " << std::endl;
527 
528  std::string namestock=GetName();
529  std::cout << "name " << namestock << " source " << source << std::endl;
530  //time_t last_time;
531  //int new_size=0;
532 
533  //ListDataStock<DataCSV> *new_listdata_csv=0;
534  //ListDataStock<SimpleData> *new_listdata_vol=0;
535 
536  // Could create directly the ListDataStock in Function GetList
537  PyObject *pStockName;
538  PyObject *pSource;
539  PyObject *pModule = NULL;
540  //PyObject *pFunc_Parser, *pFunc_GetListCSV; // *pFunc_LastCSV, *pFunc_Update ;
541  //PyObject *pInstance, *pReturn_ListCSV;
542  //PyObject *pArgs, *pArg_lasttime;
543 
544  //always Initialize the interpreter, if we want to embedded the interpreter
545  //needed for PyImport_ImportModule
546  Py_Initialize();
547 
548  pSource = PyString_FromString( source.c_str() );
549  Py_INCREF (pSource); // not necessary
550  pStockName = PyString_FromString( namestock.c_str() );
551  Py_INCREF (pStockName); // not necessary
552 
553 
554  //pModule = PyImport_ImportModule( "ParserStocks" ); //source of error
555  //pModule = PyImport_ImportModule( "ModTest" );
556 
557  pModule = PyImport_ImportModule( "ModTest2" );
558  std::cout << "pModule " << pModule << std::endl;
559 
560  // Cannot do here if the module does not exist!
561  //Py_INCREF ( pModule );
562 
563  if (pModule != NULL) {
564  // if error in module return 0
565  Py_INCREF ( pModule );
566  //get the constructor ParserStock
567  //pFunc_Parser = PyObject_GetAttrString(pModule, "ParserStocks");
568  //std::cout << "pFunc " << pFunc_Parser << std::endl;
569  std::cout << " loaded ModTest2 " << std::endl;
570 
571  } //end if pModule != NULL
572  else {
573  std::cout << " Module not loaded " << std::endl;
574  namestock.clear();
575  Py_DECREF ( pStockName );
576  Py_DECREF ( pSource );
577  throw ( StockPythonException( namestock, "Error in testwrap2 python" ) ) ;
578  }
579 
580  Py_DECREF(pModule);
581 
582  namestock.clear();
583  Py_DECREF ( pStockName );
584  Py_DECREF ( pSource );
585  Py_DECREF ( pModule );
586  pStockName = 0;
587  pSource = 0;
588 
589  //always close interpreter, not really needed but good habit, from doc
590  // seems no change in valgrind
591  Py_Finalize();
592 
593  return 1;
594 }
ListDataStock< DataCSV, VecChronologic > ldata_candle
Define a default policy for candlestick.
Definition: typedef.h:26
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.cpp:754
void GetListDataFromPyList(PyObject *pyListCSV, ldata_candle *new_listdata_csv, ldata_volume *new_listdata_vol)
Utility function to fill ListDataStocks from a python tuple.
void AddData(DataStock &data)
Add a copy of the DataStock into the ListDataStock.
int UpdateCSVFromWeb(const std::string &source, Utils::firstlast_dates opt_dates=Utils::get_fldate_default())
Update data from the Python parser (and save into the filesystem).
unsigned int GetSize() const
Return the size of the vector.
ListDataStock< SimpleData, VecChronologic > ldata_volume
Volume has also one value.
Definition: typedef.h:38
int LoadDictionary(std::string dict="")
Load the dictionary of Stock, see ServerPortfolio.
Base Exception for Stock and StockManager, all src_cpp code.
Use a policy PolicyChronologic, default VecNoChronologic.
Data type to describe Japanese candlesticks : open, high, low and close values.
Definition: DataStock.h:502
void Reserve(const unsigned int new_size)
Reserve new_size elements.
void Order(const EPChrono b_chronologic=EPChrono::CHRONO)
Function to reverse the internal vector in its original policy.
std::string Time_tToString(const time_t &time, const bool b_hour)
Return a string representing the date All times are expressed in the localtime.
Definition: Utils.cpp:157
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 SetDates()
Set the correct first/last dates from the DataStock in the vector.
Derive class which contains only one value of type type_value_data (float or double).
Definition: DataStock.h:335
static Indicator const StockCSV
Definition: Indicator.h:44
int TestwrapPython(std::string source)
static SUPPRESS_NOT_USED_WARN firstlast_dates get_fldate_default()
need to be static for using default argument in a function
Definition: Utils.h:60
Specific the wrapper python.
int TestwrapPython2(std::string source)
general structure for dates in csv files
Definition: Utils.h:54