diff --git a/autoTradeQQQLongCall.sh b/autoTradeQQQLongCall.sh index a8fd341..1a16498 100755 --- a/autoTradeQQQLongCall.sh +++ b/autoTradeQQQLongCall.sh @@ -49,6 +49,17 @@ 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. + +./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} +else + msg="Already traded, exiting" + systemd-cat -t "`basename $0` $1" -p info <<< ${msg} + exit 0 +fi priceOffset=0.0 # Get the Middle price... @@ -76,7 +87,6 @@ orderJson=$(jq -c <<-EOM EOM ) - systemd-cat -t "`basename $0` $1" -p debug <<< "Order: _${orderJson}_" echo Enter to continue, Ctrl+C to cancel @@ -84,7 +94,7 @@ read ./getNewAccessToken.sh curl -s -X POST \ - 'https://api.schwabapi.com/trader/v1/accounts/CEF970366D4CC9553B5E8846E35FD92A1867F3E73C1082A52647256F42E4746B/orders' \ + 'https://api.schwabapi.com/trader/v1/accounts/5A5B921917D97B89FDA53E1E1D13D2EB11E488ADA20A20B3C787477DE59A770E/orders' \ -H "Authorization: Bearer $(= '${shortStrike}'-50 and .strikePrice < '${shortStrike}')' temp/orderInputFile.json | head -n 7 > temp/longLeg.json 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 longStrike=$(jq -r '.strikePrice' < temp/longLeg.json) longBid=$(jq -r '.bid' < temp/longLeg.json) @@ -40,6 +39,17 @@ msg="Long Symbol: _${longSymbol}_ Strike: _${longStrike}_ Bid: _${longBid}_ Ask: systemd-cat -t "`basename $0` $1" -p info <<< ${msg} echo "${msg}" +#Check if this order has already been submitted. +./getOrders.sh | grep '\(WORKING\|FILLED\),\('${longSymbol}'\|'${shortSymbol}'\)' > temp/existingOrders.$$ +if [[ $(wc -l < temp/existingOrders.$$) -eq 0 ]];then + msg="Not Yet traded, continuing" + systemd-cat -t "`basename $0` $1" -p info <<< ${msg} +else + msg="Already traded, exiting" + systemd-cat -t "`basename $0` $1" -p info <<< ${msg} + exit 0 +fi + priceOffset=0.1 # try to get $10 more in premium... price=$(echo "scale=2; ((${shortBid}+${shortAsk})/2 - (${longBid}+${longAsk})/2) + ${priceOffset}" | bc) @@ -73,7 +83,6 @@ orderJson=$(jq -c <<-EOM EOM ) - systemd-cat -t "`basename $0` $1" -p debug <<< "Order: _${orderJson}_" #echo Enter to continue, Ctrl+C to cancel diff --git a/autoTradeSPYLongCall.sh b/autoTradeSPYLongCall.sh index e4b82a1..0f158bd 100755 --- a/autoTradeSPYLongCall.sh +++ b/autoTradeSPYLongCall.sh @@ -49,6 +49,17 @@ 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. + +./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} +else + msg="Already traded, exiting" + systemd-cat -t "`basename $0` $1" -p info <<< ${msg} + exit 0 +fi priceOffset=0.0 # Get the Middle price... @@ -76,7 +87,6 @@ orderJson=$(jq -c <<-EOM EOM ) - systemd-cat -t "`basename $0` $1" -p debug <<< "Order: _${orderJson}_" echo Enter to continue, Ctrl+C to cancel diff --git a/getOrders.sh b/getOrders.sh index 5e21b71..f0bfaa4 100755 --- a/getOrders.sh +++ b/getOrders.sh @@ -5,9 +5,9 @@ mkdir -p temp ./getNewAccessToken.sh tempFile=temp/accountOrders.tmp.$$.json -#fromEnteredTime=$(date -u "+%Y-%m-%dT%H:%M:%S.000Z" -d "-5 days") -fromEnteredTime=$(date -u "+%Y-%m-%dT%H:%M:%S.000Z" -d "-1000 minutes") -toEnteredTime=$(date -u "+%Y-%m-%dT%H:%M:%S.000Z" -d "-10 minutes") +fromEnteredTime=$(date -u "+%Y-%m-%dT%H:%M:%S.000Z" -d "-100 days") +toEnteredTime=$(date -u "+%Y-%m-%dT%H:%M:%S.000Z" -d "-0 minutes") curl -s -X GET "https://api.schwabapi.com/trader/v1/orders?fromEnteredTime=${fromEnteredTime}&toEnteredTime=${toEnteredTime}" -H "Authorization: Bearer $( ${tempFile} -cat ${tempFile} | jq -r 'map(.enteredTime)[]' - +#jq -r 'map(.enteredTime)[]' < ${tempFile} +#jq -r '.[].orderLegCollection[].instrument.symbol' < ${tempFile} +jq -r '.[] | [.orderId | tostring][0] + "," + .status + "," + .orderLegCollection[].instrument.symbol' < ${tempFile}