|
/**************************************************************************
* File: sample2.cpp
*
**************************************************************************/
#include
#include "..\..\..\include\usrdll22.h"
#include
#define MAX_RECS 10000
char directory[512];
Stock_Record data[MAX_RECS];
void menu()
{
printf( "\n\n" );
printf( " 1 - Dump Prices\n" );
printf( " 2 - Dump Master Record\n" );
printf( " 3 - Scan stocks\n" );
printf( " 4 - Scan masters\n" );
printf( " q - Quit\n\n" );
printf( " Please enter the command and press the Enter key: " );
}
void DumpMaster()
{
int rc;
Master_Rec Rec;
char symbol[1024] , temp[256];
printf( "\n What symbol: " );
if ( scanf( "%s" , symbol ) != 1 ) return;
strupr( symbol );
rc = R2_QP_ReadMaster( QP_EQUAL , QP_SYMBOL , symbol , &Rec ); // Try stocks and indexes
if ( rc != 0 ) rc = R2_QP_ReadFundMaster( QP_EQUAL , QP_SYMBOL , symbol , &Rec ); // Try funds
if ( rc != 0 )
{
printf ( "Symbol %s not found\n" , symbol );
return;
}
printf( "\nSymbol %s " , symbol );
memcpy( temp , Rec.issuer_desc , sizeof( Rec.issuer_desc ) );
temp[sizeof( Rec.issuer_desc )] = 0;
printf( " Name: %s" , temp );
memcpy( temp , Rec.issue_desc , sizeof( Rec.issue_desc ) );
temp[sizeof( Rec.issue_desc )] = 0;
printf( " %s\n" , temp );
if ( strnicmp( Rec.exchange , "00" , 2 ) == 0 ) strcpy( temp , "Index" );
if ( strnicmp( Rec.exchange , "01" , 2 ) == 0 ) strcpy( temp , "NY Stock Exchange" );
if ( strnicmp( Rec.exchange , "02" , 2 ) == 0 ) strcpy( temp , "American Stock Exchange" );
if ( strnicmp( Rec.exchange , "60" , 2 ) == 0 ) strcpy( temp , "NASDAQ" );
if ( strnicmp( Rec.exchange , "65" , 2 ) == 0 ) strcpy( temp , "OTC Bulletin Board" );
if ( strnicmp( Rec.exchange , "40" , 2 ) == 0 ) strcpy( temp , "Mutual Fund" );
printf( "\nExchange = %s\n\n" , temp );
}
void PrintLine( char *symbol , Stock_Record *day )
{
//print the information about that stock
printf( "%s," , symbol );
printf( "%02d" , day->MM );
printf( "%s" , "/" );
printf( "%02d" , day->DD );
printf( "%s" , "/" );
printf( "%04d," , day->YY );
printf( "%g," , day->open );
printf( "%g," , day->hi );
printf( "%g," , day->lo );
printf( "%g," , day->cl );
printf( "%ld," , day->vol );
printf( "%d\n" , day->RS );
}
void ScanMasters()
{
int rc , j , count , num , start;
Master_Rec Rec;
char symbol[12];
//
// Use the master record to scan through the database.
//
count = 0;
rc = R2_QP_ReadMaster( QP_APPROX , QP_SYMBOL , "A" , &Rec ); // Start at the first stock
while ( ( rc == 0 ) && ( count < 100 ) )
{
memcpy( symbol , Rec.symbol , sizeof(Rec.symbol) );
symbol[sizeof(Rec.symbol)] = 0; // Null terminate the symbol
num = R2_QP_LoadSymbol( symbol , &data[0] , MAX_RECS , FALSE , TRUE , 0 );
j = min ( num , 10 );
start = MAX_RECS - num;
// Print the first 10 records that were loaded
for ( int k=start ; k < start + j ; k++ )
{
//print the information about that stock
PrintLine( symbol , &data[k] );
}
rc = R2_QP_ReadMaster( QP_NEXT , QP_SYMBOL , symbol , &Rec ); // Get the next record in symbol order
count++;
}
}
void ScanStocks()
{
Master_Rec Rec;
char symbol[12];
int start , rc , count , j;
rc = R2_QP_Load_First_Symbol( data , MAX_RECS , TRUE, FALSE, &Rec);
count = 0;
// Limit the dump to 100 stocks, ignore indexes.
while ( ( count < 100 ) && ( rc >= 0 ) )
{
if ( strnicmp( Rec.exchange , "00" , 2 ) != 0 ) // Skip over the indexes
{
R2_QP_Get_Cur_Symbol( symbol ); // Get the current symbol
// Adjust the start value to print the last ten days that were loaded
start = max(MAX_RECS - rc , MAX_RECS - 10 );
for ( j=start ; j
{
PrintLine( symbol , &data[j] );
}
count++;
}
//load the next symbol
rc = R2_QP_Load_Next_Symbol( data , MAX_RECS, TRUE, FALSE, &Rec );
}
}
void DumpPrice()
{
char symbol[1024];
int j , rc , start;
printf( "\n What symbol: " );
j = 0;
while ( ( ( symbol[j] = getchar() ) != EOF ) && ( symbol[j] != '\n' ) ) j++;
symbol[j] = 0;
strupr( symbol );
rc = R2_QP_LoadSymbol( symbol , &data[0] , MAX_RECS , FALSE , TRUE , 0 );
if ( rc == 0 )
{
rc = R2_QP_LoadFundSymbol( symbol , &data[0] , MAX_RECS , FALSE , TRUE );
}
if ( rc == 0 )
{
printf( "%s not found\n" , symbol );
return;
}
printf( "%d records were loaded\n\n " , rc );
j = min ( rc , 10 );
printf( "The first %d are:\n\n" , j);
start = MAX_RECS - rc;
for ( int k=start ; k < start + j ; k++ )
{
//print the information about that stock
printf( "%s," , symbol );
printf( "%02d" , data[k].MM );
printf( "%s" , "/" );
printf( "%02d" , data[k].DD );
printf( "%s" , "/" );
printf( "%04d," , data[k].YY );
printf( "%g," , data[k].open );
printf( "%g," , data[k].hi );
printf( "%g," , data[k].lo );
printf( "%g," , data[k].cl );
printf( "%ld," , data[k].vol );
printf( "%d\n" , data[k].RS );
}
}
void main()
{
int ret;
HKEY hKey_Setup;
DWORD Type = 0;
DWORD Size = 0;
char tmp[1024];
printf( "\n\nInitializing...\n\n" );
ret = RegOpenKeyEx( HKEY_LOCAL_MACHINE, "Software\\Quotes Plus\\Setup",0,KEY_ALL_ACCESS, &hKey_Setup );
if ( ret != ERROR_SUCCESS )
{
printf ( "Could not open the registry\n\n" );
return;
}
ret = RegQueryValueEx( hKey_Setup, "DataDir" ,NULL,&Type, NULL, &Size );
if ( ret != ERROR_SUCCESS )
{
printf ( "Could not open the registry\n\n" );
return;
}
directory[0] = 0;
ret = RegQueryValueEx( hKey_Setup, "DataDir" ,NULL,&Type, (BYTE*)&directory[0], &Size );
if ( ret != ERROR_SUCCESS )
{
printf ( "Could not open the registry\n\n" );
return;
}
if( directory[0] == 0 )
{
printf ( "Quotes Plus is not set up on this computer\n\n" );
return;
}
RegCloseKey( hKey_Setup );
if ( directory[strlen(directory)-1] == '\\' ) directory[strlen(directory)-1] = 0;
R2_InitReadStock( directory , true , 0 , false );
ret = R2_Open_Files( ALL_DATA_FILES , directory );
if ( ret != 0 )
{
printf( "Could not open qp data files" );
abort();
}
ret = R2_Open_Files( MASTER_FILE , directory );
if ( ret != 0 )
{
printf( "Could not open qp master file" );
abort();
}
ret = R2_Open_Files( FUND_MASTER , directory );
if ( ret != 0 )
{
printf( "Could not open qp mutual fund master file" );
abort();
}
menu();
while ( scanf( "%s" , tmp ) == 1 )
{
switch (tmp[0])
{
case 'q' :
case 'Q' : exit(0);
break;
case '1' : getchar(); // Get the enter key
DumpPrice();
break;
case '2' : DumpMaster();
break;
case '3' : ScanStocks();
break;
case '4' : ScanMasters();
break;
}
menu();
} // end while
R2_Close_Files( ALL_DATA_FILES );
R2_Close_Files( MASTER_FILE );
R2_Close_Files( FUND_MASTER );
R2_Done();
}
|