2024-05-09 15:29:45 -05:00
|
|
|
#!/bin/bash
|
|
|
|
|
#set -x
|
2024-08-27 12:16:01 -05:00
|
|
|
. helpers.sh
|
2024-05-09 15:29:45 -05:00
|
|
|
outDir=data/$(date +%Y-%m-%d)
|
|
|
|
|
mkdir -p "${outDir}"
|
|
|
|
|
mkdir -p temp
|
|
|
|
|
|
2024-08-13 15:31:47 -05:00
|
|
|
ErrorLogLevel=err
|
2024-05-17 15:17:09 -05:00
|
|
|
#Handle additional commandline parameters
|
2024-08-13 15:31:47 -05:00
|
|
|
if [[ $1 == -* ]]; then
|
|
|
|
|
if [[ $1 == "-ErrorAsWarning" ]]; then
|
|
|
|
|
ErrorLogLevel=warning
|
|
|
|
|
shift
|
|
|
|
|
fi
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
symbol=$1
|
2024-05-17 15:17:09 -05:00
|
|
|
shift
|
|
|
|
|
|
2024-08-13 15:31:47 -05:00
|
|
|
queryString="?symbol=${symbol}"
|
|
|
|
|
|
2024-05-17 15:17:09 -05:00
|
|
|
while [[ $# -gt 0 ]]; do
|
|
|
|
|
queryString="${queryString}&$1=$2"
|
|
|
|
|
shift; shift
|
|
|
|
|
done
|
|
|
|
|
|
2024-08-27 12:16:01 -05:00
|
|
|
log "Querying for Symbol: _${symbol}_ query string: _${queryString}_" debug
|
2024-05-17 15:17:09 -05:00
|
|
|
|
|
|
|
|
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_"
|
2024-08-21 14:57:02 -05:00
|
|
|
if [[ "${ErrorLogLevel}" == "err" ]]; then
|
2024-08-27 12:59:41 -05:00
|
|
|
throw "${errMsg}" ${ErrorLogLevel} 2
|
2024-08-27 12:16:01 -05:00
|
|
|
else
|
2024-08-27 12:59:41 -05:00
|
|
|
log "${errMsg}" ${ErrorLogLevel}
|
2024-08-21 14:57:02 -05:00
|
|
|
fi
|
2024-05-09 15:29:45 -05:00
|
|
|
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
|
|
|
|
|
|
|
|
|
|
|