FIDAL - Financial Data Access Library |
| NAME
DESCRIPTION To make accessible a source of market data, it must be added to an "unified database" (allocated with FD_UDBaseAlloc) Many data source can be added to the same unified database. All the data source will get transparently merge. It is possible to add one or many symbols simultaneously in one call. The data is not retrieved immediately, only the index is build at this point. The data is extracted/merged later using the FD_HistoryAlloc function. In the case that the same symbol is provided from two different data source, the data will get merged according to a specific rule: the order in which the data source where added with FD_AddDataSource do determine which data takes precedence on the other. The first added data source is the "least important" one, and the data provided by the last one cannot be overwritten by the others. Example 1: You have a local database and you want an online data source to provide the missing data. You will add the online data source last. The merging is independently performed down to each price bar. Example 2: You have a local read-only CD with an error on a couple of price bars. You can "cover" the erroneous data by putting the correct price bars in a file on your hard disk. Build the unified database by adding first the CD data source and then add the hard disk data source. That way the hard disk data will be taken for this particular price bar, this will effectively correct the error. Note: For simplicity, data source cannot be individually removed. For such rare functionality, it is simpler to simply de-allocate the corresponding unified database and re-build by re-adding the needed data sources. PARAMETERS 'unifiedDatabase' 'param.id' 'param.location' 'param.info' 'param.country', 'param.exchange', 'param.type' 'param.username', 'param.password' 'param.flags'
For other error code, or to match a number to an error description, check the FD_RetCode enumeration in FIDAL/c/include/fd_common.hdefs.h SEE ALSO
#include <stdlib.h>
#include <string.h>
#include "fidal.h"
int main( void )
{
FD_RetCode retCode;
FD_UDBase *unifiedDatabase;
FD_InitializeParam initParam;
FD_AddDataSourceParam addParam;
/* Initalize the library and create an unified database. */
memset( &initParam, 0, sizeof( FD_InitializeParam ) );
if( FD_Initialize( &initParam ) != FD_SUCCESS )
exit( -1 );
if( FD_UDBaseAlloc( &unifiedDatabase ) != FD_SUCCESS )
{
FD_Shutdown();
exit( -2 );
}
/* Add Yahoo! index for all supported USA exchange. */
memset( &addParam, 0, sizeof( FD_AddDataSourceParam ) );
addParam.id = FD_YAHOO_WEB;
addParam.location = "us";
retCode = FD_AddDataSource( unifiedDatabase, &addParam );
/* ... add here code to get data with FD_HistoryAlloc ... */
FD_UDBaseFree( unifiedDatabase );
FD_Shutdown();
return 0;
}
EXAMPLE (2)
#include <stdlib.h>
#include <string.h>
#include "fidal.h"
int main( void )
{
FD_UDBase *unifiedDatabase;
FD_History *data;
FD_RetCode retCode;
FD_InitializeParam initParam;
FD_AddDataSourceParam addParam;
FD_HistoryAllocParam historyParam;
unsigned int i;
/* Initialize the access to the library. */
memset( &initParam, 0, sizeof( FD_InitializeParam ) );
if( FD_Initialize( &initParam ) != FD_SUCCESS )
exit( -1 );
/* Create an unified database. */
if( FD_UDBaseAlloc( &unifiedDatabase ) != FD_SUCCESS )
{
FD_Shutdown();
exit( -2 );
}
/* Indicate where to get the data and put it in
* the "US.NASDAQ.STOCK" category. By default
* the name of the file determine the name of
* the symbol. (Wildcards '*' can be used to
* include multiple files/symbols in one call).
*/
memset( &addParam, 0, sizeof( FD_AddDataSourceParam ) );
addParam.id = FD_ASCII_FILE;
addParam.location = "c:\\my_data\\LNUX";
addParam.info = FD_DOHLCV;
addParam.category = "US.NASDAQ.STOCK";
retCode = FD_AddDataSource( unifiedDatabase, &addParam );
/* Now, display all daily close price available
* for the LNUX symbol.
*/
if( retCode == FD_SUCCESS )
{
memset( &historyParam, 0, sizeof(FD_HistoryAllocParam) );
historyParam.category = "US.NASDAQ.STOCK";
historyParam.symbol = "LNUX";
historyParam.period = FD_DAILY;
historyParam.field = FD_CLOSE|FD_VOLUME;
retCode = FD_HistoryAlloc( unifiedDatabase, &historyParam, &data );
if( retCode == FD_SUCCESS )
{
for( i=0; i < data->nbBars; i++ )
printf( "%f %d\n", data->close[i], data->volume[i] );
FD_HistoryFree( data );
}
}
/* Clean-up and exit. */
FD_UDBaseFree( unifiedDatabase );
FD_Shutdown();
return 0;
}
EXAMPLE (3)
#include "fidal.h"
#include <stdlib.h>
#include <string.h>
int main( void )
{
FD_UDBase *unifiedDatabase;
FD_RetCode retCode;
FD_InitializeParam initParam;
FD_AddDataSourceParam addParam;
/* Initialize the access to the library. */
memset( &initParam, 0, sizeof( FD_InitializeParam ) );
if( FD_Initialize( &initParam ) != FD_SUCCESS )
exit( -1 );
if( FD_UDBaseAlloc( &unifiedDatabase ) != FD_SUCCESS )
{
FD_Shutdown();
exit( -2 );
}
/* Add all ASCII files with a "dat" extension.
* These are going to be added in the default
* "ZZ.OTHER.OTHER" category.
* This advanced example use fields definition for
* handling specific file content. In that case, only
* monthly data with only the Close value and the Volume
* is provided by the data file.
* The [SYM] fields indicates where the symbol name is
* going to be extracted from. It could have been from
* anywhere in the path!
* See documentation for this flexible feature.
*/
memset( &addParam, 0, sizeof( FD_AddDataSourceParam ) );
addParam.id = FD_ASCII_FILE;
addParam.location = "..\\download\\[SYM].dat";
addParam.info = "[YYYY][MM][C][V]";
addParam.category = "US.NASDAQ.STOCK";
retCode = FD_AddDataSource( unifiedDatabase, &addParam );
if( retCode != FD_SUCCESS )
printf( "Cannot add data source (%d)\n", retCode );
else
{
/* The following function will output on screen all category
* and symbols that are now part of the unified database.
*/
FD_Report( unifiedDatabase, stdout, FD_REPORT_CATEGORY | FD_REPORT_SYMBOL );
}
/* Free all ressources. */
FD_UDBaseFree( unifiedDatabase );
FD_Shutdown();
return 0;
}
|
|