예제 #1
0
/**** Local functions definitions.     ****/
static ErrorNumber test_index( TA_Libc *libHandle, TA_UDBase *udb )
{
   TA_RetCode retCode;
   TA_AddDataSourceParam param;
   TA_History *history;
   ErrorNumber errNumber;

   (void)libHandle;

   /* Add the Yaho! data source. */
   memset( &param, 0, sizeof( param ) );
   param.id = TA_YAHOO_WEB;
   param.location = "us";

   retCode = TA_AddDataSource( udb, &param );
   if( retCode != TA_SUCCESS )
   {
      reportError( "TA_AddDataSource", retCode );

      return TA_YAHOO_ADDDATASOURCE_USA_FAILED;
   }

   /* Get something from NASDAQ. */
   retCode = TA_HistoryAlloc( udb, "US.NASDAQ.STOCK", "MSFT",
                              TA_DAILY, 0, 0, TA_CLOSE|TA_TIMESTAMP|TA_VOLUME,
                              &history );
   if( retCode != TA_SUCCESS )
   {
      reportError( "TA_HistoryAlloc", retCode );
      return TA_YAHOO_HISTORYALLOC_1_FAILED;
   }

   if( history->nbBars < 3000 )
   {
      printf( "Insufficient nbBars returned for MSFT ticker test (%d < 3000)\n", history->nbBars );
      return TA_YAHOO_VALUE_1_FAILED;
   }

   if( !history->close || !history->timestamp || !history->volume )
   {
      return TA_YAHOO_FIELD_MISSING_1;
   }

   retCode = TA_HistoryFree( history );
   if( retCode != TA_SUCCESS )
   {
      reportError( "TA_HistoryFree", retCode );
      return TA_YAHOO_HISTORYFREE_FAILED;
   }

   /* Add canadian index. */
   param.id = TA_YAHOO_WEB;
   param.location = "ca";

   retCode = TA_AddDataSource( udb, &param );
   if( retCode != TA_SUCCESS )
   {
      reportError( "TA_AddDataSource", retCode );

      return TA_YAHOO_ADDDATASOURCE_CAN_FAILED;
   }

   /* Get something from NYSE. */
   retCode = TA_HistoryAlloc( udb, "US.NYSE.STOCK", "IBM",
                              TA_WEEKLY, 0, 0, TA_OPEN,
                              &history );
   if( retCode != TA_SUCCESS )
   {
      reportError( "TA_HistoryAlloc", retCode );
      return TA_YAHOO_HISTORYALLOC_2_FAILED;
   }

   if( history->nbBars < 2065 )
   {
      return TA_YAHOO_VALUE_2_FAILED;
   }

   if( !history->open )
   {
      return TA_YAHOO_FIELD_MISSING_2;
   }

   retCode = TA_HistoryFree( history );
   if( retCode != TA_SUCCESS )
   {
      reportError( "TA_HistoryFree", retCode );
      return TA_YAHOO_HISTORYFREE_FAILED;
   }

   /* Get something from canadian market. 
    * Also test stock using 200 price bar slice.
    */   
   retCode = TA_HistoryAlloc( udb, "CA.CDNX.STOCK", "MRY",
                              TA_DAILY, 0, 0, TA_ALL,
                              &history );
   if( retCode != TA_SUCCESS )
   {
      reportError( "TA_HistoryAlloc", retCode );
      return TA_YAHOO_HISTORYALLOC_3_FAILED;
   }

   if( history->nbBars < 700 )
   {
      return TA_YAHOO_VALUE_3_FAILED;
   }

   if( !history->open   ||
       !history->high   ||
       !history->low    ||
       !history->close  ||
       !history->volume ||
       !history->timestamp )
   {
      return TA_YAHOO_FIELD_MISSING_3;
   }

   errNumber = checkRangeSame( udb, history, &history->timestamp[0], &history->timestamp[0], 0, 1 );
   if( errNumber != TA_TEST_PASS )
   {
      printf( "Failed: Test getting first price bar only.\n" );
      return errNumber;
   }

   errNumber = checkRangeSame( udb, history, &history->timestamp[1], &history->timestamp[1], 1, 1 );
   if( errNumber != TA_TEST_PASS )
   {
      printf( "Failed: Test getting second price bar only.\n" );
      return errNumber;
   }

   errNumber = checkRangeSame( udb, history, &history->timestamp[history->nbBars-2], &history->timestamp[history->nbBars-2], history->nbBars-2, 1 );
   if( errNumber != TA_TEST_PASS )
   {
      printf( "Failed: Test getting before last price bar only.\n" );
      return errNumber;
   }
   
   errNumber = checkRangeSame( udb, history, &history->timestamp[history->nbBars-1], &history->timestamp[history->nbBars-1], history->nbBars-1, 1 );
   if( errNumber != TA_TEST_PASS )
   {
      printf( "Failed: Test getting last price bar only.\n" );
      return errNumber;
   }
   
   errNumber = checkRangeSame( udb, history, &history->timestamp[history->nbBars-200], &history->timestamp[history->nbBars-1], history->nbBars-200, 200 );
   if( errNumber != TA_TEST_PASS )
   {
      printf( "Failed: Test getting last 200 price bars only.\n" );
      return errNumber;
   }
   
   errNumber = checkRangeSame( udb, history, &history->timestamp[0], &history->timestamp[199], 0, 200 );
   if( errNumber != TA_TEST_PASS )
   {
      printf( "Failed: Test getting first 200 price bars only.\n" );
      return errNumber;
   }

   retCode = TA_HistoryFree( history );
   if( retCode != TA_SUCCESS )
   {
      reportError( "TA_HistoryFree", retCode );
      return TA_YAHOO_HISTORYFREE_FAILED;
   }

   return TA_TEST_PASS;
}
예제 #2
0
/**** Local functions definitions.     ****/
ErrorNumber test_period( TA_UDBase *unifiedDatabase )
{
   TA_RetCode retCode;
   TA_History *history;
   const TA_Timestamp *timestamp;
   unsigned int i;
   ErrorNumber retValue;
   TA_AddDataSourceParam addParam;
   TA_HistoryAllocParam histParam;

   printf( "Testing period/timeframe conversion\n" );

   /* Add access to some intra-day data. */
   memset( &addParam, 0, sizeof( TA_AddDataSourceParam) );
   addParam.id = TA_ASCII_FILE;
   addParam.location = "..\\src\\tools\\ta_regtest\\sampling\\ES.csv";
   addParam.info ="[YY][MM][DD][HH][MN=5][O][H][L][C][V]";
   addParam.category = "TA_SIM_REF";
   retCode = TA_AddDataSource( unifiedDatabase,&addParam );
   if( retCode != TA_SUCCESS )
   {
      printf( "Can't access [%s] (%d)\n", addParam.location, retCode );
      return TA_PERIOD_HISTORYALLOC_FAILED;
   }

   /* Because period transformation are very
    * dependend on the "delta" timestamp functions,
    * let's indepedently verify some of these.
    */
   retValue = testTimestampDelta();
   if( retValue != TA_TEST_PASS )
      return retValue;

   /* Verify everything from the checkTable. */
   for( i=0; i < CHECK_TABLE_SIZE; i++ )
   {
      /* Validate by requesting all the data in a
       * different timeframe.
       */
      memset( &histParam, 0, sizeof( TA_HistoryAllocParam ) );
      histParam.category = "TA_SIM_REF";
      histParam.symbol   = checkTable[i].symbol;
      histParam.field    = TA_ALL;
      histParam.period   = checkTable[i].period;
      histParam.flags    = checkTable[i].flags;
      retCode = TA_HistoryAlloc( unifiedDatabase, &histParam, &history );

      if( retCode != TA_SUCCESS )
      {
         printf( "%s%d.1 [%d]\n", fail_header, i, retCode );
         return TA_PERIOD_HISTORYALLOC_FAILED;
      }

      if( history->nbBars != checkTable[i].nbExpectedPriceBar )
      {
         printf( "%s%d.2 [%d != %d]\n",
                 fail_header, i,
                 history->nbBars,
                 checkTable[i].nbExpectedPriceBar );
         TA_HistoryFree( history );
         return TA_PERIOD_NBBAR_INCORRECT;
      }

      /* If the call is expected to return an empty history, no further check are done. */
      if( checkTable[i].nbExpectedPriceBar == 0 )
      {
         retCode = TA_HistoryFree( history );
         if( retCode != TA_SUCCESS )
         {
           printf( "%s%d.16 [%d]\n", fail_header, i, retCode );
           return TA_PERIOD_HISTORYFREE_FAILED;
         }
         continue;
      }

      #define CHECK_VALUE_OK(varName, subtestNo ) \
      { \
         if( !TA_REAL_EQ( history->varName[checkTable[i].thePriceBarToCheck], checkTable[i].expected_##varName, 0.01 ) ) \
         { \
            printf( "%s%d.%d [%f != %f]\n", \
                    fail_header, i, subtestNo, \
                    (TA_Real) history->varName[checkTable[i].thePriceBarToCheck], \
                    (TA_Real) checkTable[i].expected_##varName ); \
            TA_HistoryFree( history ); \
            return TA_PERIOD_PRICE_INCORRECT; \
         } \
      }

      CHECK_VALUE_OK( open,   3 );
      CHECK_VALUE_OK( high,   4 );
      CHECK_VALUE_OK( low,    5 );
      CHECK_VALUE_OK( close,  6 );
      CHECK_VALUE_OK( volume, 7 );

      if( history->openInterest != NULL )
      {
         printf( "%s%d.8\n", fail_header, i );
         TA_HistoryFree( history );
         return TA_PERIOD_OPENINTEREST_INCORRECT;
      }

      timestamp = &history->timestamp[checkTable[i].thePriceBarToCheck];
      if( TA_GetYear( timestamp ) != checkTable[i].expected_year )
      {
         printf( "%s%d.9 %d\n", fail_header, i, TA_GetYear(timestamp) );
         TA_HistoryFree( history );
         return TA_PERIOD_TIMESTAMP_YEAR_INCORRECT;
      }

      if( TA_GetMonth( timestamp ) != checkTable[i].expected_month )
      {
         printf( "%s%d.10 %d\n", fail_header, i, TA_GetMonth(timestamp) );
         TA_HistoryFree( history );
         return TA_PERIOD_TIMESTAMP_MONTH_INCORRECT;
      }

      if( TA_GetDay( timestamp ) != checkTable[i].expected_day )
      {
         printf( "%s%d.11 %d\n", fail_header, i, TA_GetDay(timestamp) );
         TA_HistoryFree( history );
         return TA_PERIOD_TIMESTAMP_DAY_INCORRECT;
      }

      if( TA_GetHour( timestamp ) != checkTable[i].expected_hour )
      {
         printf( "%s%d.12 %d\n", fail_header, i, TA_GetHour(timestamp) );
         TA_HistoryFree( history );
         return TA_PERIOD_TIMESTAMP_DAY_INCORRECT;
      }

      if( TA_GetMin( timestamp ) != checkTable[i].expected_min )
      {
         printf( "%s%d.13 %d\n", fail_header, i, TA_GetMin(timestamp) );
         TA_HistoryFree( history );
         return TA_PERIOD_TIMESTAMP_DAY_INCORRECT;
      }

      if( TA_GetSec( timestamp ) != checkTable[i].expected_sec )
      {
         printf( "%s%d.14 %d\n", fail_header, i, TA_GetSec(timestamp) );
         TA_HistoryFree( history );
         return TA_PERIOD_TIMESTAMP_DAY_INCORRECT;
      }

      retCode = TA_HistoryFree( history );
      if( retCode != TA_SUCCESS )
      {
         printf( "%s%d.15 [%d]\n", fail_header, i, retCode );
         return TA_PERIOD_HISTORYFREE_FAILED;
      }
   }

   return 0; /* Succcess. */
}
예제 #3
0
static ErrorNumber testHistoryAlloc( void )
{
   TA_UDBase *unifiedDatabase;
   TA_History *data;
   TA_RetCode retCode;
   TA_InitializeParam param;
   TA_AddDataSourceParam addParam;
   TA_HistoryAllocParam histParam;

   memset( &param, 0, sizeof( TA_InitializeParam ) );
   param.logOutput = stdout;
   retCode = TA_Initialize( &param );

   if( retCode != TA_SUCCESS )
   {
      printf( "Cannot initialize TA-LIB (%d)!", retCode );
      return TA_REGTEST_HISTORYALLOC_0;
   }

   /* Create an unified database. */
   if( TA_UDBaseAlloc( &unifiedDatabase ) != TA_SUCCESS )
   {
      TA_Shutdown();
      return TA_REGTEST_HISTORYALLOC_1;
   }
   
   /* USE SIMULATOR DATA */
   memset( &addParam, 0, sizeof( TA_AddDataSourceParam ) );
   addParam.id = TA_SIMULATOR;

   addParam.flags = TA_NO_FLAGS;
   retCode = TA_AddDataSource( unifiedDatabase, &addParam );

   /* Now, display all daily close price available
    * for the DAILY_REF_0 symbol.
    */
   if( retCode != TA_SUCCESS )
      return TA_REGTEST_ADDDSOURCE_FAILED;

   #if defined __BORLANDC__
      #pragma warn -ccc
      #pragma warn -rch
   #endif
      
   #define CHECK_FIELDSUBSET(field_par) \
         { \
            memset( &histParam, 0, sizeof( TA_HistoryAllocParam ) ); \
            histParam.category = "TA_SIM_REF"; \
            histParam.symbol   = "DAILY_REF_0"; \
            histParam.field    = field_par; \
            histParam.period   = TA_DAILY; \
            retCode = TA_HistoryAlloc( unifiedDatabase, &histParam, &data ); \
            if( retCode == TA_SUCCESS ) \
            { \
               if( (field_par) & TA_OPEN ) \
               { \
                  if( !data->open ) \
                     return TA_REGTEST_HISTORYALLOC_2; \
                  if( data->open[0] != 92.5 ) \
                     return TA_REGTEST_HISTORYALLOC_3; \
               } \
               else \
               { \
                  if( data->open ) \
                     return TA_REGTEST_HISTORYALLOC_4; \
               } \
               if( (field_par) & TA_HIGH ) \
               { \
                  if( !data->high ) \
                     return TA_REGTEST_HISTORYALLOC_5; \
                  if( data->high[0] != 93.25 ) \
                     return TA_REGTEST_HISTORYALLOC_6; \
               } \
               else \
               { \
                  if( data->high ) \
                     return TA_REGTEST_HISTORYALLOC_7; \
               } \
               if( (field_par) & TA_LOW ) \
               { \
                  if( !data->low ) \
                     return TA_REGTEST_HISTORYALLOC_8; \
                  if( data->low[0] != 90.75 ) \
                     return TA_REGTEST_HISTORYALLOC_9; \
               } \
               else \
               { \
                  if( data->low ) \
                     return TA_REGTEST_HISTORYALLOC_10; \
               } \
               if( (field_par) & TA_CLOSE ) \
               { \
                  if( !data->close ) \
                     return TA_REGTEST_HISTORYALLOC_11; \
                  if( data->close[0] != 91.50 ) \
                     return TA_REGTEST_HISTORYALLOC_12; \
               } \
               else \
               { \
                  if( data->close ) \
                     return TA_REGTEST_HISTORYALLOC_13; \
               } \
               if( (field_par) & TA_VOLUME ) \
               { \
                  if( !data->volume ) \
                     return TA_REGTEST_HISTORYALLOC_14; \
                  if( data->volume[0] != 4077500) \
                     return TA_REGTEST_HISTORYALLOC_15; \
               } \
               else \
               { \
                  if( data->volume ) \
                     return TA_REGTEST_HISTORYALLOC_16; \
               } \
               if( (field_par) & TA_TIMESTAMP ) \
               { \
                  if( !data->timestamp ) \
                     return TA_REGTEST_HISTORYALLOC_17; \
               } \
               else \
               { \
                  if( data->timestamp ) \
                     return TA_REGTEST_HISTORYALLOC_18; \
               } \
               TA_HistoryFree( data ); \
            } \
            else \
            { \
               printf( "Cannot TA_HistoryAlloc for TA_SIM_REF (%d)!\n", retCode ); \
               return TA_REGTEST_HISTORYALLOC_19; \
            } \
         } 
         /* 6 Fields */
         CHECK_FIELDSUBSET(TA_TIMESTAMP|TA_OPEN|TA_CLOSE|TA_HIGH|TA_LOW|TA_VOLUME)

         /* 5 Fields */
         CHECK_FIELDSUBSET(TA_OPEN|TA_CLOSE|TA_HIGH|TA_LOW|TA_VOLUME)
         CHECK_FIELDSUBSET(TA_TIMESTAMP|TA_CLOSE|TA_HIGH|TA_LOW|TA_VOLUME)
         CHECK_FIELDSUBSET(TA_TIMESTAMP|TA_OPEN|TA_HIGH|TA_LOW|TA_VOLUME)
         CHECK_FIELDSUBSET(TA_TIMESTAMP|TA_OPEN|TA_CLOSE|TA_LOW|TA_VOLUME)
         CHECK_FIELDSUBSET(TA_TIMESTAMP|TA_OPEN|TA_CLOSE|TA_HIGH|TA_VOLUME)

         /* 4 Fields */
         CHECK_FIELDSUBSET(TA_CLOSE|TA_HIGH|TA_LOW|TA_VOLUME)
         CHECK_FIELDSUBSET(TA_OPEN|TA_HIGH|TA_LOW|TA_VOLUME)
         CHECK_FIELDSUBSET(TA_OPEN|TA_CLOSE|TA_LOW|TA_VOLUME)
         CHECK_FIELDSUBSET(TA_OPEN|TA_CLOSE|TA_HIGH|TA_VOLUME)
         CHECK_FIELDSUBSET(TA_OPEN|TA_CLOSE|TA_HIGH|TA_LOW)

         CHECK_FIELDSUBSET(TA_TIMESTAMP|TA_HIGH|TA_LOW|TA_VOLUME)
         CHECK_FIELDSUBSET(TA_TIMESTAMP|TA_CLOSE|TA_LOW|TA_VOLUME)
         CHECK_FIELDSUBSET(TA_TIMESTAMP|TA_CLOSE|TA_HIGH|TA_VOLUME)
         CHECK_FIELDSUBSET(TA_TIMESTAMP|TA_CLOSE|TA_HIGH|TA_LOW)

         CHECK_FIELDSUBSET(TA_TIMESTAMP|TA_OPEN|TA_LOW|TA_VOLUME)
         CHECK_FIELDSUBSET(TA_TIMESTAMP|TA_OPEN|TA_HIGH|TA_VOLUME)
         CHECK_FIELDSUBSET(TA_TIMESTAMP|TA_OPEN|TA_HIGH|TA_LOW)

         CHECK_FIELDSUBSET(TA_TIMESTAMP|TA_OPEN|TA_CLOSE|TA_VOLUME)
         CHECK_FIELDSUBSET(TA_TIMESTAMP|TA_OPEN|TA_CLOSE|TA_LOW)

         CHECK_FIELDSUBSET(TA_TIMESTAMP|TA_OPEN|TA_CLOSE|TA_HIGH)

         /* 3 Fields */
         CHECK_FIELDSUBSET(TA_HIGH|TA_LOW|TA_VOLUME)
         CHECK_FIELDSUBSET(TA_CLOSE|TA_LOW|TA_VOLUME)
         CHECK_FIELDSUBSET(TA_CLOSE|TA_HIGH|TA_VOLUME)
         CHECK_FIELDSUBSET(TA_CLOSE|TA_HIGH|TA_LOW)

         CHECK_FIELDSUBSET(TA_OPEN|TA_LOW|TA_VOLUME)
         CHECK_FIELDSUBSET(TA_OPEN|TA_HIGH|TA_VOLUME)
         CHECK_FIELDSUBSET(TA_OPEN|TA_HIGH|TA_LOW)

         CHECK_FIELDSUBSET(TA_OPEN|TA_CLOSE|TA_VOLUME)
         CHECK_FIELDSUBSET(TA_OPEN|TA_CLOSE|TA_LOW)

         CHECK_FIELDSUBSET(TA_OPEN|TA_CLOSE|TA_HIGH)

         CHECK_FIELDSUBSET(TA_TIMESTAMP|TA_OPEN|TA_HIGH)
         CHECK_FIELDSUBSET(TA_TIMESTAMP|TA_OPEN|TA_LOW)
         CHECK_FIELDSUBSET(TA_TIMESTAMP|TA_OPEN|TA_CLOSE)
         CHECK_FIELDSUBSET(TA_TIMESTAMP|TA_OPEN|TA_VOLUME)

         CHECK_FIELDSUBSET(TA_TIMESTAMP|TA_HIGH|TA_LOW)
         CHECK_FIELDSUBSET(TA_TIMESTAMP|TA_HIGH|TA_CLOSE)
         CHECK_FIELDSUBSET(TA_TIMESTAMP|TA_HIGH|TA_VOLUME)

         CHECK_FIELDSUBSET(TA_TIMESTAMP|TA_LOW|TA_CLOSE)
         CHECK_FIELDSUBSET(TA_TIMESTAMP|TA_LOW|TA_VOLUME)

         CHECK_FIELDSUBSET(TA_TIMESTAMP|TA_CLOSE|TA_VOLUME)

         /* Two field. */
         CHECK_FIELDSUBSET(TA_TIMESTAMP|TA_OPEN)
         CHECK_FIELDSUBSET(TA_TIMESTAMP|TA_HIGH)
         CHECK_FIELDSUBSET(TA_TIMESTAMP|TA_LOW)
         CHECK_FIELDSUBSET(TA_TIMESTAMP|TA_CLOSE)
         CHECK_FIELDSUBSET(TA_TIMESTAMP|TA_VOLUME)

         CHECK_FIELDSUBSET(TA_OPEN|TA_HIGH)
         CHECK_FIELDSUBSET(TA_OPEN|TA_LOW)
         CHECK_FIELDSUBSET(TA_OPEN|TA_CLOSE)
         CHECK_FIELDSUBSET(TA_OPEN|TA_VOLUME)

         CHECK_FIELDSUBSET(TA_HIGH|TA_LOW)
         CHECK_FIELDSUBSET(TA_HIGH|TA_CLOSE)
         CHECK_FIELDSUBSET(TA_HIGH|TA_VOLUME)

         CHECK_FIELDSUBSET(TA_LOW|TA_CLOSE)
         CHECK_FIELDSUBSET(TA_LOW|TA_VOLUME)

         CHECK_FIELDSUBSET(TA_CLOSE|TA_VOLUME)

         /* One Field */
         CHECK_FIELDSUBSET(TA_TIMESTAMP);
         CHECK_FIELDSUBSET(TA_OPEN);
         CHECK_FIELDSUBSET(TA_HIGH)
         CHECK_FIELDSUBSET(TA_LOW)
         CHECK_FIELDSUBSET(TA_CLOSE)
         CHECK_FIELDSUBSET(TA_VOLUME)

   #undef CHECK_FIELDSUBSET

   /* Clean-up and exit. */
   TA_UDBaseFree( unifiedDatabase );
   TA_Shutdown();
   return TA_SUCCESS;
}
예제 #4
0
/**** Local functions definitions.     ****/
static ErrorNumber test_with_simulator( void )
{
   TA_UDBase  *uDBase;
   TA_History *history;
   TA_AddDataSourceParam param;
   TA_RetCode  retCode;
   ErrorNumber retValue;
   TA_HistoryAllocParam histParam;

   /* Initialize the library. */
   retValue = allocLib( &uDBase );
   if( retValue != TA_TEST_PASS )
      return retValue;

   /* Add a datasource using pre-defined data.
    * This data is embedded in the library and does
    * not required any external data provider.
    * The test functions may assume that this data will
    * be unmodified forever by TA-LIB.
    */
   memset( &param, 0, sizeof( TA_AddDataSourceParam ) );
   param.id = TA_SIMULATOR;
   retCode = TA_AddDataSource( uDBase, &param );

   if( retCode != TA_SUCCESS )
   {
      printf( "TA_AddDataSource failed [%d]\n", retCode );
      freeLib( uDBase );
      return TA_REGTEST_ADDDATASOURCE_FAILED;
   }

   /* Regression testing of the functionality provided
    * by ta_period.c
    */
   retValue = test_period( uDBase );
   if( retValue != TA_TEST_PASS )
   {
      freeLib( uDBase );
      return retValue;
   }

   /* Allocate the reference historical data. */
   memset( &histParam, 0, sizeof( TA_HistoryAllocParam ) );
   histParam.category = "TA_SIM_REF";
   histParam.symbol   = "DAILY_REF_0";
   histParam.field    = TA_ALL;
   histParam.period   = TA_DAILY;
   retCode = TA_HistoryAlloc( uDBase, &histParam, &history );

   if( retCode != TA_SUCCESS )
   {
      printf( "TA_HistoryAlloc failed [%d]\n", retCode );
      freeLib( uDBase );
      return TA_REGTEST_HISTORYALLOC_FAILED;
   }

   /* Perform testing of each of the TA Functions. */
   retValue = testTAFunction_ALL( history );
   if( retValue != TA_TEST_PASS )
   {
      TA_HistoryFree( history );
      freeLib( uDBase );
      return retValue;
   }

   /* Clean-up and exit. */

   retCode = TA_HistoryFree( history );
   if( retCode != TA_SUCCESS )
   {
      printf( "TA_HistoryFree failed [%d]\n", retCode );
      freeLib( uDBase );
      return TA_REGTEST_HISTORYFREE_FAILED;
   }

   retValue = freeLib( uDBase );
   if( retValue != TA_TEST_PASS )
      return retValue;

   return TA_TEST_PASS; /* All test succeed. */
}
예제 #5
0
static ErrorNumber test_one_symbol( TA_UDBase *udb )
{
   TA_RetCode retCode;
   TA_AddDataSourceParam param;
   TA_History *history;
   ErrorNumber errNumber;
   TA_HistoryAllocParam histParam;

#if 0
   /* Get KPN.AS 
    *
    * Around 9/5/2004 that symbol had a negative dividend returned from Yahoo!.
    * Un-comment this section of the code to test the TA_INVALID_NEGATIVE_DIVIDEND
    * return value.
    */
   memset( &param, 0, sizeof( param ) );
   param.id = TA_YAHOO_ONE_SYMBOL;
   param.info = "KPN.AS";
   retCode = TA_AddDataSource( udb, &param );
   if( retCode != TA_SUCCESS )
   {
      reportError( "TA_AddDataSource", retCode );
      return TA_YAHOO_ADDDATASOURCE_KPN_AS_FAILED;
   }

   memset( &histParam, 0, sizeof( TA_HistoryAllocParam ) );
   histParam.symbol   = "KPN.AS";
   histParam.field    = TA_CLOSE|TA_VOLUME;
   histParam.period   = TA_DAILY;
   retCode = TA_HistoryAlloc( udb, &histParam, &history );
   if( retCode != TA_SUCCESS )
   {
      reportError( "TA_HistoryAlloc", retCode );
      return TA_YAHOO_HISTORYALLOC_KPN_AS_FAILED;
   } 
   TA_HistoryFree( history );
#endif

   /* Test with MSFT on NASDAQ stock. */
   memset( &param, 0, sizeof( param ) );
   param.id = TA_YAHOO_ONE_SYMBOL;
   param.info = "MSFT";
   param.category = "Whatever.US.NASDAQ.STOCK";
   param.symbol = "Whatever.MSFT";

   retCode = TA_AddDataSource( udb, &param );
   if( retCode != TA_SUCCESS )
   {
      reportError( "TA_AddDataSource", retCode );

      return TA_YAHOO_ADDDATASOURCE_USA_FAILED;
   }

   /* Get something from NASDAQ. */
   memset( &histParam, 0, sizeof( TA_HistoryAllocParam ) );
   histParam.category = "Whatever.US.NASDAQ.STOCK";
   histParam.symbol   = "Whatever.MSFT";
   histParam.field    = TA_CLOSE|TA_TIMESTAMP|TA_VOLUME;
   histParam.period   = TA_DAILY;
   retCode = TA_HistoryAlloc( udb, &histParam, &history );

   if( retCode != TA_SUCCESS )
   {
      reportError( "TA_HistoryAlloc", retCode );
      return TA_YAHOO_HISTORYALLOC_1_FAILED;
   }

   if( history->nbBars < 3000 )
   {
      printf( "Insufficient nbBars returned for MSFT ticker test (%d < 3000)\n", history->nbBars );
      return TA_YAHOO_VALUE_1_FAILED;
   }

   if( !history->close || !history->timestamp || !history->volume )
   {
      return TA_YAHOO_FIELD_MISSING_1;
   }

   retCode = TA_HistoryFree( history );
   if( retCode != TA_SUCCESS )
   {
      reportError( "TA_HistoryFree", retCode );
      return TA_YAHOO_HISTORYFREE_FAILED;
   }

   /* Add complete canadian index. */
   memset( &param, 0, sizeof( param ) );
   param.id = TA_YAHOO_WEB;
   param.location = "ca";
   retCode = TA_AddDataSource( udb, &param );
   if( retCode != TA_SUCCESS )
   {
      reportError( "TA_AddDataSource", retCode );

      return TA_YAHOO_ADDDATASOURCE_CAN_FAILED;
   }

   /* Add NT. */
   memset( &param, 0, sizeof( param ) );
   param.id = TA_YAHOO_ONE_SYMBOL;
   param.info = "NT.TO";

   retCode = TA_AddDataSource( udb, &param );
   if( retCode != TA_SUCCESS )
   {
      reportError( "TA_AddDataSource", retCode );

      return TA_YAHOO_ADDDATASOURCE_CAN_FAILED;
   }

   /* Get NT from TA_YAHOO_ONE_STMBOL data source. */
   memset( &histParam, 0, sizeof( TA_HistoryAllocParam ) );
   histParam.symbol   = "NT.TO";   
   histParam.field    = TA_ALL,
   histParam.period   = TA_DAILY;
   retCode = TA_HistoryAlloc( udb, &histParam, &history );
   if( retCode != TA_SUCCESS )
   {
      reportError( "TA_HistoryAlloc", retCode );
      return TA_YAHOO_HISTORYALLOC_3_FAILED;
   }

   if( history->nbBars < 700 )
   {
      return TA_YAHOO_VALUE_3_FAILED;
   }

   if( !history->open   ||
       !history->high   ||
       !history->low    ||
       !history->close  ||
       !history->volume ||
       !history->timestamp )
   {
      return TA_YAHOO_FIELD_MISSING_3;
   }

   /* Get NT from the TA_YAHOO_WEB and make sure they return the same data. */
   errNumber = checkRangeSame( udb, history,
                               &history->timestamp[history->nbBars-200],
                               &history->timestamp[history->nbBars-1],
                               TA_DAILY, history->nbBars-200, 200 );
   if( errNumber != TA_TEST_PASS )
   {
      printf( "Failed: Test getting last 200 price bars only.\n" );
      return errNumber;
   }
   
   retCode = TA_HistoryFree( history );
   if( retCode != TA_SUCCESS )
   {
      reportError( "TA_HistoryFree", retCode );
      return TA_YAHOO_HISTORYFREE_FAILED;
   }
   
   return TA_TEST_PASS;
}
예제 #6
0
/**** Local functions definitions.     ****/
static ErrorNumber test_web( TA_UDBase *udb )
{
   TA_RetCode retCode;
   TA_AddDataSourceParam param;
   TA_History *history;
   ErrorNumber errNumber;
   TA_HistoryAllocParam histParam;

   /* Add the Yaho! data source. */
   memset( &param, 0, sizeof( param ) );
   param.id = TA_YAHOO_WEB;
   param.location = "us;server=ichart7.finance.dcn.yahoo.com"; /* ichart7.finance.dcn.yahoo.com */

   retCode = TA_AddDataSource( udb, &param );
   if( retCode != TA_SUCCESS )
   {
      reportError( "TA_AddDataSource", retCode );

      return TA_YAHOO_ADDDATASOURCE_USA_FAILED;
   }

   /* Get something from NASDAQ. */
   memset( &histParam, 0, sizeof( TA_HistoryAllocParam ) );
   histParam.category = "US.NASDAQ.STOCK";
   histParam.symbol   = "MSFT";
   histParam.field    = TA_CLOSE|TA_TIMESTAMP|TA_VOLUME;
   histParam.period   = TA_DAILY;
   retCode = TA_HistoryAlloc( udb, &histParam, &history );

   if( retCode != TA_SUCCESS )
   {
      reportError( "TA_HistoryAlloc", retCode );
      return TA_YAHOO_HISTORYALLOC_1_FAILED;
   }

   if( history->nbBars < 3000 )
   {
      printf( "Insufficient nbBars returned for MSFT ticker test (%d < 3000)\n", history->nbBars );
      return TA_YAHOO_VALUE_1_FAILED;
   }

   if( !history->close || !history->timestamp || !history->volume )
   {
      return TA_YAHOO_FIELD_MISSING_1;
   }

   retCode = TA_HistoryFree( history );
   if( retCode != TA_SUCCESS )
   {
      reportError( "TA_HistoryFree", retCode );
      return TA_YAHOO_HISTORYFREE_FAILED;
   }

   /* Add canadian index. */
   param.id = TA_YAHOO_WEB;
   param.location = "ca";
   /*param.flags = TA_DO_NOT_SPLIT_ADJUST|TA_DO_NOT_VALUE_ADJUST;*/

   retCode = TA_AddDataSource( udb, &param );
   if( retCode != TA_SUCCESS )
   {
      reportError( "TA_AddDataSource", retCode );

      return TA_YAHOO_ADDDATASOURCE_CAN_FAILED;
   }

   /* Get something from NYSE. */
   memset( &histParam, 0, sizeof( TA_HistoryAllocParam ) );
   histParam.category = "US.NYSE.STOCK";
   histParam.symbol   = "IBM";
   histParam.field    = TA_OPEN;
   histParam.period   = TA_WEEKLY;
   retCode = TA_HistoryAlloc( udb, &histParam, &history );
   if( retCode != TA_SUCCESS )
   {
      reportError( "TA_HistoryAlloc", retCode );
      return TA_YAHOO_HISTORYALLOC_2_FAILED;
   }

   if( history->nbBars < 2065 )
   {
      return TA_YAHOO_VALUE_2_FAILED;
   }

   if( !history->open )
   {
      return TA_YAHOO_FIELD_MISSING_2;
   }

   retCode = TA_HistoryFree( history );
   if( retCode != TA_SUCCESS )
   {
      reportError( "TA_HistoryFree", retCode );
      return TA_YAHOO_HISTORYFREE_FAILED;
   }

   /* Get something from canadian market. 
    * Also test stock using 200 price bar slice.
    */
   memset( &histParam, 0, sizeof( TA_HistoryAllocParam ) );
   histParam.category = "CA.TSE.STOCK";
   histParam.symbol   = "NT";
   histParam.field    = TA_ALL,
   histParam.period   = TA_DAILY;
   retCode = TA_HistoryAlloc( udb, &histParam, &history );
   if( retCode != TA_SUCCESS )
   {
      reportError( "TA_HistoryAlloc", retCode );
      return TA_YAHOO_HISTORYALLOC_3_FAILED;
   }

   if( history->nbBars < 700 )
   {
      return TA_YAHOO_VALUE_3_FAILED;
   }

   if( !history->open   ||
       !history->high   ||
       !history->low    ||
       !history->close  ||
       !history->volume ||
       !history->timestamp )
   {
      return TA_YAHOO_FIELD_MISSING_3;
   }

   errNumber = checkRangeSame( udb, history, &history->timestamp[0], &history->timestamp[0], TA_DAILY, 0, 1 );
   if( errNumber != TA_TEST_PASS )
   {
      printf( "Failed: Test getting first price bar only.\n" );
      return errNumber;
   }

   errNumber = checkRangeSame( udb, history, &history->timestamp[1], &history->timestamp[1], TA_DAILY, 1, 1 );
   if( errNumber != TA_TEST_PASS )
   {
      printf( "Failed: Test getting second price bar only.\n" );
      return errNumber;
   }

   errNumber = checkRangeSame( udb, history, &history->timestamp[history->nbBars-2], &history->timestamp[history->nbBars-2], TA_DAILY, history->nbBars-2, 1 );
   if( errNumber != TA_TEST_PASS )
   {
      printf( "Failed: Test getting before last price bar only.\n" );
      return errNumber;
   }
   
   errNumber = checkRangeSame( udb, history, &history->timestamp[history->nbBars-1], &history->timestamp[history->nbBars-1], TA_DAILY, history->nbBars-1, 1 );
   if( errNumber != TA_TEST_PASS )
   {
      printf( "Failed: Test getting last price bar only.\n" );
      return errNumber;
   }
   
   errNumber = checkRangeSame( udb, history, &history->timestamp[history->nbBars-200], &history->timestamp[history->nbBars-1], TA_DAILY, history->nbBars-200, 200 );
   if( errNumber != TA_TEST_PASS )
   {
      printf( "Failed: Test getting last 200 price bars only.\n" );
      return errNumber;
   }
   
   errNumber = checkRangeSame( udb, history, &history->timestamp[0], &history->timestamp[199], TA_DAILY, 0, 200 );
   if( errNumber != TA_TEST_PASS )
   {
      printf( "Failed: Test getting first 200 price bars only.\n" );
      return errNumber;
   }

   retCode = TA_HistoryFree( history );
   if( retCode != TA_SUCCESS )
   {
      reportError( "TA_HistoryFree", retCode );
      return TA_YAHOO_HISTORYFREE_FAILED;
   }

   /* Do again the same test, but using Monthly data this time. */      
   memset( &histParam, 0, sizeof( TA_HistoryAllocParam ) );
   histParam.category = "CA.TSE.STOCK";
   histParam.symbol   = "NT";
   histParam.field    = TA_ALL;
   histParam.period   = TA_MONTHLY;
   retCode = TA_HistoryAlloc( udb, &histParam, &history );

   if( retCode != TA_SUCCESS )
   {
      reportError( "TA_HistoryAlloc for Monthly data", retCode );
      return TA_YAHOO_HISTORYALLOC_3_FAILED;
   }

   /* printf( "Nb Bars= %d\n", history->nbBars ); */
   
   errNumber = checkRangeSame( udb, history, &history->timestamp[0], &history->timestamp[0], TA_MONTHLY, 0, 1 );
   if( errNumber != TA_TEST_PASS )
   {
      printf( "Failed: Test getting first price bar only. (Monthly)\n" );
      return errNumber;
   }

   errNumber = checkRangeSame( udb, history, &history->timestamp[1], &history->timestamp[1], TA_MONTHLY, 1, 1 );
   if( errNumber != TA_TEST_PASS )
   {
      printf( "Failed: Test getting second price bar only. (Monthly)\n" );
      return errNumber;
   }

   errNumber = checkRangeSame( udb, history, &history->timestamp[history->nbBars-2], &history->timestamp[history->nbBars-2], TA_MONTHLY, history->nbBars-2, 1 );
   if( errNumber != TA_TEST_PASS )
   {
      printf( "Failed: Test getting before last price bar only. (Monthly)\n" );
      return errNumber;
   }
   
   errNumber = checkRangeSame( udb, history, &history->timestamp[history->nbBars-1], &history->timestamp[history->nbBars-1], TA_MONTHLY, history->nbBars-1, 1 );
   if( errNumber != TA_TEST_PASS )
   {
      printf( "Failed: Test getting last price bar only. (Monthly)\n" );
      return errNumber;
   }

   retCode = TA_HistoryFree( history );
   if( retCode != TA_SUCCESS )
   {
      reportError( "TA_HistoryFree", retCode );
      return TA_YAHOO_HISTORYFREE_FAILED;
   }

   return TA_TEST_PASS;
}