- Separate getting option chains from recording

- Add checking for market open
- Remove SPX from recording
- Hopefully precent the refresh token from being
  overwritten sometimes
This commit is contained in:
2024-08-26 15:18:24 -05:00
parent 917703386d
commit 5535bdae7f
10 changed files with 508 additions and 37 deletions

View File

@@ -4,12 +4,19 @@ set -e
IFS=$'\0'
myPID=$$
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
fi
inputFile="$1"
if [[ "" == "$inputFile" ]]; then
latestFile="$(ls data/`date +%Y-%m-%d`/*\$SPX* | sort | tail -n 1)"
systemd-cat -t "`basename $0` $1" -p debug <<< "Latest File: _${latestFile}_"
inputFile=temp/orderInputFile.json
bzip2 -dc < "${latestFile}" > "${inputFile}"
inputFile=temp/orderInputFile.$$.json
./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."
@@ -20,6 +27,7 @@ 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}_"
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)
@@ -31,7 +39,7 @@ msg="Short Symbol: _${shortSymbol}_ Strike: _${shortStrike}_ Bid: _${shortBid}_
systemd-cat -t "`basename $0` $1" -p info <<< ${msg}
echo "${msg}"
jq '.putExpDateMap."'${dateKey}'"[]|map({symbol,delta,strikePrice,bid,ask,optionRoot}) | .[] | select(.optionRoot == "'${shortOptionRoot}'" and .strikePrice >= '${shortStrike}'-50 and .strikePrice < '${shortStrike}')' temp/orderInputFile.json | head -n 8 > temp/longLeg.json
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)
@@ -89,8 +97,11 @@ EOM
systemd-cat -t "`basename $0` $1" -p debug <<< "Order: _${orderJson}_"
#echo Enter to continue, Ctrl+C to cancel
#read
if [[ "${noconfirm}" != "true" ]]; then
echo Enter to continue, Ctrl+C to cancel _${noconfirm}_
read
fi
./getNewAccessToken.sh
curl -s -X POST \