Files
OptionRecorderSchwab/recordOptionChainSingleSymbolSingleRun.sh

39 lines
1.2 KiB
Bash
Raw Normal View History

2024-05-09 15:29:45 -05:00
#!/bin/bash
#set -x
symbol=$1
outDir=data/$(date +%Y-%m-%d)
queryString="?symbol=${symbol}"
2024-05-09 15:29:45 -05:00
mkdir -p "${outDir}"
mkdir -p temp
#Handle additional commandline parameters
shift
while [[ $# -gt 0 ]]; do
queryString="${queryString}&$1=$2"
shift; shift
done
msg="Querying for Symbol: _${symbol}_ query string: _${queryString}_"
systemd-cat -t "`basename $0` $1" -p debug <<< ${msg}
curl -s -X GET "https://api.schwabapi.com/marketdata/v1/chains${queryString}" \
2024-05-09 15:29:45 -05:00
-H "Authorization: Bearer $(<access_token.dat)" > temp/optionChain.${symbol}.tmp.$$.json
jqQuery=".symbol"
symbolCheck=$(jq -r ${jqQuery} < temp/optionChain.${symbol}.tmp.$$.json)
if [[ "${symbol}" != "${symbolCheck}" ]]; then
errMsg="ERROR: THE RESPONSE IS INCORRECT! Symbol: _${symbol}_ Check: _${symbolCheck}_ check file _temp/optionChain.${symbol}.tmp.$$.json_"
systemd-cat -t "`basename $0` $1" -p err <<< ${errMsg}
2024-05-09 15:29:45 -05:00
>&2 echo "${errMsg}"
exit 2
else
optionChainFileName=$(date "+%Y-%m-%d %H_%M_%S")_optionChain.${symbol}.json
#echo writing to file "${outDir}/${optionChainFileName}"
pbzip2 -9 -c < temp/optionChain.${symbol}.tmp.$$.json > "${outDir}/${optionChainFileName}.bz2"
rm temp/optionChain.${symbol}.tmp.$$.json
fi