Cleanup - centralize the log handling
This commit is contained in:
@@ -2,6 +2,8 @@
|
||||
set -x
|
||||
IFS=$'\0'
|
||||
|
||||
. helpers.sh
|
||||
|
||||
daysOutMin=90
|
||||
daysOutMax=95
|
||||
deltaMin=0.35
|
||||
@@ -9,33 +11,26 @@ deltaMax=0.40
|
||||
|
||||
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"
|
||||
if [[ "" == "$inputFile" ]]; then
|
||||
latestFile="$(ls data/`date +%Y-%m-%d`/*SPY* | sort | tail -n 1)"
|
||||
systemd-cat -t "`basename $0` $1" -p debug <<< "Latest File: _${latestFile}_"
|
||||
log "Latest File: _${latestFile}_" debug
|
||||
inputFile=temp/orderInputFile.json
|
||||
bzip2 -dc < "${latestFile}" > "${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 '.callExpDateMap | keys | .[]' "${inputFile}" | sort -r -t ":" +2 | awk -F ":" -e '{theDay=$2; if (theDay < '${daysOutMin}') { print lastDay; exit; } else { lastDay=$0; } }')
|
||||
systemd-cat -t "`basename $0` $1" -p debug <<< "Date-Key: _${dateKey}_"
|
||||
log "Date-Key: _${dateKey}_" debug
|
||||
|
||||
daysOut=$(cut -d : -f 2 <<< ${dateKey})
|
||||
if [[ ${daysOut} -gt ${daysOutMax} ]]; then
|
||||
systemd-cat -t "`basename $0` $1" -p info <<< "This option is too far in the future. _${daysOut}_ is bigger than the max days in the future is _${daysOutMax}_. Exiting."
|
||||
exit
|
||||
throw "This option is too far in the future. _${daysOut}_ is bigger than the max days in the future is _${daysOutMax}_. Exiting." info
|
||||
fi
|
||||
|
||||
#Looking for leg, between the specified deltas
|
||||
@@ -44,29 +39,21 @@ fi
|
||||
jq '.callExpDateMap."'${dateKey}'"[]|map({symbol, delta, strikePrice,bid,ask}) | .[] | select(.delta >= '${deltaMin}' and .delta <= '${deltaMax}')' "${inputFile}" | tail -n 7 > temp/longLeg.json
|
||||
numLinesInLeg=$(wc -l temp/longLeg.json | cut -c1)
|
||||
if [[ 7 -ne ${numLinesInLeg} ]]; then
|
||||
errMsg="No suitable long leg found - exiting."
|
||||
systemd-cat -t "`basename $0` $1" -p warning <<< ${errMsg}
|
||||
>&2 echo "${errMsg}"
|
||||
exit 1
|
||||
throw "No suitable long leg found - exiting." warning 1
|
||||
fi
|
||||
|
||||
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}"
|
||||
#Check if this order has already been submitted.
|
||||
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} > temp/existingOrders.$$
|
||||
if [[ $(wc -l < temp/existingOrders.$$) -eq 0 ]];then
|
||||
msg="Not Yet traded, continuing"
|
||||
systemd-cat -t "`basename $0` $1" -p info <<< ${msg}
|
||||
log "Not Yet traded, continuing" info
|
||||
else
|
||||
msg="Already traded, exiting"
|
||||
systemd-cat -t "`basename $0` $1" -p info <<< ${msg}
|
||||
exit 0
|
||||
throw "Already traded, exiting" info
|
||||
fi
|
||||
|
||||
priceOffset=0.0
|
||||
@@ -95,7 +82,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}_
|
||||
|
||||
Reference in New Issue
Block a user