15 #ifndef Python_for_stock
16 #define Python_for_stock
19 #include <python2.7/Python.h>
36 std::cout <<
"hello world last " << std::endl;
59 #ifdef DEBUG_WRAPPYSTOCK
60 std::cout <<
"wrapLastCVSUpdate symbol: " << symbol << std::endl;
64 std::string tmp_symbol = std::string(symbol);
70 if ( btest ==
true ) {
71 #ifdef DEBUG_WRAPPYSTOCK
72 std::cout <<
"Set data_test mode" << std::endl;
80 last_time_t = dates.
last;
82 std::cout <<
"wrapPyStock::wrapLastCSVUpdate got exception " << std::endl;
86 return (
long int) last_time_t;
99 #ifdef DEBUG_WRAPPYSTOCK
100 std::cout <<
"Entry wrapPyStock::wrap_LastCSVUpdate() " << std::endl;
106 long int result_date;
109 if (!PyArg_ParseTuple(args,
"si:LastCVSUpdate",&symbol,&itest))
114 #ifdef DEBUG_WRAPPYSTOCK
115 std::cout <<
"symbol " << symbol << std::endl;
116 std::cout <<
"btest" << btest << std::endl;
121 return Py_BuildValue(
"i",result_date);
137 int wrapUpdateCSV (
const char * symbol,std::vector<DataCSV> & new_csv,std::vector<SimpleData> & new_vol,
bool btest )
139 #ifdef DEBUG_WRAPPYSTOCK
140 std::cout <<
"\n\tEntry UpdateCVS in wrap: symbol " << symbol << std::endl;
141 std::cout <<
"btest " << btest << std::endl;
144 std::string tmp_symbol = std::string(symbol);
146 if ( btest ==
true ) {
147 std::cout <<
"Set data_test mode" << std::endl;
165 #ifdef DEBUG_WRAPPYSTOCK
174 #ifdef DEBUG_WRAPPYSTOCK
193 if (!PyArg_ParseTuple(args,
"i:hello",&x))
196 return Py_BuildValue(
"i",result);
222 std::vector<DataCSV> vec_csv_to_add;
223 std::vector<SimpleData> vec_vol_to_add;
226 PyObject *pyFullList;
227 PyObject *pyListData;
233 if (!PyArg_ParseTuple(args,
"sOi", &symbol, &pyFullList, &itest))
238 std::cout <<
"parser works!!" << std::endl;
241 std::cout <<
" symbol " << symbol << std::endl;
242 if ( PyList_Check(pyFullList))
243 std::cout <<
"Second argument is a list" << std::endl;
246 std::cout <<
"btest " << btest << std::endl;
247 std::cout <<
"itest " << itest << std::endl;
250 size=PyList_GET_SIZE(pyFullList);
251 std::cout <<
"size data pyFullList " << size << std::endl;
257 for (
int i=0;i<size;i++)
261 pyListData = PyList_GET_ITEM(pyFullList,i);
265 date = (time_t) PyInt_AsLong(PyList_GET_ITEM(pyListData,0));
266 op = PyFloat_AsDouble(PyList_GET_ITEM(pyListData,1));
267 pl = PyFloat_AsDouble(PyList_GET_ITEM(pyListData,2));
268 mo = PyFloat_AsDouble(PyList_GET_ITEM(pyListData,3));
269 cl = PyFloat_AsDouble(PyList_GET_ITEM(pyListData,4));
270 vol = PyFloat_AsDouble(PyList_GET_ITEM(pyListData,5));
274 data_csv->
SetData(date,op,pl,mo,cl);
279 vec_csv_to_add.push_back(*data_csv);
280 vec_vol_to_add.push_back(*data_vol);
299 result=
wrapUpdateCSV(symbol, vec_csv_to_add, vec_vol_to_add, btest);
302 return Py_BuildValue(
"i",result);
327 #ifdef DEBUG_WRAPPYSTOCK
328 std::cout <<
"Entry wrap_SaveInst " << std::endl;
334 PyObject *pyListData;
347 if ( !PyArg_ParseTuple(args,
"sOi", &symbol, &pyListData, &itest) ) {
351 std::cout <<
"Error in PyArg_ParseTuple, return NULL" << std::endl;
358 assert ( PyList_Check( pyListData ) ==
true );
359 assert ( PyList_Size( pyListData ) == 3 );
361 #ifdef DEBUG_WRAPPYSTOCK
362 std::cout <<
"\n parser argument" << std::endl;
363 std::cout <<
"symbol " << symbol << std::endl;
364 std::cout <<
"btest " << btest << std::endl;
365 std::cout <<
"PyList_Check " << PyList_Check( pyListData ) << std::endl;
366 std::cout <<
"length of pyListData " << PyList_Size( pyListData ) << std::endl;
371 date = (time_t) PyLong_AsLong( PyList_GET_ITEM(pyListData, 0) );
372 value = PyFloat_AsDouble( PyList_GET_ITEM(pyListData, 1 ) );
373 volume = PyFloat_AsDouble( PyList_GET_ITEM(pyListData, 2 ) );
375 data_inst.
SetData(date, value);
376 data_volume.
SetData(date, volume );
377 #ifdef DEBUG_WRAPPYSTOCK
378 std::cout <<
"data_inst " << data_inst << std::endl;
379 std::cout <<
"data_volume " << data_volume << std::endl;
383 if ( btest ==
true ) {
384 std::cout <<
"Set data_test mode" << std::endl;
391 std::cout <<
"DictionaryStocks::SaveInst : No data append to the file " << std::endl;
392 return Py_BuildValue(
"i",-1);
397 return Py_BuildValue(
"i",0);
407 {
"hello",
wrap_hello, METH_VARARGS,
"Execute a print hello."},
410 {
"SaveInst",
wrap_SaveInst, METH_VARARGS,
"Execute SaveInst"},
412 {NULL, NULL, 0, NULL}
429 WrapError = PyErr_NewException((
char *)
"wrapPyStock.error", NULL, NULL);
431 PyModule_AddObject(m,
"error",
WrapError);
const std::string PATH_DATA_TEST
Important variable to adjust before compilation, should be in a configuration.
ListDataStock< DataCSV, VecChronologic > ldata_candle
Define a default policy for candlestick.
Define the class Stock to deal with an unique stock: DJ, IBM...
virtual void SetData(const time_t d, const std::vector< type_value_data > &vec)
Set a full Data : date + value(s) in a vector.
int SaveCSV(const ETime tmscl, bool opt_tmp=false) const
Save Historical data to file.
Define a list of DataStock objects.
int wrapUpdateCSV(const char *symbol, std::vector< DataCSV > &new_csv, std::vector< SimpleData > &new_vol, bool btest)
Uses to add data from yahoo (DAY) for StockCSV and Volume.
Specific, inherit from FileError from utils.
long int wrapLastCSVUpdate(const char *symbol, bool btest)
Get last date available from file.
void PrintData(const unsigned int verbose=0) const
Nice formatting output on console.
ListDataStock< SimpleData, VecChronologic > ldata_volume
Volume has also one value.
void SetPathData(std::string new_path)
forced to use this function now.
Use a policy PolicyChronologic, default VecNoChronologic.
static PyObject * wrap_SaveInst(PyObject *, PyObject *args)
Save instantaneous data into file.
Main class to deal with one stock.
Data type to describe Japanese candlesticks : open, high, low and close values.
PyMODINIT_FUNC initwrapPyStock(void)
int AddListDataToMap(const ETime &tmscl, ListDataStockBase *p_listdata)
Insert a ListDataStock to the map.
void Order(const EPChrono b_chronologic=EPChrono::CHRONO)
Function to reverse the internal vector in its original policy.
virtual void SetData(const time_t d, const std::vector< type_value_data > &vec)
Set a full Data : date + value(s) in a vector.
static PyObject * wrap_UpdateCSV(PyObject *, PyObject *args)
Python wrapper to Stock::wrapUpdateCSV().
static PyMethodDef WrapMethods[]
void SetDates()
Set the correct first/last dates from the DataStock in the vector.
static PyObject * wrap_hello(PyObject *, PyObject *args)
Derive class which contains only one value of type type_value_data (float or double).
static PyObject * wrap_LastCSVUpdate(PyObject *, PyObject *args)
Get last date available from file (only DAY at this stage).
void PrintMapChrono(const unsigned int verbose=0) const
Print map content to the console.
static SUPPRESS_NOT_USED_WARN firstlast_dates get_fldate_default()
need to be static for using default argument in a function
static int Read_HeaderCSV_static(std::string namestock, ETime tmscl, Utils::firstlast_dates &dates)
Static version of Read_HeaderCSV.
static int UpdateCSV_Inst(std::string namestock, DataStock &inst_value, DataStock &inst_volume, ETime tmscl, bool opt_tmp=false)
Update file with TimeScale INST.
static PyObject * WrapError
general structure for dates in csv files