Skip to content

Instantly share code, notes, and snippets.

@spencerbutler
Created November 6, 2022 20:11
Show Gist options
  • Save spencerbutler/8ee3910e6295692e6d816bd996204a3f to your computer and use it in GitHub Desktop.
Save spencerbutler/8ee3910e6295692e6d816bd996204a3f to your computer and use it in GitHub Desktop.
ThinkOrSwim - Grab symbols from FinViz that meet your float requirements.
#!/bin/sh
# Spencer Butler <github@tcos.us>
# ToS doesn't provide stock float infomation.
# Grab symbols from FinViz that meet your float requirements.
# In ToS Watchlist > Create watchlist > import > select the csv file
# You can then create a scanner and choose this watchlist to "Scan in:".
# Change this to the directory you want to save your watchlists.
outdir="$HOME"
# Choose the fields you want to define (check finviz.com for more choices).
FLOAT='sh_float_o50' # over 50M
PRICE='sh_price_o5' # over $5
VOLUME='sh_avgvol_o1000' # over 1M
RELVOL='sh_relvol_o1.5' # over 1.5x
ATR='ta_averagetruerange_o1.5' # over $1.50
# Add these fields to your search.
fields="${FLOAT},${PRICE},${VOLUME},${RELVOL},${ATR}"
# These lines shouldn't need to be changed (much).
finviz='https://finviz.com'
start=1
per_page=20
now="$(date +%Y-%m-%d)"
screener='screener.ashx'
endpoint="$screener"
outfile="${outdir}/${now}_${fields}.csv"
[ -f "$outfile" ] && rm "$outfile"
total=$(curl -s "${finviz}/${endpoint}?v=111&f=${fields}&r=${start}" | egrep -o '<b>Total: </b>[[:digit:]]+' | cut -d '>' -f 3)
while [ "$start" -lt "$total" ]; do
curl -s "${finviz}/${endpoint}?v=111&f=${fields}&r=${start}" | egrep -o '^[A-Z]{1,}\|' | tr -d '|' | tee -a "$outfile"
start=$(( start + per_page ))
done
echo
echo "Use this URL to check/refine your query."
echo "${finviz}/${endpoint}?v=111&f=${fields}&r=1"
echo
echo "ToS Watchlist > Create watchlist > Import >"
echo "$outfile"
@anikhanna
Copy link

Bug fix

#while [ "$start" -lt "$total" ]; do
    curl -s "${finviz}/${endpoint}?v=111&f=${fields}&r=${start}" | egrep -o '^[A-Z]{1,}\|' | tr -d '|' | tee -a "$outfile"
#    start=$(( start + per_page ))
#done

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment