Adding a yahoo fundamental data piece to norgate database

AFAIK you can not get single piece of fundamental.
But you can use AFL and Ascii import to do what you want.

This code gets shares outstanding info of a list saved to text file.

/// Save "Shares Outstanding" fundamentals from Yahoo finance to text file
/// Replace tickerlist be your own symbol list or single symbol
/// AFL code by fxshrat@gmail.com
/// @link https://forum.amibroker.com/t/adding-a-yahoo-fundamental-data-piece-to-norgate-database/17549/2
EnableTextOutput(0);
listnum = 0;//GetOption( "FilterIncludeWatchlist"); // or instead use some hardcoded number etc.
tickerlist = "AAPL,MSFT";//CategoryGetSymbols(categoryWatchlist, listnum);  

shares_out = "";

Filter = 0;
trigger = ParamTrigger( "Create Shares out", "CLICK HERE" ) OR Status("action") == actionExplore;

if ( trigger ) {
	if ( Status( "stocknum" ) == 0 ) {	
		for ( i = 0; ( nm = StrExtract( tickerlist, i, ',' ) ) != ""; i++ ) {
			ih = InternetOpenURL( "https://finance.yahoo.com/quote/"+nm+"/key-statistics?p="+nm );
			
			if ( ih ) {	
				str_repl = "";
				while( ( str = InternetReadString( ih ) ) != "" ) {
					if ( StrFind(str, ">Shares Outstanding<") ) 
						str_repl = StrReplace(str, ">Shares Outstanding<", "\n");
				}
				InternetClose( ih );
				
				str_ext = StrExtract(str_repl, 1, '\n');
				str_ext = StrExtract(str_ext, 9, '>');
				shares_out += nm + "," + StrExtract(str_ext, 0, '<')+"\n";
			}		
		}

		_TRACE(shares_out);

		// save to file        
		fh = fopen("AmiQuote\\Download\\shares_out.txt", "w" );
		if ( fh ) {
			fputs( shares_out, fh );
			fclose( fh );
		} else
			Error( "ERROR: file can not be open" );
	}
}

9


Then you can do ASCII import via Format file (read documentation)

$NOQUOTES 1
$AUTOADD 1
$OVERWRITE 1
$SEPARATOR ,

$FORMAT TICKER,SHARES_OUT

Save content to file with file name yfso.format to be saved to AmiBroker ..\Formats folder and in same folder open import.types file via some NotePad version and add following line YahooFinance_SharesOut (*.txt)|*.txt|yfso.format to it.

Then use File - Import ASCII with appropriate "Files of type" selection and browse to ...Amiquote\Download folder and import shares_out.txt file.

If you do not understand something then please read documentation. It is all there already.
Upper codes are tested and working.


You may also automate file creation and import via AmiBroker batch.

2 Likes