示例#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
static ErrorNumber checkRangeSame( TA_UDBase          *udb,
                                   const TA_History   *historyRef,
                                   const TA_Timestamp *start,
                                   const TA_Timestamp *end,
                                   unsigned int        startIdx,
                                   unsigned int        nbPriceBar )
{
   TA_History *history;
   unsigned int i;
   TA_RetCode retCode;

   #if 1
      /* Do not retry... no forgiveness! */
      retCode = TA_HistoryAlloc( udb, "CA.CDNX.STOCK", "MRY",
                                 TA_DAILY, start, end, TA_ALL,
                                 &history );
   #else
   int retry, again;
   /* Try up to 10 times to get the requested number of 
    * price bar (sometimes Yahoo! or the Web do fail to
    * return the data).
    */
   again = 1;
   for( retry=0; (retry < 10) && again; retry++ )
   {
      retCode = TA_HistoryAlloc( udb, "CA.CDNX.STOCK", "MRY",
                                 TA_DAILY, start, end, TA_ALL,
                                 &history );

      if( (retCode == TA_SUCCESS) && (history->nbBars == nbPriceBar) )
         again = 0;
      else
      {
         printf( "Warning: Yahoo! history alloc retry #%d of 10\n", retry+1 );
         if( retCode == TA_SUCCESS )
         {
            TA_HistoryFree( history );
         }
         TA_Sleep( 10 /* seconds */ );
      }
   }
   #endif

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

   /* Check that the expected number of price bar is returned. */
   if( history->nbBars != nbPriceBar )
   {
      printf( "Failed: nbBars (received != requested)=(%d != %d)\n",
              history->nbBars, nbPriceBar );

      TA_HistoryFree( history );
      return TA_YAHOO_CRS_NBBARSBAD;
   }

   /* Check that the data is the same for the range. */
   for( i=0; i < nbPriceBar; i++ )
   {
      if( !TA_TimestampEqual( &history->timestamp[i], &historyRef->timestamp[startIdx+i] ) ||
          (history->open[i] != historyRef->open[startIdx+i]) ||
          (history->high[i] != historyRef->high[startIdx+i]) ||
          (history->low[i] != historyRef->low[startIdx+i]) ||
          (history->close[i] != historyRef->close[startIdx+i]) ||
          (history->volume[i] != historyRef->volume[startIdx+i]) )
      {
         printf( "Failed: Price Bar value different\n" );
         printf( "Failed: Data = %f,%f,%f,%f,%d\n", history->open[i],
                                             history->high[i],         
                                             history->low[i],
                                             history->close[i],
                                             history->volume[i] );
         printf( "Failed: Ref  = %f,%f,%f,%f,%d\n", historyRef->open[startIdx+i],
                                             historyRef->high[startIdx+i],     
                                             historyRef->low[startIdx+i],
                                             historyRef->close[startIdx+i],
                                             historyRef->volume[startIdx+i] );

         TA_HistoryFree( history );
         return TA_YAHOO_CRS_PRICEBARBAD;
      }
   }

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

   return TA_TEST_PASS;
}
示例#3
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. */
}
示例#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 checkRangeSame( TA_UDBase          *udb,
                                   const TA_History   *historyRef,
                                   const TA_Timestamp *start,
                                   const TA_Timestamp *end,      
                                   TA_Period           period,                             
                                   unsigned int        startIdx,
                                   unsigned int        nbPriceBar )
{
   TA_History *history;
   unsigned int i;
   TA_RetCode retCode;
   TA_HistoryAllocParam histParam;

   int retry, again;
   /* Try up to 10 times to get the requested number of 
    * price bar (sometimes Yahoo! or the Web do fail to
    * return the data).
    */
   again = 1;
   for( retry=0; (retry < 10) && again; retry++ )
   {
      memset( &histParam, 0, sizeof( TA_HistoryAllocParam ) );
      histParam.category = "CA.TSE.STOCK";
      histParam.symbol   = "NT";
      histParam.field    = TA_ALL;
      histParam.start    = *start;
      histParam.end      = *end;
      histParam.period   = period;
      retCode = TA_HistoryAlloc( udb, &histParam, &history );

      if( (retCode == TA_SUCCESS) && (history->nbBars == nbPriceBar) )
         again = 0;
      else
      {
         printf( "Warning: Yahoo! history alloc retry #%d of 10\n", retry+1 );
         if( retCode == TA_SUCCESS )
         {
            TA_HistoryFree( history );
         }
         TA_Sleep( 10 /* seconds */ );
      }
   }

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

   /* Check that the expected number of price bar is returned. */
   if( history->nbBars != nbPriceBar )
   {
      printf( "Failed: nbBars (received != requested)=(%d != %d)\n",
              history->nbBars, nbPriceBar );

      TA_HistoryFree( history );
      return TA_YAHOO_CRS_NBBARSBAD;
   }

   /* printf( "startIdx=%d\n", startIdx ); */

   /* Check that the data is the same for the range. */
   for( i=0; i < nbPriceBar; i++ )
   {
      if( !TA_TimestampEqual( &history->timestamp[i], &historyRef->timestamp[startIdx+i] ) ||
          (history->open[i] != historyRef->open[startIdx+i]) ||
          (history->high[i] != historyRef->high[startIdx+i]) ||
          (history->low[i] != historyRef->low[startIdx+i]) ||
          (history->close[i] != historyRef->close[startIdx+i]) ||
          (history->volume[i] != historyRef->volume[startIdx+i]) )
      {
         printf( "Failed: Price Bar value different\n" );
         printf( "Failed: Data = %d/%d/%d : %f,%f,%f,%f,%d\n",
                                             TA_GetMonth(&history->timestamp[i]),
                                             TA_GetDay(&history->timestamp[i]),
                                             TA_GetYear(&history->timestamp[i]),
                                             history->open[i],
                                             history->high[i],         
                                             history->low[i],
                                             history->close[i],
                                             history->volume[i] );
         printf( "Failed: Ref  = %d/%d/%d : %f,%f,%f,%f,%d\n",
                                             TA_GetMonth(&historyRef->timestamp[i]),
                                             TA_GetDay(&historyRef->timestamp[i]),
                                             TA_GetYear(&historyRef->timestamp[i]),
                                             historyRef->open[startIdx+i],
                                             historyRef->high[startIdx+i],     
                                             historyRef->low[startIdx+i],
                                             historyRef->close[startIdx+i],
                                             historyRef->volume[startIdx+i] );

         TA_HistoryFree( history );
         return TA_YAHOO_CRS_PRICEBARBAD;
      }
   }

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

   return TA_TEST_PASS;
}
示例#6
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;
}
示例#7
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;
}