Bash - Fetch share float of a stock from different sources

By xngo on June 1, 2019

Share float is the number of shares of a stock that is available to trade. It is important to know the total float so that you can gauge the supply and demand. For example, if the total float of a stock is 5 millions shares and today, 15 millions shares have already been traded, then it means that the shares have been changing hands 3 times. People who bought the first 5 millions shares are not likely to sell lower than their buying price, neither do people who bought the second or the third 5 millions shares. This pile on leads to share price spike.

Here is a Bash script to fetch share float from Finviz.com, Yahoo.com and The Wallstreet Journal.

#!/bin/bash
set -e
# Description: Fetch float number from different sources.
script_name=$(basename "${0}")
 
symbol=$1
 
# Error handling.
    cmd_eg=$(printf "%s\n%s\n" \
                " e.g. ./${script_name} AAPL"
    )
    if [ -z "${symbol}" ]; then
        echo "Error: Enter a symbol. Aborted!"
        echo "${cmd_eg}"
        exit 1;
    fi
 
# Fetch float from finviz.com
    url="https://finviz.com/quote.ashx?t=${symbol}"
    output_file="${symbol}.html"
    wget -q "${url}" -O "${output_file}"
 
    # Extract float number from html.
    finviz_float=$(cat "${output_file}" | grep "Shs Float" | sed 's|.*<b>||' | sed 's|</b>.*||')
 
# Fetch float from yahoo.com
    url="https://finance.yahoo.com/quote/${symbol}/key-statistics?p=${symbol}&.tsrc=fin-srch"
    output_file="${symbol}.html"
    wget -q "${url}" -O "${output_file}"
 
    # Extract float number from html.
    yahoo_float=$(cat "${output_file}" | sed 's/floatShares/\nfloatShares/' \
                    | grep floatShares | sed 's/}.*//' | sed 's/.*"fmt":"//' | sed 's/".*//')
 
# Fetch float from the wallstreet journal.
    url="https://quotes.wsj.com/${symbol}"
    output_file="${symbol}.html"
    wget -q "${url}" -O "${output_file}"
 
    # Extract float number from html.
    wsj_float=$(cat "${output_file}" | sed 's/Public Float/\nPublic Float/g' | grep 'Public Float' \
                | tail -n +2 | sed 's|</span>.*||' | sed 's/.*">//' | tr -d ' ')
 
 
# Display float numbers.
    echo "Finviz: ${finviz_float}  Yahoo: ${yahoo_float}  WSJ: ${wsj_float}"
 
# Clean up
    rm -f "${output_file}"
 

Here is an example of the results of the script above.

Apple share float

About the author

Xuan Ngo is the founder of OpenWritings.net. He currently lives in Montreal, Canada. He loves to write about programming and open source subjects.