Here is a detailed description of the shared library interface functions:
SPT_RemoveAll(): Removes all securities from memory (empty tank)
SPT_SetStrictInsertDateOrder(order):
Only allows data to be inserted in ascending or descending order.
order = 0 is descending meaning newest to oldest dates:
BHP,2017/01/10,.... Ok
BHP,2017/01/09,.... Ok
BHP,2017/01/08,.... Ok
BHP,2017/01/11,.... Error
order = 1 is ascending meaning oldest to newest dates:
BHP,2017/01/08,.... Ok
BHP,2017/01/09,.... Ok
BHP,2017/01/10,.... Ok
BHP,2017/01/07,.... Error
We need to do this so that there are no duplicates and the order is of the utmost importance.
SPT_SetInsertDateConstraint(startyear,.....,endyear,.....):
Only insert between these dates inclusive.
Other dates are ignored.
SPT_Insert(...):
Insert record such as a row from a csv file into memory (tank).
This is not used in python script as it was found to be too slow for python to read data in from csv files.
Basic verification such as open > high or low <= 0 is also performed here and if there is an error, the record is rejected and a message is displayed.
SPT_CSVFileInsert(dfname, dfnameissymbol=0/1, hastime=0/1):
Insert prices from CSV file into memory (tank)
dfnameissymbol = 0 means data filename is not the symbol. We expect the following format from csv file:
SYMBOL,date[,time],open,high,low,close,volume
dfnameissymbol = 1 means data filename is the symbol. We expect the following format from csv file:
date[,time],open,high,low,close,volume
hastime = 0 means no time column. We expect the following format from csv file:
[symbol],date,open,high,low,close,volume
hastime = 1 means time column. We expect the following format from csv file:
[symbol],date,TIME,open,high,low,close,volume
IMPORTANT NOTE: I have put some commented out code in the python script that can be used to read in multiple files.
SPT_GetTotalSecurities(): Obvious
SPT_GetTotalRecordsInserted(): Obvious (1 record = 1 successfully inserted row from csv file).
SPT_GetSecurityMaxRecords():
Returns the maximum records (1 rec = 1x[date,prices,volume]) any one security currently holds.
We need this to dynamically allocate memory for arrays in calling application such as python.
SPT_First(): Start our iterations at the first security. Returns number of records used.
SPT_Next(): Iterate to next security in the list. Returns number of records used.
SPT_GetSymbol(symbol): Get the symbol name for the current security.
SPT_GetAllPrices(date,prices...,volume): Get the prices for the current security.
SPT_GetAllPricesRev(date,prices...,volume):
Get the prices for the current security in the reverse order.
This is useful for TA purposes as order is important.
Date from csv file can be in the following formats:
dd/mm/yyyy
yyyy/mm/dd
yyyymmdd
where "/" could be any other character such as "-" or "."
Time from csv file can be in the following formats:
hr:min
hr:min:sec
hr:min:sec.msec
int
If time is just an int with no separator, then that is what gets stored (user defined).
otherwise time gets converted to milliseconds in the day and stored as follows
time = hour * 3600000 + min * 60000 + sec * 1000 + msec
To convert this value back you would have to code something like:
hour = int(time / 3600000)
minute = int((time % 3600000) / 60000)
sec = int((time % 60000) / 1000)
msec = time % 1000
A typical
date/time format is something like:
2017/04/10,10:12, or 10/04/2017T10:12:04.123, or 20170410:0940,
That is all for now, happy easter
.
Cheers,
Andrew.