Пример #1
0
/**** Local functions definitions.     ****/
static TA_RetCode doAdjustments( TA_DecodingParam *localDecodingParam,
                                 TA_String *yahooName,
                                 TA_PrivateYahooHandle *yahooHandle,
                                 const char *overideServerAddr,
                                 TA_ParamForAddData  *paramForAddData )
{
   TA_RetCode retCode;
   TA_WebPage *webPage;
   TA_Stream *stream;
   TA_StreamAccess *streamAccess;
   TA_AdjustDataParse adjustDataParse;

   adjustDataParse.paramForAddData = paramForAddData;
   adjustDataParse.yahooHandle = yahooHandle;

   /* Get the split/value adjustments from the Yahoo! web site */
   retCode = TA_WebPageAllocFromYahooName( localDecodingParam,
                                           TA_StringToChar(yahooName),
                                           overideServerAddr,
                                           &webPage, paramForAddData );

   if( retCode != TA_SUCCESS )
      return retCode;

   /* Parse the dividend/split information */
   stream = webPage->content;  
   streamAccess = TA_StreamAccessAlloc( stream );

   if( !streamAccess )
   {
      TA_WebPageFree( webPage );
      return TA_ALLOC_ERR;
   }

   retCode = TA_StreamAccessSearch( streamAccess, "Monthly" );
   if( retCode == TA_SUCCESS )
   {
      retCode = TA_StreamAccessSearch( streamAccess, "Last" );
      if( retCode == TA_SUCCESS )
      {
          /* Find the table of data. */
          retCode = TA_StreamAccessSearch( streamAccess, "yfnc_datamodoutline1" );;
          if( retCode == TA_SUCCESS )
          {
             retCode = TA_StreamAccessGetHTMLTable( streamAccess,
                                                    200,
                                                    processAdjustmentTable,
                                                    &adjustDataParse );
          }
      }
   }

   TA_StreamAccessFree( streamAccess );
   TA_WebPageFree( webPage );

   return retCode;   
}
Пример #2
0
/* Like TA_FileSeqOpen, but work with a stream instead. */
TA_RetCode TA_FileSeqOpenFromStream( TA_Stream *stream,
                                     TA_FileHandle **handle )
{
   TA_PROLOG
   TA_FileHandlePriv *fileHandlePriv;

   TA_TRACE_BEGIN(  TA_FileSeqOpen );

   TA_ASSERT( stream != NULL );
   TA_ASSERT( handle != NULL );

   /* Allocate the private file handle. */
   fileHandlePriv = (TA_FileHandlePriv *)TA_Malloc( sizeof( TA_FileHandlePriv ) );
   if( !fileHandlePriv )
   {
      TA_TRACE_RETURN( TA_ALLOC_ERR );
   }
   memset( fileHandlePriv, 0, sizeof( TA_FileHandlePriv ) );

   /* There is NO file... */
   #if defined( USE_WIN32_API )
   fileHandlePriv->handle = INVALID_HANDLE_VALUE; 
   #endif

   #if defined( USE_OSLAYER )
   fileHandlePriv->handle = (FILE *)NULL;
   #endif

   /* ... use a stream instead. */
   fileHandlePriv->stream = stream;
   fileHandlePriv->streamAccess = TA_StreamAccessAlloc( stream );
   if( !fileHandlePriv->streamAccess )
   {
      TA_TRACE_RETURN( TA_ALLOC_ERR );
   }

   /* Success! Return the info to the caller. */
   *handle = (TA_FileHandle *)fileHandlePriv;
   TA_TRACE_RETURN( TA_SUCCESS );
}
Пример #3
0
static unsigned int nbCommaField( TA_Stream *csvFile )
{
   TA_RetCode retCode;
   TA_StreamAccess *streamAccess;
   unsigned int nbComma;
   unsigned char data;

   streamAccess = TA_StreamAccessAlloc( csvFile );
   if( !streamAccess )
      return 0;

   nbComma = 0;

#ifdef WIN32
#pragma warning( disable : 4127 ) /* Disable 'conditional expression is constant' */
#endif
   while(1)
   {
      retCode = TA_StreamAccessGetByte( streamAccess, &data );
      if( retCode != TA_SUCCESS )
      {
         TA_StreamAccessFree( streamAccess );
         return 0;
      }
      if( data == ',' )
         nbComma++;
      else if( data == '\n' )
      {
         TA_StreamAccessFree( streamAccess );
         return nbComma + 1;
      }
   }
#ifdef WIN32
#pragma warning( default : 4127 ) /* Restore warning settings. */
#endif
}
Пример #4
0
static TA_RetCode internalMarketPageAlloc( TA_Libc *libHandle,
                                           const TA_DecodingParam *decodingParam,
                                           const char *yahooName,
                                           TA_YahooMarketPage **allocatedMarketPage )
{
   TA_RetCode retCode;
   TA_WebPage *webPage;
   TA_YahooMarketPage *marketPage;
   TA_StreamAccess *streamAccess;

   retCode = TA_WebPageAllocFromYahooName( libHandle,
                                           decodingParam,
                                           yahooName,
                                           &webPage );
                                              
   if( retCode != TA_SUCCESS )
      return retCode;

   /* Allocate the structure who will contained the extracted data */
   marketPage = (TA_YahooMarketPage *)TA_Malloc( libHandle, sizeof( TA_YahooMarketPage ) );
   if( !marketPage )
   {
      TA_WebPageFree( webPage );
      return TA_ALLOC_ERR;
   }
   memset( marketPage, 0, sizeof( TA_YahooMarketPage ) );

   marketPage->magicNb = TA_MARKET_PAGE_MAGIC_NB;
   marketPage->libHandle = libHandle;

   /* From this point, internalMarketPageFree can be safely called. */
    
   /* Extract the data by parsing the Web Page. */
   streamAccess = TA_StreamAccessAlloc( webPage->content );
   retCode = parseMarketPage( libHandle,
                              decodingParam,
                              streamAccess,
                              marketPage );

   if( retCode != TA_SUCCESS )
   {
      TA_StreamAccessFree( streamAccess );
      TA_WebPageFree( webPage );
      internalMarketPageFree( marketPage );
      return retCode;
   }

   retCode = TA_StreamAccessFree( streamAccess );
   if( retCode != TA_SUCCESS )
   {
      TA_WebPageFree( webPage );
      internalMarketPageFree( marketPage );
      return retCode;
   }

   retCode = TA_WebPageFree( webPage );
   if( retCode != TA_SUCCESS )
   {
      internalMarketPageFree( marketPage );
      return retCode;
   }
   
   /* Success. Return the result to the caller. */  
   *allocatedMarketPage = marketPage;

   return TA_SUCCESS;
}