Re-introduced stiching as a fallback for SPY too big; automatic order entry creation for SPX Put Spread works now.
This commit is contained in:
@@ -28,7 +28,7 @@ msg="Short Symbol: _${shortSymbol}_ Strike: _${shortStrike}_ Bid: _${shortBid}_
|
|||||||
systemd-cat -t "`basename $0` $1" -p info <<< ${msg}
|
systemd-cat -t "`basename $0` $1" -p info <<< ${msg}
|
||||||
echo "${msg}"
|
echo "${msg}"
|
||||||
|
|
||||||
jq '.putExpDateMap."2024-07-10:43"[]|map({symbol, delta, strikePrice,bid,ask}) | .[] | select(.strikePrice >= 5210-50 and .strikePrice < 5210)' temp/orderInputFile.json | head -n 7 > temp/longLeg.json
|
jq '.putExpDateMap."'${dateKey}'"[]|map({symbol, delta, strikePrice,bid,ask}) | .[] | select(.strikePrice >= '${shortStrike}'-50 and .strikePrice < '${shortStrike}')' temp/orderInputFile.json | head -n 7 > temp/longLeg.json
|
||||||
longStrike=$(jq -r '.strikePrice' < temp/longLeg.json)
|
longStrike=$(jq -r '.strikePrice' < temp/longLeg.json)
|
||||||
longBid=$(jq -r '.bid' < temp/longLeg.json)
|
longBid=$(jq -r '.bid' < temp/longLeg.json)
|
||||||
longAsk=$(jq -r '.ask' < temp/longLeg.json)
|
longAsk=$(jq -r '.ask' < temp/longLeg.json)
|
||||||
@@ -37,11 +37,14 @@ msg="Long Symbol: _${longSymbol}_ Strike: _${longStrike}_ Bid: _${longBid}_ Ask:
|
|||||||
systemd-cat -t "`basename $0` $1" -p info <<< ${msg}
|
systemd-cat -t "`basename $0` $1" -p info <<< ${msg}
|
||||||
echo "${msg}"
|
echo "${msg}"
|
||||||
|
|
||||||
orderJson=$(cat <<-EOM
|
priceOffset=0.1 # try to get $10 more in premium...
|
||||||
|
price=$(echo "scale=2; ((${shortBid}+${shortAsk})/2 - (${longBid}+${longAsk})/2) + ${priceOffset}" | bc)
|
||||||
|
|
||||||
|
orderJson=$(jq -c <<-EOM
|
||||||
{
|
{
|
||||||
"orderType": "NET_CREDIT",
|
"orderType": "NET_CREDIT",
|
||||||
"session": "NORMAL",
|
"session": "NORMAL",
|
||||||
"price": 5,
|
"price": ${price},
|
||||||
"duration": "DAY",
|
"duration": "DAY",
|
||||||
"orderStrategyType": "SINGLE",
|
"orderStrategyType": "SINGLE",
|
||||||
"quantity": 1,
|
"quantity": 1,
|
||||||
@@ -68,14 +71,16 @@ EOM
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
echo ${orderJson}
|
systemd-cat -t "`basename $0` $1" -p debug <<< "Order: _${orderJson}_"
|
||||||
|
|
||||||
|
#echo Enter to continue, Ctrl+C to cancel
|
||||||
|
#read
|
||||||
./getNewAccessToken.sh
|
./getNewAccessToken.sh
|
||||||
|
|
||||||
set -x
|
set -x
|
||||||
tempFile=temp/order.tmp.$$.json
|
tempFile=temp/order.tmp.$$.json
|
||||||
#curl -s -X POST "https://api.schwabapi.com/trader/v1/accounts/99114DC5A768D40C3FD47D02734C696EB1FEB1063D2EE864528135D8CF31392A/orders" -H "Authorization: Bearer $(<access_token.dat)" -d @order-vs.template.json # > ${tempFile}
|
|
||||||
curl -s -X POST \
|
curl -s -X POST \
|
||||||
'https://api.schwabapi.com/trader/v1/accounts/E8A70AE41449257FA5A7EABFF463BA93F23E629B909C3E09DA192582718D7627/orders' \
|
'https://api.schwabapi.com/trader/v1/accounts/C819AC820A502BA92E55D775B22BDF0E1BC91D86C62685714347734A5827CCB3/orders' \
|
||||||
-H "Authorization: Bearer $(<access_token.dat)" \
|
-H "Authorization: Bearer $(<access_token.dat)" \
|
||||||
-H 'accept: */*' \
|
-H 'accept: */*' \
|
||||||
-H 'Content-Type: application/json' \
|
-H 'Content-Type: application/json' \
|
||||||
|
|||||||
@@ -17,14 +17,27 @@ jq -r '.[].Symbol' allSymbols.json | sort | while read theSymbol; do
|
|||||||
#fi
|
#fi
|
||||||
|
|
||||||
if [[ '$XSP' = ${theSymbol} ]]; then
|
if [[ '$XSP' = ${theSymbol} ]]; then
|
||||||
#./recordOptionChainSingleSymbolSpecialRun.sh ${theSymbol} toDate $(date "+%Y-%m-%d" -d "+200 days")
|
|
||||||
# 2024-05-27, it seems that the ITM/OTM/NTM handling no longer makes an impact, therefore falling back to the normal method but restricting to 200 days
|
|
||||||
# for XSP this is no a break of the leg I guess...
|
|
||||||
|
|
||||||
./recordOptionChainSingleSymbolSingleRun.sh ${theSymbol} toDate $(date "+%Y-%m-%d" -d "+200 days")
|
./recordOptionChainSingleSymbolSingleRun.sh ${theSymbol} toDate $(date "+%Y-%m-%d" -d "+200 days")
|
||||||
if [[ $? -ne 0 ]]; then
|
if [[ $? -ne 0 ]]; then
|
||||||
touch temp/hadErrors.$$.tmp
|
touch temp/hadErrors.$$.tmp
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
# The above one might fail, so we also try with stitching
|
||||||
|
./recordOptionChainSingleSymbolSpecialRun.sh ${theSymbol}
|
||||||
|
continue
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [[ 'SPY' = ${theSymbol} ]]; then
|
||||||
|
./recordOptionChainSingleSymbolSingleRun.sh ${theSymbol}
|
||||||
|
if [[ $? -ne 0 ]]; then
|
||||||
|
systemd-cat -t "`basename $0`" -p warning <<< "falling back to stitching for ${theSymbol}"
|
||||||
|
./recordOptionChainSingleSymbolSpecialRun.sh ${theSymbol}
|
||||||
|
if [[ $? -ne 0 ]]; then
|
||||||
|
touch temp/hadErrors.$$.tmp
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
|
# The above one might fail, so we also try with stitching
|
||||||
continue
|
continue
|
||||||
fi
|
fi
|
||||||
|
|
||||||
@@ -36,7 +49,6 @@ jq -r '.[].Symbol' allSymbols.json | sort | while read theSymbol; do
|
|||||||
continue
|
continue
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
|
||||||
./recordOptionChainSingleSymbolSingleRun.sh ${theSymbol}
|
./recordOptionChainSingleSymbolSingleRun.sh ${theSymbol}
|
||||||
if [[ $? -ne 0 ]]; then
|
if [[ $? -ne 0 ]]; then
|
||||||
touch temp/hadErrors.$$.tmp
|
touch temp/hadErrors.$$.tmp
|
||||||
|
|||||||
@@ -3,9 +3,6 @@
|
|||||||
# This is for big chains, that cause the Schwab API to error out (like $XSP)
|
# 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
|
# I add the range parameter (ITM/NTM/OTM) so that I get less data per request
|
||||||
|
|
||||||
# 2024-05-27: DEPRECATED - THIS FILE IS GOING TO BE REOMVED:
|
|
||||||
# This doesn't seem to be creating smaller responses anymore, therefore this method isn't used anymore anywhere...
|
|
||||||
|
|
||||||
symbol=$1
|
symbol=$1
|
||||||
outDir=data/$(date +%Y-%m-%d)
|
outDir=data/$(date +%Y-%m-%d)
|
||||||
queryString="?symbol=${symbol}"
|
queryString="?symbol=${symbol}"
|
||||||
@@ -52,7 +49,7 @@ jq '. | map_values(select(type=="object"))' < ${ITMtempFile} > ${ITMtempFile}.o
|
|||||||
jq '. | map_values(select(type=="object"))' < ${OTMtempFile} > ${OTMtempFile}.objOnly
|
jq '. | map_values(select(type=="object"))' < ${OTMtempFile} > ${OTMtempFile}.objOnly
|
||||||
jq -s '.[0] * .[1] * .[2] * .[3]' temp/numberOfContracts.$$.tmp temp/CommonDetail.$$.tmp ${ITMtempFile}.objOnly ${OTMtempFile}.objOnly > temp/optionChain.${symbol}.tmp.$$.json
|
jq -s '.[0] * .[1] * .[2] * .[3]' temp/numberOfContracts.$$.tmp temp/CommonDetail.$$.tmp ${ITMtempFile}.objOnly ${OTMtempFile}.objOnly > temp/optionChain.${symbol}.tmp.$$.json
|
||||||
|
|
||||||
optionChainFileName=$(date "+%Y-%m-%d %H_%M_%S")_optionChain.${symbol}.json
|
optionChainFileName=$(date "+%Y-%m-%d %H_%M_%S")_optionChain.${symbol}.stitched.json
|
||||||
pbzip2 -9 -c < temp/optionChain.${symbol}.tmp.$$.json > "${outDir}/${optionChainFileName}.bz2"
|
pbzip2 -9 -c < temp/optionChain.${symbol}.tmp.$$.json > "${outDir}/${optionChainFileName}.bz2"
|
||||||
|
|
||||||
rm temp/*$$*
|
rm temp/*$$*
|
||||||
|
|||||||
Reference in New Issue
Block a user