Files
OptionRecorderSchwab/recordOptionChainSingleSymbolSingleRun.sh

49 lines
1.3 KiB
Bash
Executable File

#!/bin/bash
#set -x
. helpers.sh
outDir=data/$(date +%Y-%m-%d)
mkdir -p "${outDir}"
mkdir -p temp
ErrorLogLevel=err
#Handle additional commandline parameters
if [[ $1 == -* ]]; then
if [[ $1 == "-ErrorAsWarning" ]]; then
ErrorLogLevel=warning
shift
fi
fi
symbol=$1
shift
queryString="?symbol=${symbol}"
while [[ $# -gt 0 ]]; do
queryString="${queryString}&$1=$2"
shift; shift
done
log "Querying for Symbol: _${symbol}_ query string: _${queryString}_" debug
curl -s -X GET "https://api.schwabapi.com/marketdata/v1/chains${queryString}" \
-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_"
if [[ "${ErrorLogLevel}" == "err" ]]; then
throw "${errMsg}" ${ErrorLogLevel} 2
else
log "${errMsg}" ${ErrorLogLevel}
fi
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