Cleanup - centralize the log handling

This commit is contained in:
2024-08-27 12:16:01 -05:00
parent d8891ec75f
commit a6b7fc7afe
15 changed files with 124 additions and 180 deletions

View File

@@ -3,6 +3,8 @@
# This is for big chains, that cause the Schwab API to error out (like $XSP)
# I add the range parameter (ITM/NTM/OTM) so that I get less data per request
. helpers.sh
symbol=$1
outDir=data/$(date +%Y-%m-%d)
queryString="?symbol=${symbol}"
@@ -19,8 +21,7 @@ while [[ $# -gt 0 ]]; do
done
for range in ITM OTM NTM; do
msg="Querying for Symbol: _${symbol}_ query string: _${queryString}&range=${range}_"
systemd-cat -t "`basename $0` $1" -p debug <<< ${msg}
log "Querying for Symbol: _${symbol}_ query string: _${queryString}&range=${range}_" debug
curl -s -X GET "https://api.schwabapi.com/marketdata/v1/chains${queryString}&range=${range}" \
-H "Authorization: Bearer $(<access_token.dat)" > temp/optionChain.${symbol}.${range}.tmp.$$.json
@@ -28,10 +29,7 @@ for range in ITM OTM NTM; do
jqQuery=".symbol"
symbolCheck=$(jq -r ${jqQuery} < temp/optionChain.${symbol}.${range}.tmp.$$.json)
if [[ "${symbol}" != "${symbolCheck}" ]]; then
errMsg="ERROR: THE RESPONSE IS INCORRECT! Symbol: _${symbol}_ Check: _${symbolCheck}_ check file _temp/optionChain.${symbol}.${range}.tmp.$$.json_"
systemd-cat -t "`basename $0` $1" -p err <<< ${errMsg}
>&2 echo "${errMsg}"
exit 2
throw "ERROR: THE RESPONSE IS INCORRECT! Symbol: _${symbol}_ Check: _${symbolCheck}_ check file _temp/optionChain.${symbol}.${range}.tmp.$$.json_" err 2
fi
optionChainPartFileName=$(date "+%Y-%m-%d %H_%M_%S")_optionChain.${symbol}.${range}.json