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,14 +3,11 @@
set -e
IFS=$'\0'
myPID=$$
. helpers.sh
marketOpen=$([[ $(./getMarketHours.sh | jq '.option[].isOpen' | grep true | wc -l) -ne 0 ]] && echo true || echo false)
if [[ ${marketOpen} == false ]]; then
errMsg="The market is closed, exiting."
systemd-cat -t "`basename $0` $1" -p info <<< ${errMsg}
>&2 echo "${errMsg}"
exit 2
throw "The market is closed, exiting." info 2
fi
inputFile="$1"
@@ -19,15 +16,11 @@ if [[ "" == "$inputFile" ]]; then
./getOptionChain.sh '$SPX' fromDate $(date "+%Y-%m-%d" -d "+40 days") toDate $(date "+%Y-%m-%d" -d "+46 days") > "${inputFile}"
fi
if [[ ! -f "${inputFile}" ]]; then
errMsg="ERROR: Input file _${inputFile}_ does not exist."
systemd-cat -t "`basename $0` $1" -p err <<< ${errMsg}
>&2 echo "${errMsg}"
exit 1
throw "ERROR: Input file _${inputFile}_ does not exist." err 1
fi
dateKey=$(jq -r '.putExpDateMap | keys | .[]' "${inputFile}" | head -n 1)
systemd-cat -t "`basename $0` $1" -p debug <<< "Date-Key: _${dateKey}_"
echo "Date-Key: _${dateKey}_"
log "Date-Key: _${dateKey}_" debug
jq '.putExpDateMap."'${dateKey}'"[]|map({symbol,delta,strikePrice,bid,ask,optionRoot}) |.[] | select(.delta >= -0.30 and .delta <= -0.25) ' "${inputFile}" | tail -n 8 > temp/shortLeg.json
shortStrike=$(jq -r '.strikePrice' < temp/shortLeg.json)
@@ -35,31 +28,22 @@ shortBid=$(jq -r '.bid' < temp/shortLeg.json)
shortAsk=$(jq -r '.ask' < temp/shortLeg.json)
shortSymbol=$(jq -r '.symbol' < temp/shortLeg.json)
shortOptionRoot=$(jq -r '.optionRoot' < temp/shortLeg.json)
msg="Short Symbol: _${shortSymbol}_ Strike: _${shortStrike}_ Bid: _${shortBid}_ Ask: _${shortAsk}_"
systemd-cat -t "`basename $0` $1" -p info <<< ${msg}
echo "${msg}"
log "Short Symbol: _${shortSymbol}_ Strike: _${shortStrike}_ Bid: _${shortBid}_ Ask: _${shortAsk}_" info
jq '.putExpDateMap."'${dateKey}'"[]|map({symbol,delta,strikePrice,bid,ask,optionRoot}) | .[] | select(.optionRoot == "'${shortOptionRoot}'" and .strikePrice >= '${shortStrike}'-50 and .strikePrice < '${shortStrike}')' "${inputFile}" | head -n 8 > temp/longLeg.json
longStrike=$(jq -r '.strikePrice' < temp/longLeg.json)
longBid=$(jq -r '.bid' < temp/longLeg.json)
longAsk=$(jq -r '.ask' < temp/longLeg.json)
longSymbol=$(jq -r '.symbol' < temp/longLeg.json)
msg="Long Symbol: _${longSymbol}_ Strike: _${longStrike}_ Bid: _${longBid}_ Ask: _${longAsk}_"
systemd-cat -t "`basename $0` $1" -p info <<< ${msg}
echo "${msg}"
log "Long Symbol: _${longSymbol}_ Strike: _${longStrike}_ Bid: _${longBid}_ Ask: _${longAsk}_" info
#Check if this order has already been submitted.
./getOrders.sh | (grep '\(WORKING\|FILLED\),'${longSymbol:0:12} || true) > temp/existingOrders.${myPID}
if [[ $(wc -l < temp/existingOrders.${myPID}) -eq 0 ]];then
msg="Not Yet traded, continuing"
systemd-cat -t "`basename $0` $1" -p info <<< ${msg}
echo ${msg}
log "Not Yet traded, continuing" info
else
msg="Already traded, exiting"
systemd-cat -t "`basename $0` $1" -p info <<< ${msg}
echo ${msg}
exit 0
throw "Already traded, exiting" info
fi
priceOffset=0.1 # try to get $10 more in premium...
@@ -95,7 +79,7 @@ orderJson=$(jq -c <<-EOM
EOM
)
systemd-cat -t "`basename $0` $1" -p debug <<< "Order: _${orderJson}_"
log "Order: _${orderJson}_" debug
if [[ "${noconfirm}" != "true" ]]; then
echo Enter to continue, Ctrl+C to cancel _${noconfirm}_