Shares Outstanding for Investing

Hello,
Starting from the code of @fxshrat

I want to adapt it for www.investing.com:
https://www.investing.com/equities/atlantic-american

but when generating the output file with the "AAME" ticker it doesn't do it right, I have to put "atlantic-american" then it does it right. In my database I only have the ticker.
Is there a way to get Investing's Outstanding Shares?
Thanks for your help.
Best regards,
Carlos

I have in my database:

I need:


Results:

// Shares Outstanding Investing
// https://forum.amibroker.com/t/adding-a-yahoo-fundamental-data-piece-to-norgate-database/17549

// Apply to --> *Current
// Range --> 1 recent bar(s)

/// 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 = CategoryGetSymbols( categoryWatchlist, 8 ); // Sotcks SP500
// listnum = CategoryGetSymbols( categoryWatchlist, 12 ); // Sotcks Wilshire 5000
// tickerlist = "AAL,AAME,AAOI,AAON,AAPL,AAWW,AAXN,ABAC,ABAX,ABCB,ABCD,ABCO,ABEO,ABIO,ABMD,ABTL,ABUS,ACAD,ACET,ACGL,ACHC,ACHN,ACIW,ACLS,ACOR,ACRX,ACSF,ACST,ACTA,ACTG,ACUR,ACXM,ADAP,ADAT,ADBE,ADHD,ADI,ADMA,ADMP,ADMS,ADP,ADRO,ADSK,ADTN,ADUS,ADVM";
tickerlist = "agilent-tech,alcoa,aac-holdings,american-airlines-group,atlantic-american,apple-computer-inc,achillion-pharmaceuticals";

what = ">Shares Outstanding<";
shares_out = "";

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

if ( trigger ) {
		// save to file        
		fh = fopen("C:\\Users\\Carlos\\Pictures\\ICB ES-TRADABA\\GICS\\OK\\Pruebas\\shares_out_Investing.csv", "w" );
			
			// Cabecera
			fputs( "Ticker,NumAcc\n", fh );


	if ( Status( "stocknum" ) == 0 ) {	
		// for ( i = 0; ( nm = StrExtract( listnum, i, ',' ) ) != ""; i++ ) {
		for ( i = 0; ( nm = StrExtract( tickerlist, i, ',' ) ) != ""; i++ ) {
			ih = InternetOpenURL( "https://www.investing.com/equities/" + nm );
			if ( ih ) {	
				str_repl = "";
				while( ( str = InternetReadString( ih ) ) != "" ) {
					if ( StrFind(str, what) ) 
						str_repl = StrReplace(str, what, "\n");
				}
				InternetClose( ih );
				
				str_ext = StrExtract(str_repl, 1, '\n');
				str_ext = StrExtract(str_ext, 2, '>');
				shares_out += nm + ";" + StrExtract(str_ext, 0, '<')+"\n";
			}		
		}

		_TRACE(shares_out);


		if ( fh ) {
			fputs( shares_out, fh );
			fclose( fh );
		} else
			Error( "ERROR: file can not be open" );
	}
}

Insert "atlantic-american" as ALIAS to Symbol Information of AAME (similar for other symbols of interest).

14

And in code call Alias field via GetFnDataForeign() function.

// Shares Outstanding Investing
// https://forum.amibroker.com/t/adding-a-yahoo-fundamental-data-piece-to-norgate-database/17549
// Apply to --> *Current
// Range --> 1 recent bar(s)
/// 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
/// @link https://forum.amibroker.com/t/shares-outstanding-for-investing/20885/2
EnableTextOutput(0);
// listnum = 8; // Sotcks SP500
// listnum = 12; // Sotcks Wilshire 5000
tickerlist = "AAME"; //CategoryGetSymbols(categoryWatchlist, listnum);  

what = ">Shares Outstanding<";
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++ ) {
			alias = GetFnDataForeign("Alias", nm);
			ih = InternetOpenURL( "https://www.investing.com/equities/" + alias );
			if ( ih ) {	
				str_repl = "";
				while( ( str = InternetReadString( ih ) ) != "" ) {
					if ( StrFind(str, what) ) 
						str_repl = StrReplace(str, what, "\n");
				}
				InternetClose( ih );
				
				str_ext = StrExtract(str_repl, 1, '\n');
				str_ext = StrExtract(str_ext, 2, '>');
				shares_out += nm + ";" + StrExtract(str_ext, 0, '<')+"\n";
			}		
		}

		_TRACE(shares_out);

		// save to file        
		fh = fopen("C:\\shares_out_Investing.csv", "w" );
		if ( fh ) {			
			// Cabecera
			fputs( "Ticker,NumAcc\n", fh );
			fputs( shares_out, fh );
			fclose( fh );
		} else
			Error( "ERROR: file can not be open" );
	}
}

15

2 Likes

Hi @fxshrat,

As always fast and effective with your response.
Thank you very much.
Best regards,
Carlos

A question:
Is there a way to create a file (csv, txt) with the Investing aliases so that I don't have to search for them one by one?

It is already solved.

Thank you for all @fxshrat