Cleanup - centralize the log handling
This commit is contained in:
@@ -3,13 +3,11 @@ set -x
|
||||
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"
|
||||
@@ -18,15 +16,11 @@ if [[ "" == "$inputFile" ]]; then
|
||||
./getOptionChain.sh '$SPX' fromDate $(date "+%Y-%m-%d" -d "+1 days") toDate $(date "+%Y-%m-%d" -d "+1 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
|
||||
|
||||
underlyingPrice=$(jq ".underlyingPrice" "${inputFile}")
|
||||
atmStrike=$(jq -r '.callExpDateMap[]|keys[]' "${inputFile}" | sort -n | awk -e '{lastStrike=$1; if ($1 > '${underlyingPrice}') {print $1; exit } }')
|
||||
@@ -39,27 +33,21 @@ shortStrikeP=$(jq -r '.strikePrice' < temp/shortLegP.json)
|
||||
shortBidP=$(jq -r '.bid' < temp/shortLegP.json)
|
||||
shortAskP=$(jq -r '.ask' < temp/shortLegP.json)
|
||||
shortSymbolP=$(jq -r '.symbol' < temp/shortLegP.json)
|
||||
msg="Short Put Symbol: _${shortSymbolP}_ Strike: _${shortStrikeP}_ Bid: _${shortBidP}_ Ask: _${shortAskP}_"
|
||||
systemd-cat -t "`basename $0` $1" -p info <<< ${msg}
|
||||
echo "${msg}"
|
||||
log "Short Put Symbol: _${shortSymbolP}_ Strike: _${shortStrikeP}_ Bid: _${shortBidP}_ Ask: _${shortAskP}_}" info
|
||||
|
||||
jq '.callExpDateMap."'${dateKey}'"[]|map({symbol,delta,strikePrice,bid,ask,optionRoot}) |.[] | select(.optionRoot == "'${optionRoot}'" and .strikePrice=='${atmStrike}') ' "${inputFile}" | tail -n 8 > temp/shortLegC.json
|
||||
shortStrikeC=$(jq -r '.strikePrice' < temp/shortLegC.json)
|
||||
shortBidC=$(jq -r '.bid' < temp/shortLegC.json)
|
||||
shortAskC=$(jq -r '.ask' < temp/shortLegC.json)
|
||||
shortSymbolC=$(jq -r '.symbol' < temp/shortLegC.json)
|
||||
msg="Short Call Symbol: _${shortSymbolC}_ Strike: _${shortStrikeC}_ Bid: _${shortBidC}_ Ask: _${shortAskC}_"
|
||||
systemd-cat -t "`basename $0` $1" -p info <<< ${msg}
|
||||
echo "${msg}"
|
||||
log "Short Call Symbol: _${shortSymbolC}_ Strike: _${shortStrikeC}_ Bid: _${shortBidC}_ Ask: _${shortAskC}_" info
|
||||
|
||||
jq '.putExpDateMap."'${dateKey}'"[]|map({symbol,delta,strikePrice,bid,ask,optionRoot}) | .[] | select(.optionRoot == "'${optionRoot}'" and .strikePrice >= '${shortStrikeP}'-5 and .strikePrice < '${shortStrikeP}')' "${inputFile}" | head -n 8 > temp/longLegP.json
|
||||
longStrikeP=$(jq -r '.strikePrice' < temp/longLegP.json)
|
||||
longBidP=$(jq -r '.bid' < temp/longLegP.json)
|
||||
longAskP=$(jq -r '.ask' < temp/longLegP.json)
|
||||
longSymbolP=$(jq -r '.symbol' < temp/longLegP.json)
|
||||
msg="Long Symbol: _${longSymbolP}_ Strike: _${longStrikeP}_ Bid: _${longBidP}_ Ask: _${longAskP}_"
|
||||
systemd-cat -t "`basename $0` $1" -p info <<< ${msg}
|
||||
echo "${msg}"
|
||||
log "Long Symbol: _${longSymbolP}_ Strike: _${longStrikeP}_ Bid: _${longBidP}_ Ask: _${longAskP}_" info
|
||||
|
||||
#Check if this order has already been submitted.
|
||||
jq '.callExpDateMap."'${dateKey}'"[]|map({symbol,delta,strikePrice,bid,ask,optionRoot}) | .[] | select(.optionRoot == "'${optionRoot}'" and .strikePrice >= '${shortStrikeC}'+5 and .strikePrice > '${shortStrikeP}')' "${inputFile}" | head -n 8 > temp/longLegC.json
|
||||
@@ -67,22 +55,15 @@ longStrikeC=$(jq -r '.strikePrice' < temp/longLegC.json)
|
||||
longBidC=$(jq -r '.bid' < temp/longLegC.json)
|
||||
longAskC=$(jq -r '.ask' < temp/longLegC.json)
|
||||
longSymbolC=$(jq -r '.symbol' < temp/longLegC.json)
|
||||
msg="Long Symbol: _${longSymbolC}_ Strike: _${longStrikeC}_ Bid: _${longBidC}_ Ask: _${longAskC}_"
|
||||
systemd-cat -t "`basename $0` $1" -p info <<< ${msg}
|
||||
echo "${msg}"
|
||||
log "Long Symbol: _${longSymbolC}_ Strike: _${longStrikeC}_ Bid: _${longBidC}_ Ask: _${longAskC}_" info
|
||||
|
||||
#Check if this order has already been submitted.
|
||||
./getOrders.sh | (grep '\(WORKING\|FILLED\),'${longSymbolC: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.00 # try to get a little better price
|
||||
@@ -140,7 +121,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 ${orderJson} | jq
|
||||
|
||||
Reference in New Issue
Block a user